From 5ccbfecb89960b458d4e56d0a584d06b7e732208 Mon Sep 17 00:00:00 2001 From: lifegpc Date: Tue, 24 May 2022 03:03:36 +0000 Subject: [PATCH] Do not panic if command line have unreconginzed option. Return 1 if no command is parsed. --- .gitignore | 1 + src/main.rs | 2 +- src/opts.rs | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 184feba..b0e1363 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /proc_macros/target .vscode/ test/ +.workspace/ diff --git a/src/main.rs b/src/main.rs index 05fe7dd..00aab34 100644 --- a/src/main.rs +++ b/src/main.rs @@ -112,7 +112,7 @@ impl Main { pub fn run(&mut self) -> i32 { self.cmd = opts::parse_cmd(); if self.cmd.is_none() { - return 0; + return 1; } let cmd = self.cmd.as_ref().unwrap(); self.settings = Some(SettingStore::default()); diff --git a/src/opts.rs b/src/opts.rs index 45d3453..e1fb181 100644 --- a/src/opts.rs +++ b/src/opts.rs @@ -191,7 +191,8 @@ pub fn parse_cmd() -> Option { let result = match opts.parse(&argv[1..]) { Ok(m) => m, Err(err) => { - panic!("{}", err.to_string()) + println!("{}", err.to_string()); + return None; } }; if result.opt_present("h") || result.free.len() == 0 {