From 20274ad9381b28d1dd4de5b9e255fed6f88c03ad Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Sun, 17 Feb 2019 17:29:38 -0800 Subject: 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. --- nitrocli/src/args.rs | 18 ++++-------------- 1 file 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) -> 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, -) -> Result<(Command, ExecCtx<'io>, Vec)> { +/// Parse the command-line arguments and execute the selected command. +pub(crate) fn handle_arguments(ctx: &mut RunCtx<'_>, args: Vec) -> Result<()> { use std::io::Write; let mut model: Option = 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) -> Result<()> { - let (command, mut ctx, args) = parse_arguments(ctx, args)?; - command.execute(&mut ctx, args) + command.execute(&mut ctx, subargs) } -- cgit v1.2.1