Skip to content

Commit

Permalink
Remove args::parse_arguments function
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
d-e-s-o committed Feb 18, 2019
1 parent ff3c5fd commit 20274ad
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions nitrocli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}

0 comments on commit 20274ad

Please sign in to comment.