summaryrefslogtreecommitdiff
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
commit4d57ac618124878b06aabaa8f392bc52ec60e6c9 (patch)
tree3b17f52e8c8add106173a16d118a81a487eba178
parent560152b074e017753517f1d3c6e4431410ebed4b (diff)
downloadnitrocli-4d57ac618124878b06aabaa8f392bc52ec60e6c9.tar.gz
nitrocli-4d57ac618124878b06aabaa8f392bc52ec60e6c9.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";