diff options
Diffstat (limited to 'cli/flags.rs')
-rw-r--r-- | cli/flags.rs | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/cli/flags.rs b/cli/flags.rs index eb98c6032..313d8ff1a 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -41,6 +41,7 @@ pub enum DenoSubcommand { }, Help, Info { + json: bool, file: Option<String>, }, Install { @@ -454,10 +455,11 @@ fn eval_parse(flags: &mut Flags, matches: &clap::ArgMatches) { fn info_parse(flags: &mut Flags, matches: &clap::ArgMatches) { ca_file_arg_parse(flags, matches); unstable_arg_parse(flags, matches); + let json = matches.is_present("json"); no_check_arg_parse(flags, matches); - flags.subcommand = DenoSubcommand::Info { file: matches.value_of("file").map(|f| f.to_string()), + json, }; } @@ -824,6 +826,12 @@ TypeScript compiler cache: Subdirectory containing TS compiler output.", .arg(ca_file_arg()) .arg(no_check_arg()) .arg(unstable_arg()) + .arg( + Arg::with_name("json") + .long("json") + .help("Outputs the information in JSON format") + .takes_value(false), + ) } fn cache_subcommand<'a, 'b>() -> App<'a, 'b> { @@ -1784,6 +1792,19 @@ mod tests { r.unwrap(), Flags { subcommand: DenoSubcommand::Info { + json: false, + file: Some("script.ts".to_string()), + }, + ..Flags::default() + } + ); + + let r = flags_from_vec_safe(svec!["deno", "info", "--json", "script.ts"]); + assert_eq!( + r.unwrap(), + Flags { + subcommand: DenoSubcommand::Info { + json: true, file: Some("script.ts".to_string()), }, ..Flags::default() @@ -1794,7 +1815,22 @@ mod tests { assert_eq!( r.unwrap(), Flags { - subcommand: DenoSubcommand::Info { file: None }, + subcommand: DenoSubcommand::Info { + json: false, + file: None + }, + ..Flags::default() + } + ); + + let r = flags_from_vec_safe(svec!["deno", "info", "--json"]); + assert_eq!( + r.unwrap(), + Flags { + subcommand: DenoSubcommand::Info { + json: true, + file: None + }, ..Flags::default() } ); @@ -2790,6 +2826,7 @@ mod tests { r.unwrap(), Flags { subcommand: DenoSubcommand::Info { + json: false, file: Some("https://example.com".to_string()), }, ca_file: Some("example.crt".to_owned()), |