diff options
Diffstat (limited to 'apps/koffice/invoice/src/cli.rs')
-rw-r--r-- | apps/koffice/invoice/src/cli.rs | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/apps/koffice/invoice/src/cli.rs b/apps/koffice/invoice/src/cli.rs new file mode 100644 index 000000000000..cbf27efe6cc4 --- /dev/null +++ b/apps/koffice/invoice/src/cli.rs @@ -0,0 +1,76 @@ +use crate::Meta; +use clap::{App, AppSettings, Arg, SubCommand}; + +pub struct AppState { + pub meta: Meta, + pub cmd: Command, +} + +pub enum Command { + Init, + Generate, + Install, +} + +pub fn parse() -> AppState { + let project_id = + Arg::with_name("project id").help("The project identifier. Format: [client/]<project>"); + + let timefile = Arg::with_name("timefile") + .help("Location of the project's time file") + .takes_value(true) + .long("file") + .short("f") + .default_value("./time.cass"); + + let template = Arg::with_name("template") + .help("Override the default application template") + .long("templ") + .short("t") + .takes_value(true) + .default_value("$XDG_CONFIG_HOME/k-office/template.tex"); + + let revision = Arg::with_name("revision") + .help("Override the default revision system") + .long("rev") + .short("r") + .takes_value(true); + + let app = App::new("invoice") + .version(env!("CARGO_PKG_VERSION")) + .about("A k-office tool to generate and manage invoices") + .settings(&[ + AppSettings::SubcommandRequired, + AppSettings::GlobalVersion, + AppSettings::ColoredHelp, + AppSettings::DontCollapseArgsInUsage, + ]) + .subcommand( + SubCommand::with_name("init") + .about("Initialise a new invoice config") + .arg(timefile) + .arg(revision.clone()), + ) + .subcommand( + SubCommand::with_name("generate") + .about("Generate an invoice PDF for a client/ project based on a template") + .arg(revision) + .arg(template), + ); + + 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"); + + AppState { + meta: crate::base::init(project_id, timefile, template, revision), + cmd: match matches.subcommand() { + ("init", _) => Command::Init, + ("generate", _) => Command::Generate, + _ => unreachable!(), + }, + } +} |