@@ -49,14 +49,17 @@ fn get_completions_string<G: Generator>(gen: G, cmd: &mut ClapCommand) -> Result
49
49
}
50
50
51
51
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
+ }
61
64
Ok ( ( ) )
62
65
}
0 commit comments