-
Notifications
You must be signed in to change notification settings - Fork 892
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
Include shell completion for Cargo #1425
Changes from all commits
472f0cf
51a5e56
8fb5d31
d7c5bdd
bafd117
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ pub fn main() -> Result<()> { | |
("default", Some(m)) => default_(cfg, m)?, | ||
("toolchain", Some(c)) => match c.subcommand() { | ||
("install", Some(m)) => update(cfg, m)?, | ||
("list", Some(_)) => common::list_toolchains(cfg)?, | ||
("list", Some(m)) => common::list_toolchains(cfg, m)?, | ||
("link", Some(m)) => toolchain_link(cfg, m)?, | ||
("uninstall", Some(m)) => toolchain_remove(cfg, m)?, | ||
(_, _) => unreachable!(), | ||
|
@@ -80,11 +80,34 @@ pub fn main() -> Result<()> { | |
}, | ||
("completions", Some(c)) => { | ||
if let Some(shell) = c.value_of("shell") { | ||
let shell = shell.parse::<Shell>().unwrap(); | ||
let prefix = "~/.rustup/toolchains/$(rustup toolchain list --default)"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This prefix is not correct - rustup is not necessarily installed here, and the default toolchain isn't necessarily correct. To get the installation directory of the active toolchain, you should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does to replace the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Diggsey Help me to finish this, please. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
cli().gen_completions_to( | ||
"rustup", | ||
shell.parse::<Shell>().unwrap(), | ||
shell, | ||
&mut io::stdout(), | ||
); | ||
|
||
match shell { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-trivial logic like this should be pulled out into its own function. |
||
Shell::Bash => { | ||
writeln!( | ||
&mut io::stdout(), | ||
"\n. {}{}", | ||
prefix, | ||
"/etc/bash_completion.d/cargo" | ||
); | ||
} | ||
Shell::Zsh => { | ||
writeln!( | ||
&mut io::stdout(), | ||
"\n. {}{}", | ||
prefix, | ||
"/share/zsh/site-functions/_cargo" | ||
); | ||
} | ||
_ => (), | ||
}; | ||
} | ||
} | ||
(_, _) => unreachable!(), | ||
|
@@ -172,7 +195,15 @@ pub fn cli() -> App<'static, 'static> { | |
.setting(AppSettings::VersionlessSubcommands) | ||
.setting(AppSettings::DeriveDisplayOrder) | ||
.setting(AppSettings::SubcommandRequiredElseHelp) | ||
.subcommand(SubCommand::with_name("list").about("List installed toolchains")) | ||
.subcommand( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change should not be necessary There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you requesting to remove the new |
||
SubCommand::with_name("list") | ||
.about("List installed toolchains") | ||
.arg( | ||
Arg::with_name("default") | ||
.long("default") | ||
.help("Show only the default toolchain"), | ||
), | ||
) | ||
.subcommand( | ||
SubCommand::with_name("install") | ||
.about("Install or update a given toolchain") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert the changes to this file as they should not be necessary.