summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2019-02-17 17:29:38 -0800
committerDaniel Mueller <deso@posteo.net>2019-02-17 17:29:38 -0800
commit20274ad9381b28d1dd4de5b9e255fed6f88c03ad (patch)
treee5395f8707ae6b68c0f821b36be9594c7dc24336
parentff3c5fd8f6370265156d308b44c3b039ead12fd4 (diff)
downloadnitrocli-20274ad9381b28d1dd4de5b9e255fed6f88c03ad.tar.gz
nitrocli-20274ad9381b28d1dd4de5b9e255fed6f88c03ad.tar.bz2
Remove args::parse_arguments function
The split between the parse_arguments and the handle_arguments functions is not really useful for reasoning about the code. In fact, it just adds additional overhead in the form of complex function signatures into the picture. As it provides no real other value, this change merges the functionality of both functions into a single one: handle_arguments.
-rw-r--r--nitrocli/src/args.rs18
1 files changed, 4 insertions, 14 deletions
diff --git a/nitrocli/src/args.rs b/nitrocli/src/args.rs
index 924b10e..8bf0013 100644
--- a/nitrocli/src/args.rs
+++ b/nitrocli/src/args.rs
@@ -862,12 +862,8 @@ fn pws_status(ctx: &mut ExecCtx<'_>, args: Vec<String>) -> Result<()> {
commands::pws_status(ctx, all)
}
-/// Parse the command-line arguments and return the selected command and
-/// the remaining arguments for the command.
-fn parse_arguments<'io, 'ctx: 'io>(
- ctx: &'ctx mut RunCtx<'_>,
- args: Vec<String>,
-) -> Result<(Command, ExecCtx<'io>, Vec<String>)> {
+/// Parse the command-line arguments and execute the selected command.
+pub(crate) fn handle_arguments(ctx: &mut RunCtx<'_>, args: Vec<String>) -> Result<()> {
use std::io::Write;
let mut model: Option<DeviceModel> = None;
@@ -917,7 +913,7 @@ fn parse_arguments<'io, 'ctx: 'io>(
result?;
subargs.insert(0, format!("nitrocli {}", command));
- let ctx = ExecCtx {
+ let mut ctx = ExecCtx {
model,
stdout: ctx.stdout,
stderr: ctx.stderr,
@@ -928,11 +924,5 @@ fn parse_arguments<'io, 'ctx: 'io>(
password: ctx.password.take(),
verbosity,
};
- Ok((command, ctx, subargs))
-}
-
-/// Parse the command-line arguments and execute the selected command.
-pub(crate) fn handle_arguments(ctx: &mut RunCtx<'_>, args: Vec<String>) -> Result<()> {
- let (command, mut ctx, args) = parse_arguments(ctx, args)?;
- command.execute(&mut ctx, args)
+ command.execute(&mut ctx, subargs)
}