From 79f770b178da2d74f10eaa5668b3c3521ab6bb59 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Sat, 1 Jun 2019 21:54:32 +0900 Subject: fmt: add --stdout option (#2439) --- cli/flags.rs | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'cli') diff --git a/cli/flags.rs b/cli/flags.rs index 7d05d0c01..d0b8f8465 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -167,7 +167,12 @@ This command has implicit access to all permissions (equivalent to deno run --al Automatically downloads Prettier dependencies on first run. - deno fmt --write myfile1.ts myfile2.ts", + deno fmt myfile1.ts myfile2.ts", + ).arg( + Arg::with_name("stdout") + .long("stdout") + .help("Output formated code to stdout") + .takes_value(false), ).arg( Arg::with_name("files") .takes_value(true) @@ -194,7 +199,7 @@ ability to spawn subprocesses. deno run --allow-net --allow-read https://deno.land/std/http/file_server.ts # run program with permission to read whitelist files from disk and listen to network - deno run --allow-net --allow-read=$(pwd) https://deno.land/std/http/file_server.ts + deno run --allow-net --allow-read=$(pwd) https://deno.land/std/http/file_server.ts # run program with all permissions deno run -A https://deno.land/std/http/file_server.ts", @@ -456,8 +461,10 @@ pub fn flags_from_vec( .collect(); argv.extend(files); - // `deno fmt` writes to the files by default - argv.push("--write".to_string()); + if !fmt_match.is_present("stdout") { + // `deno fmt` writes to the files by default + argv.push("--write".to_string()); + } DenoSubcommand::Run } @@ -918,4 +925,28 @@ mod tests { assert_eq!(subcommand, DenoSubcommand::Run); assert_eq!(argv, svec!["deno", "script.ts"]); } + + #[test] + fn test_flags_from_vec_22() { + let (flags, subcommand, argv) = flags_from_vec(svec![ + "deno", + "fmt", + "--stdout", + "script_1.ts", + "script_2.ts" + ]); + assert_eq!( + flags, + DenoFlags { + allow_write: true, + allow_read: true, + ..DenoFlags::default() + } + ); + assert_eq!(subcommand, DenoSubcommand::Run); + assert_eq!( + argv, + svec!["deno", PRETTIER_URL, "script_1.ts", "script_2.ts"] + ); + } } -- cgit v1.2.3