From d7bc4410826a8a201efd0df90743c6072db2f363 Mon Sep 17 00:00:00 2001 From: Joshua Yin <56745535+Subjective@users.noreply.github.com> Date: Tue, 5 Sep 2023 18:12:20 -0700 Subject: [PATCH 1/3] fix: shell detection message always outputed when generating completion --- src/cmds/completions.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/cmds/completions.rs b/src/cmds/completions.rs index c57c543..d251709 100644 --- a/src/cmds/completions.rs +++ b/src/cmds/completions.rs @@ -49,14 +49,17 @@ fn get_completions_string(gen: G, cmd: &mut ClapCommand) -> Result } pub fn completion_handler(m: &ArgMatches, cmd: &mut ClapCommand) -> Result<(), Error> { - let shell = *m.get_one::("shell").unwrap_or( - // if shell value is not provided try to get from the environment - { - println!("# Since shell arg value is not provided trying to get the default shell from the environment."); - &Shell::from_env().ok_or(Error::MatchError)? - } - ); - let completions = get_completions_string(shell, cmd)?; - println!("{}", completions); + let shell_result = m.get_one::("shell"); + if let Some(shell) = shell_result { + // Shell argument is provided, use it directly + let completions = get_completions_string(*shell, cmd)?; + println!("{}", completions); + } else { + // Shell argument is not provided, fall back to the default shell from the environment + let shell = Shell::from_env().ok_or(Error::MatchError)?; + let completions = get_completions_string(shell, cmd)?; + println!("{}", completions); + println!("# Since shell arg value is not provided trying to get the default shell from the environment."); + } Ok(()) } From 539696c461521fb9717da89d0c562cb20bfc9745 Mon Sep 17 00:00:00 2001 From: Joshua Yin <56745535+Subjective@users.noreply.github.com> Date: Tue, 5 Sep 2023 18:14:01 -0700 Subject: [PATCH 2/3] Remove shell detection message --- src/cmds/completions.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/cmds/completions.rs b/src/cmds/completions.rs index d251709..bc675de 100644 --- a/src/cmds/completions.rs +++ b/src/cmds/completions.rs @@ -49,17 +49,11 @@ fn get_completions_string(gen: G, cmd: &mut ClapCommand) -> Result } pub fn completion_handler(m: &ArgMatches, cmd: &mut ClapCommand) -> Result<(), Error> { - let shell_result = m.get_one::("shell"); - if let Some(shell) = shell_result { - // Shell argument is provided, use it directly - let completions = get_completions_string(*shell, cmd)?; - println!("{}", completions); - } else { - // Shell argument is not provided, fall back to the default shell from the environment - let shell = Shell::from_env().ok_or(Error::MatchError)?; - let completions = get_completions_string(shell, cmd)?; - println!("{}", completions); - println!("# Since shell arg value is not provided trying to get the default shell from the environment."); - } + let shell = *m.get_one::("shell").unwrap_or( + // if shell value is not provided try to get from the environment + &Shell::from_env().ok_or(Error::MatchError)?, + ); + let completions = get_completions_string(shell, cmd)?; + println!("{}", completions); Ok(()) } From 9b9ca936a487782ed4a373f562d2726e58b1bddd Mon Sep 17 00:00:00 2001 From: Joshua Yin <56745535+Subjective@users.noreply.github.com> Date: Tue, 5 Sep 2023 18:24:12 -0700 Subject: [PATCH 3/3] Update README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c80ae9d..6d16aa0 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,8 @@ You may also obtain specific shell configuration using. leetcode completions fish ``` +If no argument is provided, the shell is inferred from the `SHELL` environment variable. + ## Usage