summaryrefslogtreecommitdiff
path: root/cli/flags.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2019-06-14 19:05:06 +0200
committerRyan Dahl <ry@tinyclouds.org>2019-06-14 10:05:06 -0700
commit3dff147d0ca1a2cd8d264d20a178d71cb38b1c4e (patch)
tree71a0ee8049e4452df471e0a7321435039c7a6f27 /cli/flags.rs
parent52448f351d7b0882ac67e2974b93c1e730f5dbb3 (diff)
feat: add deno install command (#2522)
Diffstat (limited to 'cli/flags.rs')
-rw-r--r--cli/flags.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/cli/flags.rs b/cli/flags.rs
index 8b95aefae..a4cbd2133 100644
--- a/cli/flags.rs
+++ b/cli/flags.rs
@@ -339,6 +339,29 @@ Demonstrates breaking the input up by space delimiter instead of by lines:
.takes_value(true),
).arg(Arg::with_name("code").takes_value(true).required(true)),
).subcommand(
+ SubCommand::with_name("install")
+ .settings(&[
+ AppSettings::DisableVersion,
+ AppSettings::DisableHelpSubcommand,
+ AppSettings::AllowExternalSubcommands,
+ AppSettings::SubcommandRequired,
+ ])
+ .about("Install script as executable")
+ .long_about(
+"Automatically downloads deno_installer dependencies on first run.
+
+ deno install file_server https://deno.land/std/http/file_server.ts --allow-net --allow-read",
+ ).arg(
+ Arg::with_name("exe_name")
+ .help("Executable name")
+ .required(true),
+ ).subcommand(
+ // this is a fake subcommand - it's used in conjunction with
+ // AppSettings:AllowExternalSubcommand to treat it as an
+ // entry point script
+ SubCommand::with_name("<script>").about("Script URL"),
+ ),
+ ).subcommand(
// this is a fake subcommand - it's used in conjunction with
// AppSettings:AllowExternalSubcommand to treat it as an
// entry point script
@@ -485,6 +508,8 @@ fn parse_run_args(mut flags: DenoFlags, matches: &ArgMatches) -> DenoFlags {
/// Used for `deno fmt <files>...` subcommand
const PRETTIER_URL: &str = "https://deno.land/std@v0.7.0/prettier/main.ts";
+/// Used for `deno install...` subcommand
+const INSTALLER_URL: &str = "https://deno.land/std@a3015be/installer/mod.ts";
/// These are currently handled subcommands.
/// There is no "Help" subcommand because it's handled by `clap::App` itself.
@@ -494,6 +519,7 @@ pub enum DenoSubcommand {
Eval,
Fetch,
Info,
+ Install,
Repl,
Run,
Types,
@@ -583,6 +609,30 @@ pub fn flags_from_vec(
argv.extend(vec![file.to_string()]);
DenoSubcommand::Info
}
+ ("install", Some(install_match)) => {
+ flags.allow_read = true;
+ flags.allow_write = true;
+ flags.allow_net = true;
+ flags.allow_env = true;
+ flags.allow_run = true;
+ argv.push(INSTALLER_URL.to_string());
+
+ let exe_name: &str = install_match.value_of("exe_name").unwrap();
+ match install_match.subcommand() {
+ (script_url, Some(script_match)) => {
+ argv.extend(vec![exe_name.to_string(), script_url.to_string()]);
+ let flags: Vec<String> = script_match
+ .values_of("")
+ .unwrap()
+ .map(String::from)
+ .collect();
+ argv.extend(flags);
+
+ DenoSubcommand::Install
+ }
+ _ => unreachable!(),
+ }
+ }
("types", Some(_)) => DenoSubcommand::Types,
("run", Some(run_match)) => {
match run_match.subcommand() {