Query user for profile at startup when none have been specified (#432)

This commit is contained in:
VAWVAW 2025-05-30 02:25:07 +00:00 committed by GitHub
parent 82ed796a91
commit e99674b245
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,7 +5,7 @@ use std::collections::HashMap;
use std::fmt;
use std::fs::File;
use std::hash::{Hash, Hasher};
use std::io::{BufReader, BufWriter};
use std::io::{BufReader, BufWriter, Write};
use std::path::{Path, PathBuf};
use std::process;
@ -874,11 +874,33 @@ impl ApplicationSettings {
} else if profiles.len() == 1 {
profiles.into_iter().next().unwrap()
} else {
loop {
println!("\nNo profile specified. Available profiles:");
profiles
.keys()
.enumerate()
.for_each(|(i, name)| println!("{}: {}", i, name));
print!("Select a number or 'q' to quit: ");
let _ = std::io::stdout().flush();
let mut input = String::new();
let _ = std::io::stdin().read_line(&mut input);
if input.trim() == "q" {
usage!(
"No profile specified. \
Please use -P or add \"default_profile\" to your configuration.\n\n\
For more information try '--help'",
);
}
if let Ok(i) = input.trim().parse::<usize>() {
if i < profiles.len() {
break profiles.into_iter().nth(i).unwrap();
}
}
println!("\nInvalid index.");
}
};
let macros = merge_maps(macros, profile.macros.take()).unwrap_or_default();