Skip to content

Commit fc3dce4

Browse files
feat: allow config as a positional arg or flag arg
to prevent annoying footgun
1 parent 8afe64d commit fc3dce4

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

crescendo/src/main.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,23 @@ static GLOBAL: MiMalloc = MiMalloc;
2626
#[derive(Parser, Debug)]
2727
#[command(version, about, long_about = None)]
2828
struct CliArgs {
29-
config: PathBuf,
29+
/// Path to the configuration file (positional argument)
30+
config_file: Option<PathBuf>,
31+
/// Path to the configuration file (flag variant)
32+
#[arg(short, long, hide = true)]
33+
config: Option<PathBuf>,
3034
}
3135

3236
#[tokio::main(flavor = "current_thread")]
3337
async fn main() {
3438
let args = CliArgs::parse();
3539

36-
println!("[~] Loading config from {}...", args.config.display());
37-
config::init(if args.config.exists() {
38-
Config::from_file(&args.config).unwrap_or_else(|e| panic!("[!] Failed to load config file: {e:?}"))
40+
let config_path = args.config_file.or(args.config).expect("[!] Config file path must be provided.");
41+
println!("[~] Loading config from {}...", config_path.display());
42+
config::init(if config_path.exists() {
43+
Config::from_file(&config_path).unwrap_or_else(|e| panic!("[!] Failed to load config file: {e:?}"))
3944
} else {
40-
panic!("[!] Config file not found: {}", args.config.display());
45+
panic!("[!] Config file not found: {}", config_path.display());
4146
});
4247

4348
if let Err(err) = utils::increase_nofile_limit(config::get().network_worker.total_connections * 10) {

0 commit comments

Comments
 (0)