-
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
Allow selecting toolchains to uninstall with glob pattern #2540
Conversation
$ rustup toolchain list stable-x86_64-apple-darwin (default) nightly-2020-04-18-x86_64-apple-darwin nightly-2020-04-20-x86_64-apple-darwin nightly-x86_64-apple-darwin $ rustup toolchain uninstall --regex 'nightly-*' info: uninstalling toolchain 'nightly-2020-04-18-x86_64-apple-darwin' info: toolchain 'nightly-2020-04-18-x86_64-apple-darwin' uninstalled info: uninstalling toolchain 'nightly-2020-04-20-x86_64-apple-darwin' info: toolchain 'nightly-2020-04-20-x86_64-apple-darwin' uninstalled info: uninstalling toolchain 'nightly-x86_64-apple-darwin' info: toolchain 'nightly-x86_64-apple-darwin' uninstalled $ rustup toolchain list stable-x86_64-apple-darwin (default)
One comment, before I even look at the code too deeply, I'm not sure regular expressions are ideal for this, instead perhaps it's best to advertise this as shell-glob style patterns. i.e. |
I'm not fully sure what you mean by "advertise as shell-glob style patterns": It takes a regex, not a glob pattern. I realized that I confused myself with the example I tried because I used the regex |
Most "mortals" are not regex savvy, but they understand shell glob patterns (i.e. |
So are you suggesting that we only allow the metacharacter |
Oh, I guess we could use the |
If I were working in C I'd just use the |
c39c730
to
7ce4203
Compare
src/cli/rustup_mode.rs
Outdated
info!("no toolchains matched pattern '{}'", pattern_str); | ||
return Ok(utils::ExitCode(0)); |
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.
I think this should return a non-zero exit code, but I modelled this after rustup toolchain uninstall some-toolchain
, which just shows a message with a successful exit code. Should I change both of them to return an error?
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.
If it has always been "safe" in the shell scripting sense to "remove" a toolchain which isn't present, then we wouldn't want to break peoples' scripting by making them check first before trying. Better to be informational but consistent with past behaviour here I think.
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.
I'm not entirely sure that this makes sense. Patterns are new; failure to match a pattern is a new situation. We can detect a toolchain string that has no pattern characters and do the prior behaviour, if we want to.
That means, we can take a first principles design here if appropriate.
First treat the toolchain as a pattern; if it doesn't match anything, then treat it as a partial toolchain specifier.
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.
I think all this needs is some documentation, and then it's ready to go! Where should I put the docs?
#[test] | ||
fn toolchain_uninstall_pattern() { | ||
setup(&|config| { | ||
expect_ok(config, &["rustup", "uninstall", "stable-*"]); | ||
expect_ok(config, &["rustup", "uninstall", "nightly-*"]); | ||
let mut cmd = clitools::cmd(config, "rustup", &["show"]); | ||
clitools::env(config, &mut cmd); | ||
let out = cmd.output().unwrap(); | ||
assert!(out.status.success()); | ||
let stdout = String::from_utf8(out.stdout).unwrap(); | ||
assert!(!stdout.contains(for_host!("'stable-{}'"))); | ||
assert!(!stdout.contains(for_host!("'nightly-2015-01-01-{}'"))); | ||
}); | ||
} |
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.
I just copied this test code from other tests and modified it. Is the test correct?
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.
You probably want to start the test by installing and asserting that stable and nightly are there. Otherwise I think this is fine.
@kinnison Could you review this again? Thanks! |
#[test] | ||
fn toolchain_uninstall_pattern() { | ||
setup(&|config| { | ||
expect_ok(config, &["rustup", "uninstall", "stable-*"]); | ||
expect_ok(config, &["rustup", "uninstall", "nightly-*"]); | ||
let mut cmd = clitools::cmd(config, "rustup", &["show"]); | ||
clitools::env(config, &mut cmd); | ||
let out = cmd.output().unwrap(); | ||
assert!(out.status.success()); | ||
let stdout = String::from_utf8(out.stdout).unwrap(); | ||
assert!(!stdout.contains(for_host!("'stable-{}'"))); | ||
assert!(!stdout.contains(for_host!("'nightly-2015-01-01-{}'"))); | ||
}); | ||
} |
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.
You probably want to start the test by installing and asserting that stable and nightly are there. Otherwise I think this is fine.
Closing in favor of #3862, as discussed in #3519 (comment). Thanks a lot for helping out nonetheless! |
@djc The idea is that one would be able to do If the demand is still there we can make another PR with @camelid as the co-author, I have no problem with that. |
It might still make sense to have glob support. At the least one should print the command you suggested when someone tries to use globs with rustup: it's not trivial to come up with it, nor is it guaranteed to always work in the future. |
Closes #2530.
Examples
Correct usage
Invalid pattern
Work-in-progress: