From 4d57ac618124878b06aabaa8f392bc52ec60e6c9 Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Sat, 24 Aug 2019 09:29:11 -0700 Subject: Introduce NITROCLI constant This change introduces a constant for the frequently used string "nitrocli" to the program and replaces usages of those strings with references to the constant. --- nitrocli/src/args.rs | 41 ++++++++++++++++++++++++++++++++--------- nitrocli/src/main.rs | 1 + 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/nitrocli/src/args.rs b/nitrocli/src/args.rs index dfa42eb..fe35a9e 100644 --- a/nitrocli/src/args.rs +++ b/nitrocli/src/args.rs @@ -288,7 +288,12 @@ fn unencrypted(ctx: &mut ExecCtx<'_>, args: Vec) -> Result<()> { subargs.insert( 0, - format!("nitrocli {} {}", Command::Unencrypted, subcommand), + format!( + "{} {} {}", + crate::NITROCLI, + Command::Unencrypted, + subcommand, + ), ); subcommand.execute(ctx, subargs) } @@ -334,7 +339,10 @@ fn encrypted(ctx: &mut ExecCtx<'_>, args: Vec) -> Result<()> { parser.stop_on_first_argument(true); parse(ctx, parser, args)?; - subargs.insert(0, format!("nitrocli {} {}", Command::Encrypted, subcommand)); + subargs.insert( + 0, + format!("{} {} {}", crate::NITROCLI, Command::Encrypted, subcommand), + ); subcommand.execute(ctx, subargs) } @@ -382,7 +390,10 @@ fn hidden(ctx: &mut ExecCtx<'_>, args: Vec) -> Result<()> { parser.stop_on_first_argument(true); parse(ctx, parser, args)?; - subargs.insert(0, format!("nitrocli {} {}", Command::Hidden, subcommand)); + subargs.insert( + 0, + format!("{} {} {}", crate::NITROCLI, Command::Hidden, subcommand), + ); subcommand.execute(ctx, subargs) } @@ -450,7 +461,10 @@ fn config(ctx: &mut ExecCtx<'_>, args: Vec) -> Result<()> { parser.stop_on_first_argument(true); parse(ctx, parser, args)?; - subargs.insert(0, format!("nitrocli {} {}", Command::Config, subcommand)); + subargs.insert( + 0, + format!("{} {} {}", crate::NITROCLI, Command::Config, subcommand), + ); subcommand.execute(ctx, subargs) } @@ -559,7 +573,10 @@ fn otp(ctx: &mut ExecCtx<'_>, args: Vec) -> Result<()> { parser.stop_on_first_argument(true); parse(ctx, parser, args)?; - subargs.insert(0, format!("nitrocli {} {}", Command::Otp, subcommand)); + subargs.insert( + 0, + format!("{} {} {}", crate::NITROCLI, Command::Otp, subcommand), + ); subcommand.execute(ctx, subargs) } @@ -727,7 +744,10 @@ fn pin(ctx: &mut ExecCtx<'_>, args: Vec) -> Result<()> { parser.stop_on_first_argument(true); parse(ctx, parser, args)?; - subargs.insert(0, format!("nitrocli {} {}", Command::Pin, subcommand)); + subargs.insert( + 0, + format!("{} {} {}", crate::NITROCLI, Command::Pin, subcommand), + ); subcommand.execute(ctx, subargs) } @@ -784,7 +804,10 @@ fn pws(ctx: &mut ExecCtx<'_>, args: Vec) -> Result<()> { parser.stop_on_first_argument(true); parse(ctx, parser, args)?; - subargs.insert(0, format!("nitrocli {} {}", Command::Pws, subcommand)); + subargs.insert( + 0, + format!("{} {} {}", crate::NITROCLI, Command::Pws, subcommand), + ); subcommand.execute(ctx, subargs) } @@ -937,14 +960,14 @@ pub(crate) fn handle_arguments(ctx: &mut RunCtx<'_>, args: Vec) -> Resul let result = parse(&mut stdio_buf, parser, args); if version { - println!(ctx, "nitrocli {}", env!("CARGO_PKG_VERSION"))?; + println!(ctx, "{} {}", crate::NITROCLI, env!("CARGO_PKG_VERSION"))?; Ok(()) } else { stdout_buf.flush()?; stderr_buf.flush()?; result?; - subargs.insert(0, format!("nitrocli {}", command)); + subargs.insert(0, format!("{} {}", crate::NITROCLI, command)); let mut ctx = ExecCtx { model, diff --git a/nitrocli/src/main.rs b/nitrocli/src/main.rs index 57fbceb..bb4b007 100644 --- a/nitrocli/src/main.rs +++ b/nitrocli/src/main.rs @@ -87,6 +87,7 @@ use crate::error::Error; type Result = result::Result; +const NITROCLI: &str = "nitrocli"; const NITROCLI_ADMIN_PIN: &str = "NITROCLI_ADMIN_PIN"; const NITROCLI_USER_PIN: &str = "NITROCLI_USER_PIN"; const NITROCLI_NEW_ADMIN_PIN: &str = "NITROCLI_NEW_ADMIN_PIN"; -- cgit v1.2.3