mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
fix(cli): show error on unrecognized V8 flag, exit on --help (#6980)
This commit is contained in:
parent
707bfbd5b5
commit
f22b7dc783
4 changed files with 39 additions and 8 deletions
25
cli/main.rs
25
cli/main.rs
|
@ -96,6 +96,7 @@ use state::exit_unstable;
|
|||
use std::env;
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use std::iter::once;
|
||||
use std::path::PathBuf;
|
||||
use std::pin::Pin;
|
||||
use upgrade::upgrade_command;
|
||||
|
@ -666,9 +667,27 @@ pub fn main() {
|
|||
let flags = flags::flags_from_vec(args);
|
||||
|
||||
if let Some(ref v8_flags) = flags.v8_flags {
|
||||
let mut v8_flags_ = v8_flags.clone();
|
||||
v8_flags_.insert(0, "UNUSED_BUT_NECESSARY_ARG0".to_string());
|
||||
v8_set_flags(v8_flags_);
|
||||
let v8_flags_includes_help = v8_flags
|
||||
.iter()
|
||||
.any(|flag| flag == "-help" || flag == "--help");
|
||||
let v8_flags = once("UNUSED_BUT_NECESSARY_ARG0".to_owned())
|
||||
.chain(v8_flags.iter().cloned())
|
||||
.collect::<Vec<_>>();
|
||||
let unrecognized_v8_flags = v8_set_flags(v8_flags)
|
||||
.into_iter()
|
||||
.skip(1)
|
||||
.collect::<Vec<_>>();
|
||||
if !unrecognized_v8_flags.is_empty() {
|
||||
for f in unrecognized_v8_flags {
|
||||
eprintln!("error: V8 did not recognize flag '{}'", f);
|
||||
}
|
||||
eprintln!();
|
||||
eprintln!("For a list of V8 flags, use '--v8-flags=--help'");
|
||||
std::process::exit(1);
|
||||
}
|
||||
if v8_flags_includes_help {
|
||||
std::process::exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
let log_level = match flags.log_level {
|
||||
|
|
|
@ -2030,17 +2030,23 @@ itest!(unbuffered_stdout {
|
|||
|
||||
// Cannot write the expression to evaluate as "console.log(typeof gc)"
|
||||
// because itest! splits args on whitespace.
|
||||
itest!(eval_v8_flags {
|
||||
itest!(v8_flags_eval {
|
||||
args: "eval --v8-flags=--expose-gc console.log(typeof(gc))",
|
||||
output: "v8_flags.js.out",
|
||||
});
|
||||
|
||||
itest!(run_v8_flags {
|
||||
itest!(v8_flags_run {
|
||||
args: "run --v8-flags=--expose-gc v8_flags.js",
|
||||
output: "v8_flags.js.out",
|
||||
});
|
||||
|
||||
itest!(run_v8_help {
|
||||
itest!(v8_flags_unrecognized {
|
||||
args: "repl --v8-flags=--foo,bar,--trace-gc,-baz",
|
||||
output: "v8_flags_unrecognized.out",
|
||||
exit_code: 1,
|
||||
});
|
||||
|
||||
itest!(v8_help {
|
||||
args: "repl --v8-flags=--help",
|
||||
output: "v8_help.out",
|
||||
});
|
||||
|
|
5
cli/tests/v8_flags_unrecognized.out
Normal file
5
cli/tests/v8_flags_unrecognized.out
Normal file
|
@ -0,0 +1,5 @@
|
|||
error: V8 did not recognize flag '--foo'
|
||||
error: V8 did not recognize flag 'bar'
|
||||
error: V8 did not recognize flag '-baz'
|
||||
|
||||
For a list of V8 flags, use '--v8-flags=--help'
|
|
@ -1,3 +1,4 @@
|
|||
[WILDCARD]
|
||||
Synopsis:
|
||||
[WILDCARD]d8[WILDCARD]
|
||||
Options:
|
||||
[WILDCARD]
|
||||
--trace-gc [WILDCARD]
|
||||
|
|
Loading…
Reference in a new issue