Uh oh!
There was an error while loading. Please reload this page.
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)
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
kinnison
commented
Oct 28, 2020
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. |
camelid
commented
Oct 28, 2020
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 |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
kinnison
commented
Oct 28, 2020
Most "mortals" are not regex savvy, but they understand shell glob patterns (i.e. |
camelid
commented
Oct 28, 2020
So are you suggesting that we only allow the metacharacter |
Oh, I guess we could use the |
kinnison
commented
Oct 28, 2020
If I were working in C I'd just use the |
c39c730 to
7ce4203CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| info!("no toolchains matched pattern '{}'", pattern_str); | ||
| return Ok(utils::ExitCode(0)); |
There was a problem hiding this comment.
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.
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.
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.
camelid
left a comment
There was a problem hiding this comment.
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.
I just copied this test code from other tests and modified it. Is the test correct?
There was a problem hiding this comment.
You probably want to start the test by installing and asserting that stable and nightly are there. Otherwise I think this is fine.
camelid
commented
Nov 18, 2020
@kinnison Could you review this again? Thanks! |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| #[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.
You probably want to start the test by installing and asserting that stable and nightly are there. Otherwise I think this is fine.
Uh oh!
There was an error while loading. Please reload this page.
rami3l
commented
Jul 10, 2024
Closing in favor of #3862, as discussed in #3519 (comment). Thanks a lot for helping out nonetheless! |
djc
commented
Jul 10, 2024
@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. |
est31
commented
Jul 10, 2024
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: