aboutsummaryrefslogtreecommitdiff
path: root/nitrocli/src/args.rs
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2019-01-19 10:45:37 -0800
committerDaniel Mueller <deso@posteo.net>2019-01-19 10:45:37 -0800
commit0ca4582b07681993b720b684a80ff2e2498463bc (patch)
tree4c84389b393333a7a9dcfb2a0b083596f00a935c /nitrocli/src/args.rs
parent609ccf89d5098c948f12175f926a682aeb2d904a (diff)
downloadnitrocli-0ca4582b07681993b720b684a80ff2e2498463bc.tar.gz
nitrocli-0ca4582b07681993b720b684a80ff2e2498463bc.tar.bz2
Manually handle -V/--version argument
Diffstat (limited to 'nitrocli/src/args.rs')
-rw-r--r--nitrocli/src/args.rs39
1 files changed, 25 insertions, 14 deletions
diff --git a/nitrocli/src/args.rs b/nitrocli/src/args.rs
index 55f781b..33069e6 100644
--- a/nitrocli/src/args.rs
+++ b/nitrocli/src/args.rs
@@ -829,13 +829,19 @@ pub(crate) fn handle_arguments(ctx: &mut RunCtx<'_>, args: Vec<String>) -> Resul
fmt_enum!(DeviceModel::all_variants())
);
let mut verbosity = 0;
+ let mut version = false;
let mut command = Command::Status;
let cmd_help = cmd_help!(command);
let mut subargs = vec![];
let mut parser = argparse::ArgumentParser::new();
- parser.add_option(
+ // Note that ideally we would want to use the argparse::Print action
+ // which was specifically designed with a --version argument in mind.
+ // However, this option does not honor the io::Write object passed to
+ // the ArgumentParser's parse method. To work around this problem, we
+ // implement the same functionality here manually.
+ let _ = parser.refer(&mut version).add_option(
&["-V", "--version"],
- argparse::Print(format!("nitrocli {}", env!("CARGO_PKG_VERSION"))),
+ argparse::StoreTrue,
"Print version information and exit",
);
let _ = parser.refer(&mut verbosity).add_option(
@@ -862,16 +868,21 @@ pub(crate) fn handle_arguments(ctx: &mut RunCtx<'_>, args: Vec<String>) -> Resul
subargs.insert(0, format!("nitrocli {}", command));
- let mut ctx = ExecCtx {
- model,
- stdout: ctx.stdout,
- stderr: ctx.stderr,
- admin_pin: ctx.admin_pin.take(),
- user_pin: ctx.user_pin.take(),
- new_admin_pin: ctx.new_admin_pin.take(),
- new_user_pin: ctx.new_user_pin.take(),
- password: ctx.password.take(),
- verbosity,
- };
- command.execute(&mut ctx, subargs)
+ if version {
+ ctx.stdout.write_all(concat!("nitrocli ", env!("CARGO_PKG_VERSION")).as_ref())?;
+ Ok(())
+ } else {
+ let mut ctx = ExecCtx {
+ model,
+ stdout: ctx.stdout,
+ stderr: ctx.stderr,
+ admin_pin: ctx.admin_pin.take(),
+ user_pin: ctx.user_pin.take(),
+ new_admin_pin: ctx.new_admin_pin.take(),
+ new_user_pin: ctx.new_user_pin.take(),
+ password: ctx.password.take(),
+ verbosity,
+ };
+ command.execute(&mut ctx, subargs)
+ }
}