From 591b5e4a7dfc1c3537c7a2c7091ebe3890271780 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 13 Apr 2019 19:24:15 +0200 Subject: [PATCH] Add deno eval subcommand (#2102) --- cli/flags.rs | 82 ++++++++++++++++++++++++++------------------- cli/main.rs | 32 +++++++++++++----- tests/029_eval.out | 1 + tests/029_eval.test | 2 ++ website/manual.md | 1 + 5 files changed, 75 insertions(+), 43 deletions(-) create mode 100644 tests/029_eval.out create mode 100644 tests/029_eval.test diff --git a/cli/flags.rs b/cli/flags.rs index 9f6a978b21..3fd3f91fbc 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -25,6 +25,7 @@ pub struct DenoFlags { pub prefetch: bool, pub info: bool, pub fmt: bool, + pub eval: bool, } impl<'a> From> for DenoFlags { @@ -82,28 +83,26 @@ impl<'a> From> for DenoFlags { if matches.is_present("fmt") { flags.fmt = true; } + if matches.is_present("eval") { + flags.eval = true; + } flags } } -#[cfg_attr(feature = "cargo-clippy", allow(stutter))] -pub fn set_flags( - args: Vec, -) -> Result<(DenoFlags, Vec), String> { - let app_settings: Vec = vec![ - AppSettings::AllowExternalSubcommands, - AppSettings::DisableHelpSubcommand, - ]; - - let env_variables_help = "ENVIRONMENT VARIABLES: +static ENV_VARIABLES_HELP: &str = "ENVIRONMENT VARIABLES: DENO_DIR Set deno's base directory NO_COLOR Set to disable color"; - let clap_app = App::new("deno") +fn create_cli_app<'a, 'b>() -> App<'a, 'b> { + let cli_app = App::new("deno") + .bin_name("deno") .global_settings(&[AppSettings::ColorNever]) - .settings(&app_settings[..]) - .after_help(env_variables_help) + .settings(&[ + AppSettings::AllowExternalSubcommands, + AppSettings::DisableHelpSubcommand, + ]).after_help(ENV_VARIABLES_HELP) .arg( Arg::with_name("version") .short("v") @@ -171,18 +170,25 @@ pub fn set_flags( .long("prefetch") .help("Prefetch the dependencies"), ).subcommand( - // TODO(bartlomieju): version is not handled properly SubCommand::with_name("info") + .setting(AppSettings::DisableVersion) .about("Show source file related info") .arg(Arg::with_name("file").takes_value(true).required(true)), ).subcommand( - // TODO(bartlomieju): version is not handled properly - SubCommand::with_name("fmt").about("Format files").arg( - Arg::with_name("files") - .takes_value(true) - .multiple(true) - .required(true), - ), + SubCommand::with_name("eval") + .setting(AppSettings::DisableVersion) + .about("Eval script") + .arg(Arg::with_name("code").takes_value(true).required(true)), + ).subcommand( + SubCommand::with_name("fmt") + .setting(AppSettings::DisableVersion) + .about("Format files") + .arg( + Arg::with_name("files") + .takes_value(true) + .multiple(true) + .required(true), + ), ).subcommand( // this is a fake subcommand - it's used in conjunction with // AppSettings:AllowExternalSubcommand to treat it as an @@ -190,43 +196,49 @@ pub fn set_flags( SubCommand::with_name("