Skip to content

Commit

Permalink
Allow using 1/2/3/4 for x.py setup options
Browse files Browse the repository at this point in the history
This undocumented feature allows you to typo 'a' as '1'.
  • Loading branch information
jyn514 committed Oct 29, 2020
1 parent 07e968b commit 1e73724
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/bootstrap/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,28 +127,31 @@ 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);
}
}
input.parse()
}

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();
Expand Down

0 comments on commit 1e73724

Please sign in to comment.