From e4564f45a3ce1cde20334b7fb82f1f9fbab116e8 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Wed, 19 Jun 2024 20:57:46 -0700 Subject: [PATCH] Don't exit process in `run()` on argument parse error (#2176) --- src/run.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/run.rs b/src/run.rs index 38b2233..a745112 100644 --- a/src/run.rs +++ b/src/run.rs @@ -1,7 +1,6 @@ use super::*; -/// Main entry point into `just`. Parse arguments from `args` and run. `run()` -/// will exit the proceess if `args` cannot be parsed. +/// Main entry point into `just`. Parse arguments from `args` and run. #[allow(clippy::missing_errors_doc)] pub fn run(args: impl Iterator + Clone>) -> Result<(), i32> { #[cfg(windows)] @@ -18,7 +17,10 @@ pub fn run(args: impl Iterator + Clone>) -> Result<() let app = Config::app(); info!("Parsing command line arguments…"); - let matches = app.get_matches_from(args); + let matches = app.try_get_matches_from(args).map_err(|err| { + err.print().ok(); + err.exit_code() + })?; let config = Config::from_matches(&matches).map_err(Error::from);