diff --git a/src/main.rs b/src/main.rs index bca60c3..c22bbce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use std::env::{set_current_dir as cd, set_var}; use structopt::StructOpt; +use structopt::clap::ErrorKind as ClapError; // For UNIX extended metadata mod cli; @@ -11,11 +12,27 @@ mod task; use log::Context; fn main() -> Result<(), std::io::Error> { + let mut context = Context::new(); + // TODO: use StructOpt::from_iter_safe so we can hook on Cli error // to display additional unknown_arg error message. - let cmd = cli::Cli::from_args(); - - let mut context = Context::new(); + //let cmd = cli::Cli::from_args(); + let res = cli::Cli::from_iter_safe(std::env::args()); + if res.is_err() { + let e = res.unwrap_err(); + match &e.kind { + ClapError::UnknownArgument => { + context.insert("$i18n_arg".to_string(), e.info.unwrap().first().unwrap().to_string()); + log::error("unknown_arg", &context); + std::process::exit(1); + }, + /*ClapError::HelpDisplayed { + e.exit() + }*/ + _ => e.exit() + } + } + let cmd = res.unwrap(); let basedir = cmd.basedir(); context.insert("$i18n_basedir".to_string(), basedir.to_str().unwrap().to_string());