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

fix: shell detection message always outputed when generating completion #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
clearloop merged 3 commits into clearloop:master from Subjective:master
Sep 9, 2023

Conversation

Copy link
Contributor

@Subjective Subjective commented Sep 6, 2023

It seems like the shell detection message is always outputed when generating shell completions, regardless of whether the user provided a shell or not. The issue is that the println() is always being executed when it is inside the closure provided to the unwrap_or, event when a valid shell is provided. I'm not familiar with rust, so I don't know why this is the case.

More importantly though, even if the message is ouptuted correctly, it actually prevents the completion from detected correctly (at least for zsh) when added to a file in the fpath like so:
$ leetcode completions zsh >! /usr/local/share/zsh/site-functions/_leetcode

That line has to be manually deleted since it comes before #compdef leetcode

# Since shell arg value is not provided trying to get the default shell from the environment.
#compdef leetcode
...

For these reasons, I think it would be best to just not output it at all and include that info in the README.

If you would prefer to keep the detection message, the following snippet will correctly output the message at the end of the file, but is no where near as elegant.

pub fn completion_handler(m: &ArgMatches, cmd: &mut ClapCommand) -> Result<(), Error> {
 let shell_result = m.get_one::<Shell>("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(())
}

Let me know what you think. Thanks.

clearloop reacted with heart emoji
Copy link
Contributor Author

Subjective commented Sep 8, 2023
edited
Loading

Hmmm, I'm not entirely sure why the ci/cd build fails for macOS, it seems to work locally on my own system

clearloop reacted with heart emoji

Copy link
Owner

Hmmm, I'm not entirely sure why the ci/cd build fails for macOS, it seems to work locally on my own system

nevermind, I'll fix it later

Subjective reacted with thumbs up emoji

@clearloop clearloop merged commit 05e1880 into clearloop:master Sep 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@clearloop clearloop clearloop approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

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