The SSH host key has changed on 8 April, 2022 to this one: SHA256:573uTBSeh74kvOo0HJXi5ijdzRm8me27suzNEDlGyrQ

Add a -c/--config option to use a config file different from the default

main
Gergely Polonkai 6 months ago
parent b63d4cbac8
commit 09e3dbcb9e
No known key found for this signature in database
GPG Key ID: 2D2885533B869ED4
  1. 6
      README.md
  2. 4
      example-config.toml
  3. 17
      src/config.rs
  4. 7
      src/main.rs

@ -4,7 +4,7 @@ This is a Rust implementation of cinnamon’s [Seasonal Hours Clock](https://git
## Configuration
Create a file `$XDG_CONFIG_HOME/seasonal-clock.toml` (where `$XDG_CONFIG_HOME` is `~/.config` on Linux systems) with the following content:
Create a file `$XDG_CONFIG_HOME/seasonal-clock.toml` (where `$XDG_CONFIG_HOME` is `~/.config` on Linux systems) with the following content (or use/modify [example-config.toml](example-config.toml)):
```
[seasonal-clock]
@ -24,6 +24,10 @@ 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.
### Use a different config
Pass `-c FILE` or `--config FILE` to use `FILE` as the configuration file (instead of the default). I’m not sure if it can be useful; i only did this to show off my Rust skills ^_^
## Features
### Seasonal hours!

@ -0,0 +1,4 @@
[seasonal-clock]
# This is somewhere arond Hungary
latitude = 47.65
longitude = 19.28

@ -1,4 +1,5 @@
use std::fs;
use std::path::PathBuf;
use serde::Deserialize;
@ -14,17 +15,23 @@ struct CompleteConfig {
seasonal_clock: Config,
}
pub fn get_config() -> Option<Config> {
let xdg_dirs = xdg::BaseDirectories::new().unwrap();
let config_path = xdg_dirs
.place_config_file("seasonal-clock.toml")
.expect("cannot create configuration directory");
pub fn get_config(filename: Option<String>) -> Option<Config> {
let config_path = match filename {
Some(v) => PathBuf::from(v),
None => {
let xdg_dirs = xdg::BaseDirectories::new().unwrap();
xdg_dirs
.place_config_file("seasonal-clock.toml")
.expect("cannot create configuration directory")
}
};
let data: std::io::Result<String> = fs::read_to_string(config_path);
if let Ok(..) = data {
let complete_config: CompleteConfig = toml::from_str(&data.unwrap()).unwrap();
Some(complete_config.seasonal_clock)
} else {
eprintln!("Could not parse config file {:?}", data);
None
}
}

@ -21,6 +21,10 @@ struct Args {
/// Print the current hour’s name and exit
#[clap(short, long)]
now: bool,
/// Use FILE as the configuration file
#[clap(short, long, value_name = "FILE")]
config: Option<String>,
}
sctk::default_environment!(SeasonalClock, desktop);
@ -32,7 +36,8 @@ fn main() {
println!("{}", get_current_hour_name());
std::process::exit(0);
}
let config = get_config();
let config = get_config(args.config);
run_windowed(&config);
}

Loading…
Cancel
Save