Skip to content

Commit

Permalink
refactor(cli): rewrite rustup (toolchain|update|(un)?install) with …
Browse files Browse the repository at this point in the history
…`clap-derive`
  • Loading branch information
rami3l committed May 12, 2024
1 parent e92b85e commit 8983028
Show file tree
Hide file tree
Showing 15 changed files with 245 additions and 241 deletions.
397 changes: 205 additions & 192 deletions src/cli/rustup_mode.rs

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions src/toolchain/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,15 +458,6 @@ impl Display for CustomToolchainName {
}
}

/// Thunk to avoid
/// = note: `fn(&'2 str) -> Result<CustomToolchainName, <CustomToolchainName as TryFrom<&'2 str>>::Error> {<CustomToolchainName as TryFrom<&'2 str>>::try_from}` must implement `FnOnce<(&'1 str,)>`, for any lifetime `'1`...
/// = note: ...but it actually implements `FnOnce<(&'2 str,)>`, for some specific lifetime `'2`
pub(crate) fn custom_toolchain_name_parser(
value: &str,
) -> Result<CustomToolchainName, InvalidName> {
CustomToolchainName::try_from(value)
}

/// An toolchain specified just via its path. Relative paths enable arbitrary
/// code execution in a rust dir, so as a partial mitigation is limited to
/// absolute paths.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
bin.name = "rustup"
args = ["component","add","--help"]
args = ["component", "add", "--help"]
stdout = """
...
Add a component to a Rust toolchain
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
bin.name = "rustup"
args = ["component","remove","--help"]
args = ["component", "remove", "--help"]
stdout = """
...
Remove a component from a Rust toolchain
Expand Down
6 changes: 3 additions & 3 deletions tests/suite/cli-ui/rustup/rustup_help_cmd_stdout.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ The Rust toolchain installer
Usage: rustup[EXE] [OPTIONS] [+toolchain] [COMMAND]
Commands:
show Show the active and installed toolchains or profiles
update Update Rust toolchains and rustup
check Check for updates to Rust toolchains and rustup
default Set the default toolchain
toolchain Modify or query the installed toolchains
target Modify a toolchain's supported targets
component Modify a toolchain's installed components
override Modify toolchain overrides for directories
Expand All @@ -24,6 +21,9 @@ Commands:
self Modify the rustup installation
set Alter rustup settings
completions Generate tab-completion scripts for your shell
show Show the active and installed toolchains or profiles
update Update Rust toolchains and rustup
toolchain Modify or query the installed toolchains
help Print this message or the help of the given subcommand(s)
Arguments:
Expand Down
6 changes: 3 additions & 3 deletions tests/suite/cli-ui/rustup/rustup_help_flag_stdout.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ The Rust toolchain installer
Usage: rustup[EXE] [OPTIONS] [+toolchain] [COMMAND]
Commands:
show Show the active and installed toolchains or profiles
update Update Rust toolchains and rustup
check Check for updates to Rust toolchains and rustup
default Set the default toolchain
toolchain Modify or query the installed toolchains
target Modify a toolchain's supported targets
component Modify a toolchain's installed components
override Modify toolchain overrides for directories
Expand All @@ -24,6 +21,9 @@ Commands:
self Modify the rustup installation
set Alter rustup settings
completions Generate tab-completion scripts for your shell
show Show the active and installed toolchains or profiles
update Update Rust toolchains and rustup
toolchain Modify or query the installed toolchains
help Print this message or the help of the given subcommand(s)
Arguments:
Expand Down
8 changes: 4 additions & 4 deletions tests/suite/cli-ui/rustup/rustup_only_options_stdout.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ rustup [..]
The Rust toolchain installer
Usage: rustup [OPTIONS] [+toolchain] [COMMAND]
Usage: rustup[EXE] [OPTIONS] [+toolchain] [COMMAND]
Commands:
show Show the active and installed toolchains or profiles
update Update Rust toolchains and rustup
check Check for updates to Rust toolchains and rustup
default Set the default toolchain
toolchain Modify or query the installed toolchains
target Modify a toolchain's supported targets
component Modify a toolchain's installed components
override Modify toolchain overrides for directories
Expand All @@ -24,6 +21,9 @@ Commands:
self Modify the rustup installation
set Alter rustup settings
completions Generate tab-completion scripts for your shell
show Show the active and installed toolchains or profiles
update Update Rust toolchains and rustup
toolchain Modify or query the installed toolchains
help Print this message or the help of the given subcommand(s)
Arguments:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
bin.name = "rustup"
args = ["toolchain","install","--help"]
args = ["toolchain", "install", "--help"]
stdout = """
...
Install or update a given toolchain
Usage: rustup[EXE] toolchain install [OPTIONS] <toolchain>...
Usage: rustup[EXE] toolchain install [OPTIONS] <TOOLCHAIN>...
Arguments:
<toolchain>... Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see
<TOOLCHAIN>... Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see
`rustup help toolchain`
Options:
--profile <profile> [possible values: minimal, default, complete]
-c, --component <components>... Add specific components on installation
-t, --target <targets>... Add specific targets on installation
--no-self-update Don't perform self update when running the`rustup toolchain
install` command
--force Force an update, even if some components are missing
--allow-downgrade Allow rustup to downgrade the toolchain to satisfy your component
choice
--force-non-host Install toolchains that require an emulator. See
https://github.com/rust-lang/rustup/wiki/Non-host-toolchains
-h, --help Print help
--profile <PROFILE> [possible values: minimal, default, complete]
-c, --component <COMPONENT>... Add specific components on installation
-t, --target <TARGET>... Add specific targets on installation
--no-self-update Don't perform self update when running the `rustup toolchain
install` command
--force Force an update, even if some components are missing
--allow-downgrade Allow rustup to downgrade the toolchain to satisfy your component
choice
--force-non-host Install toolchains that require an emulator. See
https://github.com/rust-lang/rustup/wiki/Non-host-toolchains
-h, --help Print help
"""
stderr = ""
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
bin.name = "rustup"
args = ["toolchain","link","--help"]
args = ["toolchain", "link", "--help"]
stdout = """
...
Create a custom toolchain by symlinking to a directory
Usage: rustup[EXE] toolchain link <toolchain> <path>
Usage: rustup[EXE] toolchain link <TOOLCHAIN> <PATH>
Arguments:
<toolchain> Custom toolchain name
<path> Path to the directory
<TOOLCHAIN> Custom toolchain name
<PATH> Path to the directory
Options:
-h, --help Print help
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ stdout = """
...
Uninstall a toolchain
Usage: rustup[EXE] toolchain uninstall <toolchain>...
Usage: rustup[EXE] toolchain uninstall <TOOLCHAIN>...
Arguments:
<toolchain>... Toolchain name, such as 'stable', 'nightly', '1.8.0', or a custom toolchain name.
<TOOLCHAIN>... Toolchain name, such as 'stable', 'nightly', '1.8.0', or a custom toolchain name.
For more information see `rustup help toolchain`
Options:
Expand Down
4 changes: 2 additions & 2 deletions tests/suite/cli-ui/rustup/rustup_up_cmd_help_flag_stdout.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ stdout = """
...
Update Rust toolchains and rustup
Usage: rustup[EXE] update [OPTIONS] [toolchain]...
Usage: rustup[EXE] update [OPTIONS] [TOOLCHAIN]...
Arguments:
[toolchain]... Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see
[TOOLCHAIN]... Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see
`rustup help toolchain`
Options:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ stdout = """
...
Update Rust toolchains and rustup
Usage: rustup[EXE] update [OPTIONS] [toolchain]...
Usage: rustup[EXE] update [OPTIONS] [TOOLCHAIN]...
Arguments:
[toolchain]... Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see
[TOOLCHAIN]... Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see
`rustup help toolchain`
Options:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ stdout = """
...
Update Rust toolchains and rustup
Usage: rustup[EXE] update [OPTIONS] [toolchain]...
Usage: rustup[EXE] update [OPTIONS] [TOOLCHAIN]...
Arguments:
[toolchain]... Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see
[TOOLCHAIN]... Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see
`rustup help toolchain`
Options:
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/cli_self_upd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ fn update_bogus_version() {
config.expect_ok(&["rustup-init", "-y", "--no-modify-path"]);
config.expect_err(
&["rustup", "update", "1.0.0-alpha"],
"invalid value '1.0.0-alpha' for '[toolchain]...': invalid toolchain name: '1.0.0-alpha'",
"invalid value '1.0.0-alpha' for '[TOOLCHAIN]...': invalid toolchain name: '1.0.0-alpha'",
);
});
}
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/cli_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ fn cannot_add_empty_named_custom_toolchain() {
let path = path.to_string_lossy();
config.expect_err(
&["rustup", "toolchain", "link", "", &path],
"invalid value '' for '<toolchain>': invalid toolchain name ''",
"invalid value '' for '<TOOLCHAIN>': invalid toolchain name ''",
);
});
}
Expand Down

0 comments on commit 8983028

Please sign in to comment.