diff options
author | Satya Rohith <me@satyarohith.com> | 2021-02-21 22:28:32 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-21 17:58:32 +0100 |
commit | 06fcfc5c0a2e39f0b723914bb2edb74a99c67bfb (patch) | |
tree | 39f7f2ab171f86ac3dd4dde60f4b1590ec55b5d3 /cli/flags.rs | |
parent | fe1b512820cbdfd2b93ddfc8e935556878339425 (diff) |
feat: add --ext flag to deno eval (#9295)
This PR deprecates the "--ts"/"-T" flag of "deno eval" (which will later be removed in 2.0)
and introduces "--ext" which is used by "deno fmt" for content type selection.
This is to ensure we have a single flag that can be used across subcommands
to select the language (JS/TS).
Diffstat (limited to 'cli/flags.rs')
-rw-r--r-- | cli/flags.rs | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/cli/flags.rs b/cli/flags.rs index c58e3e3d4..0ae8de27d 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -44,7 +44,7 @@ pub enum DenoSubcommand { Eval { print: bool, code: String, - as_typescript: bool, + ext: String, }, Fmt { check: bool, @@ -525,7 +525,14 @@ fn eval_parse(flags: &mut Flags, matches: &clap::ArgMatches) { flags.allow_write = Some(vec![]); flags.allow_plugin = true; flags.allow_hrtime = true; + // TODO(@satyarohith): remove this flag in 2.0. let as_typescript = matches.is_present("ts"); + let ext = if as_typescript { + "ts".to_string() + } else { + matches.value_of("ext").unwrap().to_string() + }; + let print = matches.is_present("print"); let mut code: Vec<String> = matches .values_of("code_arg") @@ -538,11 +545,7 @@ fn eval_parse(flags: &mut Flags, matches: &clap::ArgMatches) { for v in code_args { flags.argv.push(v); } - flags.subcommand = DenoSubcommand::Eval { - print, - code, - as_typescript, - }; + flags.subcommand = DenoSubcommand::Eval { print, code, ext }; } fn info_parse(flags: &mut Flags, matches: &clap::ArgMatches) { @@ -999,17 +1002,27 @@ fn eval_subcommand<'a, 'b>() -> App<'a, 'b> { deno eval \"console.log('hello world')\" To evaluate as TypeScript: - deno eval -T \"const v: string = 'hello'; console.log(v)\" + deno eval --ext=ts \"const v: string = 'hello'; console.log(v)\" This command has implicit access to all permissions (--allow-all).", ) .arg( + // TODO(@satyarohith): remove this argument in 2.0. Arg::with_name("ts") .long("ts") .short("T") .help("Treat eval input as TypeScript") .takes_value(false) - .multiple(false), + .multiple(false) + .hidden(true), + ) + .arg( + Arg::with_name("ext") + .long("ext") + .help("Set standard input (stdin) content type") + .takes_value(true) + .default_value("js") + .possible_values(&["ts", "tsx", "js", "jsx"]), ) .arg( Arg::with_name("print") @@ -2296,7 +2309,7 @@ mod tests { subcommand: DenoSubcommand::Eval { print: false, code: "'console.log(\"hello\")'".to_string(), - as_typescript: false, + ext: "js".to_string(), }, allow_net: Some(vec![]), allow_env: true, @@ -2319,7 +2332,7 @@ mod tests { subcommand: DenoSubcommand::Eval { print: true, code: "1+2".to_string(), - as_typescript: false, + ext: "js".to_string(), }, allow_net: Some(vec![]), allow_env: true, @@ -2343,7 +2356,7 @@ mod tests { subcommand: DenoSubcommand::Eval { print: false, code: "'console.log(\"hello\")'".to_string(), - as_typescript: true, + ext: "ts".to_string(), }, allow_net: Some(vec![]), allow_env: true, @@ -2367,7 +2380,7 @@ mod tests { subcommand: DenoSubcommand::Eval { print: false, code: "42".to_string(), - as_typescript: false, + ext: "js".to_string(), }, unstable: true, import_map_path: Some("import_map.json".to_string()), @@ -2410,7 +2423,7 @@ mod tests { subcommand: DenoSubcommand::Eval { print: false, code: "console.log(Deno.args)".to_string(), - as_typescript: false, + ext: "js".to_string(), }, argv: svec!["arg1", "arg2"], allow_net: Some(vec![]), |