diff options
Diffstat (limited to 'apps/koffice/invoice/src/cli.rs')
-rw-r--r-- | apps/koffice/invoice/src/cli.rs | 52 |
1 files changed, 47 insertions, 5 deletions
diff --git a/apps/koffice/invoice/src/cli.rs b/apps/koffice/invoice/src/cli.rs index cbf27efe6cc4..6565eb75e2eb 100644 --- a/apps/koffice/invoice/src/cli.rs +++ b/apps/koffice/invoice/src/cli.rs @@ -10,6 +10,7 @@ pub enum Command { Init, Generate, Install, + Set(String, Option<String>), } pub fn parse() -> AppState { @@ -42,34 +43,75 @@ pub fn parse() -> AppState { .settings(&[ AppSettings::SubcommandRequired, AppSettings::GlobalVersion, - AppSettings::ColoredHelp, AppSettings::DontCollapseArgsInUsage, ]) .subcommand( SubCommand::with_name("init") .about("Initialise a new invoice config") + .arg(project_id.clone()) .arg(timefile) .arg(revision.clone()), ) .subcommand( SubCommand::with_name("generate") .about("Generate an invoice PDF for a client/ project based on a template") + .arg(project_id) .arg(revision) .arg(template), + ) + .subcommand( + SubCommand::with_name("set") + .about("Set a variable in the k-office configuration") + .arg( + Arg::with_name("key") + .required(true) + .takes_value(true) + .help("The configuration key to set"), + ) + .arg( + Arg::with_name("value") + .takes_value(true) + .help("The value to set the key to. Missing value deletes the key"), + ), ); let matches = app.get_matches(); - let project_id = matches.value_of("project id"); - let timefile = matches.value_of("timefile"); - let template = matches.value_of("template"); - let revision = matches.value_of("revision"); + let project_id = match matches.subcommand() { + ("init", Some(vals)) => vals.value_of("project id"), + ("generate", Some(vals)) => vals.value_of("project id"), + _ => None, + }; + + let timefile = match matches.subcommand() { + ("init", Some(vals)) => vals.value_of("timefile"), + ("generate", Some(vals)) => vals.value_of("timefile"), + _ => None, + }; + + let template = match matches.subcommand() { + ("init", Some(vals)) => vals.value_of("template"), + ("generate", Some(vals)) => vals.value_of("template"), + _ => None, + }; + + let revision = match matches.subcommand() { + ("init", Some(vals)) => vals.value_of("revision"), + ("generate", Some(vals)) => vals.value_of("revision"), + _ => None, + }; + + let (key, value) = match matches.subcommand() { + ("set", Some(vals)) => (vals.value_of("key"), vals.value_of("value")), + _ => (None, None), + }; AppState { meta: crate::base::init(project_id, timefile, template, revision), cmd: match matches.subcommand() { ("init", _) => Command::Init, ("generate", _) => Command::Generate, + ("set", _) => Command::Set(key.unwrap().into(), value.map(Into::into)), _ => unreachable!(), }, } |