diff options
-rw-r--r-- | cli/main.rs | 13 | ||||
-rw-r--r-- | cli/tests/integration_tests.rs | 36 |
2 files changed, 47 insertions, 2 deletions
diff --git a/cli/main.rs b/cli/main.rs index a3b8f3a6d..c9644073b 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -1261,8 +1261,17 @@ pub fn main() { std::process::exit(1); } - let flags = - unwrap_or_exit(flags::flags_from_vec(args).map_err(AnyError::from)); + let flags = match flags::flags_from_vec(args) { + Ok(flags) => flags, + Err(err @ clap::Error { .. }) + if err.kind == clap::ErrorKind::HelpDisplayed + || err.kind == clap::ErrorKind::VersionDisplayed => + { + err.write_to(&mut std::io::stdout()).unwrap(); + std::process::exit(0); + } + Err(err) => unwrap_or_exit(Err(AnyError::from(err))), + }; if !flags.v8_flags.is_empty() { init_v8_flags(&*flags.v8_flags); } diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 20e391171..df55b5e7c 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -64,6 +64,42 @@ fn std_lint() { } #[test] +fn help_flag() { + let status = util::deno_cmd() + .current_dir(util::root_path()) + .arg("--help") + .spawn() + .unwrap() + .wait() + .unwrap(); + assert!(status.success()); +} + +#[test] +fn version_short_flag() { + let status = util::deno_cmd() + .current_dir(util::root_path()) + .arg("-V") + .spawn() + .unwrap() + .wait() + .unwrap(); + assert!(status.success()); +} + +#[test] +fn version_long_flag() { + let status = util::deno_cmd() + .current_dir(util::root_path()) + .arg("--version") + .spawn() + .unwrap() + .wait() + .unwrap(); + assert!(status.success()); +} + +#[test] fn unit_test_lint() { let status = util::deno_cmd() .arg("lint") |