Commit e99674b245

e99674b2453761b4ef8536506a332c7e08d0bbf6

parent: 82ed796a91

Unregistered key

VAWVAW <94846592+VAWVAW@users.noreply.github.com> · 2025-05-30 02:25 UTC
committer: <noreply@github.com>

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

Layout: unified · split

src/config.rs +28 −6
@@ -5,7 +5,7 @@ use std::collections::HashMap;
55use std::fmt;
66use std::fs::File;
77use std::hash::{Hash, Hasher};
8use std::io::{BufReader, BufWriter};
8use std::io::{BufReader, BufWriter, Write};
99use std::path::{Path, PathBuf};
1010use std::process;
1111
@@ -874,11 +874,33 @@ impl ApplicationSettings {
874874 } else if profiles.len() == 1 {
875875 profiles.into_iter().next().unwrap()
876876 } else {
877 usage!(
878 "No profile specified. \
879 Please use -P or add \"default_profile\" to your configuration.\n\n\
880 For more information try '--help'",
881 );
877 loop {
878 println!("\nNo profile specified. Available profiles:");
879 profiles
880 .keys()
881 .enumerate()
882 .for_each(|(i, name)| println!("{}: {}", i, name));
883
884 print!("Select a number or 'q' to quit: ");
885 let _ = std::io::stdout().flush();
886
887 let mut input = String::new();
888 let _ = std::io::stdin().read_line(&mut input);
889
890 if input.trim() == "q" {
891 usage!(
892 "No profile specified. \
893 Please use -P or add \"default_profile\" to your configuration.\n\n\
894 For more information try '--help'",
895 );
896 }
897 if let Ok(i) = input.trim().parse::<usize>() {
898 if i < profiles.len() {
899 break profiles.into_iter().nth(i).unwrap();
900 }
901 }
902 println!("\nInvalid index.");
903 }
882904 };
883905
884906 let macros = merge_maps(macros, profile.macros.take()).unwrap_or_default();