diff options
Diffstat (limited to 'cli/flags.rs')
-rw-r--r-- | cli/flags.rs | 188 |
1 files changed, 186 insertions, 2 deletions
diff --git a/cli/flags.rs b/cli/flags.rs index 470d0cf10..693d290c4 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -339,12 +339,111 @@ This command has implicit access to all permissions (equivalent to deno run --al Automatically downloads Prettier dependencies on first run. deno fmt myfile1.ts myfile2.ts", - ).arg( + ) + .arg( Arg::with_name("stdout") .long("stdout") .help("Output formated code to stdout") .takes_value(false), - ).arg( + ) + .arg( + Arg::with_name("print-width") + .long("print-width") + .value_name("int") + .help("Specify the line length that the printer will wrap on.") + .takes_value(true) + .require_equals(true) + ) + .arg( + Arg::with_name("tab-width") + .long("tab-width") + .value_name("int") + .help("Specify the number of spaces per indentation-level.") + .takes_value(true) + .require_equals(true) + ) + .arg( + Arg::with_name("use-tabs") + .long("use-tabs") + .help("Indent lines with tabs instead of spaces.") + .takes_value(false) + ) + .arg( + Arg::with_name("no-semi") + .long("no-semi") + .help("Print semicolons at the ends of statements.") + .takes_value(false) + ) + .arg( + Arg::with_name("single-quote") + .long("single-quote") + .help("Use single quotes instead of double quotes.") + .takes_value(false) + ) + .arg( + Arg::with_name("quote-props") + .long("quote-props") + .value_name("as-needed|consistent|preserve") + .help("Change when properties in objects are quoted.") + .takes_value(true) + .possible_values(&["as-needed", "consistent", "preserve"]) + .require_equals(true) + ) + .arg( + Arg::with_name("jsx-single-quote") + .long("jsx-single-quote") + .help("Use single quotes instead of double quotes in JSX.") + .takes_value(false) + ) + .arg( + Arg::with_name("jsx-bracket-same-line") + .long("jsx-bracket-same-line") + .help( + "Put the > of a multi-line JSX element at the end of the last line +instead of being alone on the next line (does not apply to self closing elements)." + ) + .takes_value(false) + ) + .arg( + Arg::with_name("trailing-comma") + .long("trailing-comma") + .help("Print trailing commas wherever possible when multi-line.") + .takes_value(false) + ) + .arg( + Arg::with_name("no-bracket-spacing") + .long("no-bracket-spacing") + .help("Print spaces between brackets in object literals.") + .takes_value(false) + ) + .arg( + Arg::with_name("arrow-parens") + .long("arrow-parens") + .value_name("avoid|always") + .help("Include parentheses around a sole arrow function parameter.") + .takes_value(true) + .possible_values(&["avoid", "always"]) + .require_equals(true) + ) + .arg( + Arg::with_name("prose-wrap") + .long("prose-wrap") + .value_name("always|never|preserve") + .help("How to wrap prose.") + .takes_value(true) + .possible_values(&["always", "never", "preserve"]) + .require_equals(true) + ) + .arg( + Arg::with_name("end-of-line") + .long("end-of-line") + .value_name("auto|lf|crlf|cr") + .help("Which end of line characters to apply.") + .takes_value(true) + .possible_values(&["auto", "lf", "crlf", "cr"]) + .require_equals(true) + ) + .arg( Arg::with_name("files") .takes_value(true) .multiple(true) @@ -866,6 +965,36 @@ pub fn flags_from_vec( argv.push("--write".to_string()); } + let prettier_flags = [ + ["1", "print-width"], + ["1", "tab-width"], + ["0", "use-tabs"], + ["0", "no-semi"], + ["0", "single-quote"], + ["1", "quote-props"], + ["0", "jsx-single-quote"], + ["0", "jsx-bracket-same-line"], + ["0", "trailing-comma"], + ["0", "no-bracket-spacing"], + ["1", "arrow-parens"], + ["1", "prose-wrap"], + ["1", "end-of-line"], + ]; + + for opt in &prettier_flags { + let t = opt[0]; + let keyword = opt[1]; + + if fmt_match.is_present(&keyword) { + if t == "0" { + argv.push(format!("--{}", keyword)); + } else { + argv.push(format!("--{}", keyword)); + argv.push(fmt_match.value_of(keyword).unwrap().to_string()); + } + } + } + DenoSubcommand::Run } ("info", Some(info_match)) => { @@ -1908,4 +2037,59 @@ mod tests { assert_eq!(subcommand, DenoSubcommand::Run); assert_eq!(argv, svec!["deno", "script.ts"]) } + + #[test] + fn test_flags_from_vec_39() { + let (flags, subcommand, argv) = flags_from_vec(svec![ + "deno", + "fmt", + "--print-width=100", + "--tab-width=4", + "--use-tabs", + "--no-semi", + "--single-quote", + "--arrow-parens=always", + "--prose-wrap=preserve", + "--end-of-line=crlf", + "--quote-props=preserve", + "--jsx-single-quote", + "--jsx-bracket-same-line", + "script.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.ts", + "--write", + "--print-width", + "100", + "--tab-width", + "4", + "--use-tabs", + "--no-semi", + "--single-quote", + "--quote-props", + "preserve", + "--jsx-single-quote", + "--jsx-bracket-same-line", + "--arrow-parens", + "always", + "--prose-wrap", + "preserve", + "--end-of-line", + "crlf" + ] + ); + } } |