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("