From b63d4cbac8eb922488c3a7dd8eb9605d7c88cc3c Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Tue, 24 May 2022 17:14:51 +0200 Subject: [PATCH] =?UTF-8?q?Add=20a=20-n/--now=20flag=20to=20only=20print?= =?UTF-8?q?=20the=20current=20hour=E2=80=99s=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 ++++++++ src/main.rs | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b07977c..f107b79 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,14 @@ longitude = 19.286 If you don’t provide a configuration file, the day parts (day/night time and the golden/blue hours) won’t be visible on the clock face. +## Command line arguments + +### Just print the current hour’s name + +You can pass `-n` or `--now` to the app to only print the current hour’s name. + +This can be used in scripts, or in i3/sway panels, for example. + ## Features ### Seasonal hours! diff --git a/src/main.rs b/src/main.rs index bd5a935..44ca5ee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,17 +11,27 @@ mod clock; mod config; mod svg_clock; +use clock::get_current_hour_name; use config::{get_config, Config}; use svg_clock::{cache_hour_name_paths, gen_svg, svg_to_usvg}; #[derive(Parser, Debug)] #[clap(author, version, about, long_about = None)] -struct Args {} +struct Args { + /// Print the current hour’s name and exit + #[clap(short, long)] + now: bool, +} sctk::default_environment!(SeasonalClock, desktop); fn main() { - Args::parse(); + let args = Args::parse(); + + if args.now { + println!("{}", get_current_hour_name()); + std::process::exit(0); + } let config = get_config(); run_windowed(&config);