Skip to content

Commit

Permalink
Using a mut parameter, because you cannot call args_finished on a bor…
Browse files Browse the repository at this point in the history
…rowed value
  • Loading branch information
lookbusy1344 committed May 3, 2024
1 parent b4d6726 commit e602ddc
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn worker_func() -> anyhow::Result<()> {
}

// parse the command line arguments
let (config, suppliedpath) = process_command_line(&mut pargs)?;
let (config, suppliedpath) = process_command_line(pargs)?;

if config.debugmode {
show_help(false);
Expand Down Expand Up @@ -108,8 +108,8 @@ fn worker_func() -> anyhow::Result<()> {
Ok(())
}

/// process the command line arguments and return a ConfigSettings struct
fn process_command_line(pargs: &mut Arguments) -> anyhow::Result<(ConfigSettings, Option<String>)> {
/// process the command line arguments and return a `ConfigSettings` struct
fn process_command_line(mut pargs: Arguments) -> anyhow::Result<(ConfigSettings, Option<String>)> {
// get algorithm as string and parse it
let algostr: Option<String> = pargs.opt_value_from_str(["-a", "--algorithm"])?;
let algo = parse_hash_algorithm(&algostr);
Expand All @@ -130,8 +130,9 @@ fn process_command_line(pargs: &mut Arguments) -> anyhow::Result<(ConfigSettings
));
}

let algo = algo.unwrap(); // unwrap the algorithm

// unwrap, and properly assign the default encoding
let algo = algo.unwrap();
let encoding = {
let mut e = encoding.unwrap();

Expand Down Expand Up @@ -159,6 +160,7 @@ fn process_command_line(pargs: &mut Arguments) -> anyhow::Result<(ConfigSettings
));
}

// build the config struct
let config = ConfigSettings::new(
pargs.contains(["-d", "--debug"]),
pargs.contains(["-x", "--exclude-filenames"]),
Expand Down

0 comments on commit e602ddc

Please sign in to comment.