Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d7bc441

Browse files
fix: shell detection message always outputed when generating completion
1 parent fc4029f commit d7bc441

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

‎src/cmds/completions.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,17 @@ fn get_completions_string<G: Generator>(gen: G, cmd: &mut ClapCommand) -> Result
4949
}
5050

5151
pub fn completion_handler(m: &ArgMatches, cmd: &mut ClapCommand) -> Result<(), Error> {
52-
let shell = *m.get_one::<Shell>("shell").unwrap_or(
53-
// if shell value is not provided try to get from the environment
54-
{
55-
println!("# Since shell arg value is not provided trying to get the default shell from the environment.");
56-
&Shell::from_env().ok_or(Error::MatchError)?
57-
}
58-
);
59-
let completions = get_completions_string(shell, cmd)?;
60-
println!("{}", completions);
52+
let shell_result = m.get_one::<Shell>("shell");
53+
if let Some(shell) = shell_result {
54+
// Shell argument is provided, use it directly
55+
let completions = get_completions_string(*shell, cmd)?;
56+
println!("{}", completions);
57+
} else {
58+
// Shell argument is not provided, fall back to the default shell from the environment
59+
let shell = Shell::from_env().ok_or(Error::MatchError)?;
60+
let completions = get_completions_string(shell, cmd)?;
61+
println!("{}", completions);
62+
println!("# Since shell arg value is not provided trying to get the default shell from the environment.");
63+
}
6164
Ok(())
6265
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /