mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 23:34:47 -05:00
feat: add deno install command (#2522)
This commit is contained in:
parent
52448f351d
commit
3dff147d0c
2 changed files with 51 additions and 0 deletions
50
cli/flags.rs
50
cli/flags.rs
|
@ -338,6 +338,29 @@ Demonstrates breaking the input up by space delimiter instead of by lines:
|
||||||
.help("Set delimiter, defaults to newline")
|
.help("Set delimiter, defaults to newline")
|
||||||
.takes_value(true),
|
.takes_value(true),
|
||||||
).arg(Arg::with_name("code").takes_value(true).required(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(
|
).subcommand(
|
||||||
// this is a fake subcommand - it's used in conjunction with
|
// this is a fake subcommand - it's used in conjunction with
|
||||||
// AppSettings:AllowExternalSubcommand to treat it as an
|
// AppSettings:AllowExternalSubcommand to treat it as an
|
||||||
|
@ -485,6 +508,8 @@ fn parse_run_args(mut flags: DenoFlags, matches: &ArgMatches) -> DenoFlags {
|
||||||
|
|
||||||
/// Used for `deno fmt <files>...` subcommand
|
/// Used for `deno fmt <files>...` subcommand
|
||||||
const PRETTIER_URL: &str = "https://deno.land/std@v0.7.0/prettier/main.ts";
|
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.
|
/// These are currently handled subcommands.
|
||||||
/// There is no "Help" subcommand because it's handled by `clap::App` itself.
|
/// There is no "Help" subcommand because it's handled by `clap::App` itself.
|
||||||
|
@ -494,6 +519,7 @@ pub enum DenoSubcommand {
|
||||||
Eval,
|
Eval,
|
||||||
Fetch,
|
Fetch,
|
||||||
Info,
|
Info,
|
||||||
|
Install,
|
||||||
Repl,
|
Repl,
|
||||||
Run,
|
Run,
|
||||||
Types,
|
Types,
|
||||||
|
@ -583,6 +609,30 @@ pub fn flags_from_vec(
|
||||||
argv.extend(vec![file.to_string()]);
|
argv.extend(vec![file.to_string()]);
|
||||||
DenoSubcommand::Info
|
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,
|
("types", Some(_)) => DenoSubcommand::Types,
|
||||||
("run", Some(run_match)) => {
|
("run", Some(run_match)) => {
|
||||||
match run_match.subcommand() {
|
match run_match.subcommand() {
|
||||||
|
|
|
@ -347,6 +347,7 @@ fn main() {
|
||||||
DenoSubcommand::Eval => eval_command(flags, argv),
|
DenoSubcommand::Eval => eval_command(flags, argv),
|
||||||
DenoSubcommand::Fetch => fetch_or_info_command(flags, argv, false),
|
DenoSubcommand::Fetch => fetch_or_info_command(flags, argv, false),
|
||||||
DenoSubcommand::Info => fetch_or_info_command(flags, argv, true),
|
DenoSubcommand::Info => fetch_or_info_command(flags, argv, true),
|
||||||
|
DenoSubcommand::Install => run_script(flags, argv),
|
||||||
DenoSubcommand::Repl => run_repl(flags, argv),
|
DenoSubcommand::Repl => run_repl(flags, argv),
|
||||||
DenoSubcommand::Run => run_script(flags, argv),
|
DenoSubcommand::Run => run_script(flags, argv),
|
||||||
DenoSubcommand::Types => types_command(),
|
DenoSubcommand::Types => types_command(),
|
||||||
|
|
Loading…
Reference in a new issue