diff options
Diffstat (limited to 'apps/cassiopeia/src/bin/cass.rs')
-rw-r--r-- | apps/cassiopeia/src/bin/cass.rs | 65 |
1 files changed, 60 insertions, 5 deletions
diff --git a/apps/cassiopeia/src/bin/cass.rs b/apps/cassiopeia/src/bin/cass.rs index 45b032d7d768..90f84661ae0c 100644 --- a/apps/cassiopeia/src/bin/cass.rs +++ b/apps/cassiopeia/src/bin/cass.rs @@ -1,8 +1,8 @@ -use cassiopeia::{self as cass, meta}; +use cassiopeia::{meta, Cassiopeia}; use clap::{App, Arg, SubCommand}; fn main() { - let app = App::new(meta::NAME) + let cli = App::new(meta::NAME) .version(meta::VERSION) .about(meta::ABOUT) .after_help("To learn more on how to use cassiopeia, check out the documentation \ @@ -23,15 +23,16 @@ If you want to report a bug, please do so on my mailing list: lists.sr.ht/~space .default_value("./time.cass") .takes_value(true), ) + .subcommand(SubCommand::with_name(meta::CMD_UPDATE).about(meta::CMD_UPDATE_ABOUT)) .subcommand( SubCommand::with_name(meta::CMD_START) .about(meta::CMD_START_ABOUT) - .arg(Arg::with_name(meta::ARG_ROUNDING).help(meta::ARG_ROUNDING_ABOUT)), + .arg(Arg::with_name(meta::ARG_ROUNDING).short("r").long("no-round").help(meta::ARG_ROUNDING_ABOUT)), ) .subcommand( SubCommand::with_name(meta::CMD_STOP) .about(meta::CMD_STOP_ABOUT) - .arg(Arg::with_name(meta::ARG_ROUNDING).help(meta::ARG_ROUNDING_ABOUT)), + .arg(Arg::with_name(meta::ARG_ROUNDING).short("r").long("no-round").help(meta::ARG_ROUNDING_ABOUT)), ) .subcommand( SubCommand::with_name(meta::CMD_INVOICE) @@ -65,5 +66,59 @@ If you want to report a bug, please do so on my mailing list: lists.sr.ht/~space ) .get_matches(); - let file = cass::load_file("/home/projects/clients/nyantec-nix-workshops/time.cass"); + let cass_file = cli.value_of(meta::ARG_FILE).unwrap(); + let mut cass = match Cassiopeia::load(cass_file) { + Some(cf) => cf, + None => { + eprintln!( + "Invalid CASS file '{}'; file not found, or unparsable.", + cass_file + ); + std::process::exit(2); + } + }; + + // Parse the matches generated by clap + match cli.subcommand() { + ("start", Some(ops)) => { + // This parameter turns rounding OFF + let round = ops.is_present(meta::ARG_ROUNDING); + match cass.start(!round) { + Some(()) => println!("Started session!"), + None => { + eprintln!("Failed to start session..."); + std::process::exit(1); + } + } + } + ("stop", Some(ops)) => { + // This parameter turns rounding OFF + let round = ops.is_present(meta::ARG_ROUNDING); + match cass.stop(!round) { + Some(()) => println!("Stopped session!"), + None => { + eprintln!("Failed to stop session..."); + std::process::exit(1); + } + } + } + ("invoice", _) => { + println!("Invoice command only partially implemented! No generation is supported"); + match cass.invoice().run() { + Some(()) => println!("Added INVOICE block"), + None => { + eprintln!("Failed to add INVOICE block..."); + std::process::exit(1); + } + } + } + ("update", _) => match cass.update() { + Some(()) => println!("Updated file to new version: {}", meta::VERSION), + None => { + eprintln!("Failed to update file..."); + std::process::exit(1); + } + }, + (_, _) => todo!(), + } } |