mirror of
https://github.com/youwen5/iamb.git
synced 2025-06-19 13:19:51 -07:00
Query user for profile at startup when none have been specified (#432)
This commit is contained in:
parent
82ed796a91
commit
e99674b245
1 changed files with 28 additions and 6 deletions
|
@ -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 {
|
||||
usage!(
|
||||
"No profile specified. \
|
||||
Please use -P or add \"default_profile\" to your configuration.\n\n\
|
||||
For more information try '--help'",
|
||||
);
|
||||
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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue