Skip to content

Commit 1e73724

Browse files
committed
Allow using 1/2/3/4 for x.py setup options
This undocumented feature allows you to typo 'a' as '1'.
1 parent 07e968b commit 1e73724

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/bootstrap/setup.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -127,28 +127,31 @@ pub fn setup(src_path: &Path, profile: Profile) {
127127

128128
// Used to get the path for `Subcommand::Setup`
129129
pub fn interactive_path() -> io::Result<Profile> {
130-
fn abbrev_all() -> impl Iterator<Item = (String, Profile)> {
131-
('a'..).map(|c| c.to_string()).zip(Profile::all())
130+
fn abbrev_all() -> impl Iterator<Item = ((String, String), Profile)> {
131+
('a'..)
132+
.zip(1..)
133+
.map(|(letter, number)| (letter.to_string(), number.to_string()))
134+
.zip(Profile::all())
132135
}
133136

134137
fn parse_with_abbrev(input: &str) -> Result<Profile, String> {
135138
let input = input.trim().to_lowercase();
136-
for (letter, profile) in abbrev_all() {
137-
if input == letter {
139+
for ((letter, number), profile) in abbrev_all() {
140+
if input == letter || input == number {
138141
return Ok(profile);
139142
}
140143
}
141144
input.parse()
142145
}
143146

144147
println!("Welcome to the Rust project! What do you want to do with x.py?");
145-
for (letter, profile) in abbrev_all() {
148+
for ((letter, _), profile) in abbrev_all() {
146149
println!("{}) {}: {}", letter, profile, profile.purpose());
147150
}
148151
let template = loop {
149152
print!(
150153
"Please choose one ({}): ",
151-
abbrev_all().map(|(l, _)| l).collect::<Vec<_>>().join("/")
154+
abbrev_all().map(|((l, _), _)| l).collect::<Vec<_>>().join("/")
152155
);
153156
io::stdout().flush()?;
154157
let mut input = String::new();

0 commit comments

Comments
 (0)