aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2019-08-24 09:29:11 -0700
committerDaniel Mueller <deso@posteo.net>2019-08-24 09:29:11 -0700
commit43932f46aaa4798e3ce8f091eb3cb4e28c937526 (patch)
tree7e07bc8733eebe2748e71226452b19fc26d0cf89
parente9c205f951e11d09bc3f8a56f5f2d62641b588d9 (diff)
downloadnitrocli-43932f46aaa4798e3ce8f091eb3cb4e28c937526.tar.gz
nitrocli-43932f46aaa4798e3ce8f091eb3cb4e28c937526.tar.bz2
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.
-rw-r--r--nitrocli/src/args.rs41
-rw-r--r--nitrocli/src/main.rs1
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<String>) -> 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<String>) -> 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<String>) -> 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<String>) -> 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<String>) -> 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<String>) -> 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<String>) -> 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<String>) -> 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<T> = result::Result<T, Error>;
+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";