0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -05:00

fix: don't error on version and help flag (#9064)

This commit is contained in:
Luca Casonato 2021-01-09 13:08:03 +01:00 committed by GitHub
parent 6d7da6309e
commit 4361895476
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 2 deletions

View file

@ -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);
}

View file

@ -63,6 +63,42 @@ fn std_lint() {
assert!(status.success());
}
#[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()