From 3e535df8a8bf5ac9968b5f3c5d390da82e4d4a17 Mon Sep 17 00:00:00 2001 From: Teascade Date: Mon, 24 Aug 2020 20:47:11 +0300 Subject: [PATCH] Add api-key flag --- src/cmd.rs | 9 ++++++++- src/main.rs | 10 +++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/cmd.rs b/src/cmd.rs index 2186cd2..4c8ca23 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -48,7 +48,14 @@ pub struct BetweenOpt { #[derive(FromArgs)] #[argh(subcommand, name = "init", description = "initializes a config file")] -pub struct InitOpt {} +pub struct InitOpt { + #[argh( + option, + short = 'a', + description = "the API-key for the generated config-file" + )] + pub api_key: Option, +} #[derive(FromArgs)] #[argh( diff --git a/src/main.rs b/src/main.rs index a31fe03..f7bb202 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,8 +43,11 @@ fn from_env(env: EnvOpt) -> Result<(), GenericError> { ); Ok(()) } - Subcommand::Init(_) => { - let config = Config::default(); + Subcommand::Init(opt) => { + let mut config = Config::default(); + if let Some(api_key) = opt.api_key { + config.api_key = api_key; + } config.write_to(&env.config)?; Ok(()) } @@ -52,7 +55,8 @@ fn from_env(env: EnvOpt) -> Result<(), GenericError> { let mut config = Config::from_path(&env.config)?; let mut api = API::new(config.clone()); - let tags = api.get_tags()?; + let mut tags = api.get_tags()?; + tags.sort_by(|tag1, tag2| tag1.id.cmp(&tag2.id)); match opt.subcommand { NickSub::List(_) => {