diff --git a/.gitignore b/.gitignore index ea8c4bf..b6a5d22 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +secret.toml \ No newline at end of file diff --git a/config.toml b/config.toml deleted file mode 100644 index a4270ff..0000000 --- a/config.toml +++ /dev/null @@ -1,7 +0,0 @@ -api_key = "E3GrOiQAnY61BP623XXzt9Fo87A1IQrS1FFzD57P" -tags_url = "https://platform.yepzon.com/tags" -states_url = "https://platform.yepzon.com/tags/{tag}/states" -locations_url = "https://platform.yepzon.com/tags/{tag}/locations/{state}" -timestamp_format = "%Y-%m-%dT%H:%M:%S%.fZ" -between_format = "%d.%m.%Y %H:%M:%S" -throttle = 9 diff --git a/src/cmd.rs b/src/cmd.rs index a3a2e5c..95291a4 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -1,4 +1,5 @@ use argh::FromArgs; +use std::path::PathBuf; #[derive(FromArgs)] #[argh(description = "Tool for gathering location data from Yepzon servers.")] @@ -15,11 +16,17 @@ pub enum Subcommand { } #[derive(FromArgs)] -#[argh(subcommand, name = "run")] -#[argh(description = "Run the tool")] -pub struct RunOpt {} +#[argh(subcommand, name = "run", description = "Run the tool")] +pub struct RunOpt { + #[argh( + option, + short = 'c', + description = "otus", + default = "PathBuf::from(\"config.toml\")" + )] + pub config: PathBuf, +} #[derive(FromArgs)] -#[argh(subcommand, name = "init")] -#[argh(description = "Initialize a config file")] +#[argh(subcommand, name = "init", description = "Initialize a config file")] pub struct InitOpt {} diff --git a/src/main.rs b/src/main.rs index a8820dd..9770870 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,14 +23,17 @@ fn main() { fn from_env(env: EnvOpt) -> Result<(), GenericError> { match env.subcommand { - Subcommand::Run(_) => { - let mut file = File::open("config.toml").with_msg("Could not find config.toml")?; + Subcommand::Run(opt) => { + let mut file = File::open(&opt.config).with_msg(format!( + "Could not find {}", + opt.config.to_str().unwrap_or("") + ))?; let mut string = String::new(); file.read_to_string(&mut string) - .with_msg("config.toml is not valid UTF-8")?; + .with_msg("config file is not valid UTF-8")?; let config: Config = - toml::from_str(&string).with_msg("config.toml is not a valid config file")?; + toml::from_str(&string).with_msg("given config file is not a valid config file")?; run( &config, @@ -100,7 +103,7 @@ fn run(config: &Config, from: Option, to: Option) -> Result<(), println!("{:<100}", "Done!"); locations.sort_by(|loc1, loc2| loc2.timestamp.cmp(&loc1.timestamp)); - let locs = API::get_between(&locations, from, to, false, &config); + let _locs = API::get_between(&locations, from, to, false, &config); /*dbg!( &locs.iter().map(|loc| loc.0).collect::>(), locs.len(),