diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2020-11-07 01:02:07 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-07 01:02:07 +0900 |
| commit | 8ca753108c85fc5a99c256be5e31793c538b794e (patch) | |
| tree | 3d0377cbf2216a287d9cf7c8946c1007aaf5b3d5 | |
| parent | 91153d5009d110e70768e3665212a880658a79ec (diff) | |
| parent | 1e737249afa1219205f6cc182ce975ffe94f06f9 (diff) | |
| download | rust-8ca753108c85fc5a99c256be5e31793c538b794e.tar.gz rust-8ca753108c85fc5a99c256be5e31793c538b794e.zip | |
Rollup merge of #78514 - jyn514:setup-number, r=Mark-Simulacrum
Allow using 1/2/3/4 for `x.py setup` options This undocumented feature allows you to typo 'a' as '1'. r? ```@Mark-Simulacrum``` cc ```@Lokathor```
| -rw-r--r-- | src/bootstrap/setup.rs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/bootstrap/setup.rs b/src/bootstrap/setup.rs index f5ce45a5bd1..55d2445fc49 100644 --- a/src/bootstrap/setup.rs +++ b/src/bootstrap/setup.rs @@ -127,14 +127,17 @@ pub fn setup(src_path: &Path, profile: Profile) { // Used to get the path for `Subcommand::Setup` pub fn interactive_path() -> io::Result<Profile> { - fn abbrev_all() -> impl Iterator<Item = (String, Profile)> { - ('a'..).map(|c| c.to_string()).zip(Profile::all()) + fn abbrev_all() -> impl Iterator<Item = ((String, String), Profile)> { + ('a'..) + .zip(1..) + .map(|(letter, number)| (letter.to_string(), number.to_string())) + .zip(Profile::all()) } fn parse_with_abbrev(input: &str) -> Result<Profile, String> { let input = input.trim().to_lowercase(); - for (letter, profile) in abbrev_all() { - if input == letter { + for ((letter, number), profile) in abbrev_all() { + if input == letter || input == number { return Ok(profile); } } @@ -142,13 +145,13 @@ pub fn interactive_path() -> io::Result<Profile> { } println!("Welcome to the Rust project! What do you want to do with x.py?"); - for (letter, profile) in abbrev_all() { + for ((letter, _), profile) in abbrev_all() { println!("{}) {}: {}", letter, profile, profile.purpose()); } let template = loop { print!( "Please choose one ({}): ", - abbrev_all().map(|(l, _)| l).collect::<Vec<_>>().join("/") + abbrev_all().map(|((l, _), _)| l).collect::<Vec<_>>().join("/") ); io::stdout().flush()?; let mut input = String::new(); |
