Add api-key flag

This commit is contained in:
Sofia 2020-08-24 20:47:11 +03:00
parent a2a92d39eb
commit 3e535df8a8
2 changed files with 15 additions and 4 deletions

View File

@ -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<String>,
}
#[derive(FromArgs)]
#[argh(

View File

@ -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(_) => {