2020-01-02 15:13:47 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2019-06-26 06:02:13 -04:00
|
|
|
use clap::App;
|
|
|
|
use clap::AppSettings;
|
|
|
|
use clap::Arg;
|
|
|
|
use clap::ArgMatches;
|
|
|
|
use clap::SubCommand;
|
2019-06-22 12:02:51 -04:00
|
|
|
use log::Level;
|
2020-04-03 13:40:11 -04:00
|
|
|
use std::net::SocketAddr;
|
2020-05-29 11:27:43 -04:00
|
|
|
use std::path::PathBuf;
|
2019-11-26 11:06:32 -05:00
|
|
|
|
|
|
|
/// Creates vector of strings, Vec<String>
|
|
|
|
macro_rules! svec {
|
|
|
|
($($x:expr),*) => (vec![$($x.to_string()),*]);
|
|
|
|
}
|
2018-08-17 16:34:30 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
|
|
pub enum DenoSubcommand {
|
2020-02-04 14:24:33 -05:00
|
|
|
Bundle {
|
|
|
|
source_file: String,
|
2020-02-11 04:29:36 -05:00
|
|
|
out_file: Option<PathBuf>,
|
2020-02-04 14:24:33 -05:00
|
|
|
},
|
|
|
|
Completions {
|
|
|
|
buf: Box<[u8]>,
|
|
|
|
},
|
2020-03-28 14:16:57 -04:00
|
|
|
Doc {
|
|
|
|
json: bool,
|
2020-04-09 08:34:24 -04:00
|
|
|
source_file: Option<String>,
|
2020-03-28 14:16:57 -04:00
|
|
|
filter: Option<String>,
|
|
|
|
},
|
2020-02-04 14:24:33 -05:00
|
|
|
Eval {
|
|
|
|
code: String,
|
2020-02-28 09:17:56 -05:00
|
|
|
as_typescript: bool,
|
2020-02-04 14:24:33 -05:00
|
|
|
},
|
2020-04-07 11:24:47 -04:00
|
|
|
Cache {
|
2020-02-04 14:24:33 -05:00
|
|
|
files: Vec<String>,
|
|
|
|
},
|
2020-02-13 16:02:18 -05:00
|
|
|
Fmt {
|
2020-01-29 21:16:48 -05:00
|
|
|
check: bool,
|
2020-02-13 16:02:18 -05:00
|
|
|
files: Vec<String>,
|
2020-01-29 21:16:48 -05:00
|
|
|
},
|
2019-11-26 11:06:32 -05:00
|
|
|
Help,
|
2020-02-04 14:24:33 -05:00
|
|
|
Info {
|
|
|
|
file: Option<String>,
|
|
|
|
},
|
2020-01-30 18:42:39 -05:00
|
|
|
Install {
|
|
|
|
module_url: String,
|
|
|
|
args: Vec<String>,
|
2020-05-01 15:33:11 -04:00
|
|
|
name: Option<String>,
|
|
|
|
root: Option<PathBuf>,
|
2020-02-08 03:49:55 -05:00
|
|
|
force: bool,
|
2020-01-30 18:42:39 -05:00
|
|
|
},
|
2019-11-26 11:06:32 -05:00
|
|
|
Repl,
|
2020-02-04 14:24:33 -05:00
|
|
|
Run {
|
|
|
|
script: String,
|
|
|
|
},
|
2020-02-11 06:01:56 -05:00
|
|
|
Test {
|
|
|
|
fail_fast: bool,
|
2020-04-27 07:05:26 -04:00
|
|
|
quiet: bool,
|
2020-02-11 06:01:56 -05:00
|
|
|
allow_none: bool,
|
|
|
|
include: Option<Vec<String>>,
|
2020-04-02 09:26:40 -04:00
|
|
|
filter: Option<String>,
|
2020-02-11 06:01:56 -05:00
|
|
|
},
|
2019-11-26 11:06:32 -05:00
|
|
|
Types,
|
2020-03-23 11:37:24 -04:00
|
|
|
Upgrade {
|
|
|
|
dry_run: bool,
|
|
|
|
force: bool,
|
2020-05-09 06:31:15 -04:00
|
|
|
version: Option<String>,
|
2020-03-23 11:37:24 -04:00
|
|
|
},
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for DenoSubcommand {
|
|
|
|
fn default() -> DenoSubcommand {
|
2020-02-04 14:24:33 -05:00
|
|
|
DenoSubcommand::Repl
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
2018-08-17 16:34:30 -04:00
|
|
|
}
|
|
|
|
|
2019-01-08 14:44:06 -05:00
|
|
|
#[derive(Clone, Debug, PartialEq, Default)]
|
2020-02-26 05:52:15 -05:00
|
|
|
pub struct Flags {
|
2019-12-03 17:23:10 -05:00
|
|
|
/// Vector of CLI arguments - these are user script arguments, all Deno
|
|
|
|
/// specific flags are removed.
|
2019-11-26 11:06:32 -05:00
|
|
|
pub argv: Vec<String>,
|
|
|
|
pub subcommand: DenoSubcommand,
|
|
|
|
|
2018-08-31 07:51:12 -04:00
|
|
|
pub allow_env: bool,
|
2019-05-23 12:28:29 -04:00
|
|
|
pub allow_hrtime: bool,
|
2020-04-30 11:23:40 -04:00
|
|
|
pub allow_net: bool,
|
|
|
|
pub allow_plugin: bool,
|
|
|
|
pub allow_read: bool,
|
|
|
|
pub allow_run: bool,
|
|
|
|
pub allow_write: bool,
|
|
|
|
pub cache_blacklist: Vec<String>,
|
|
|
|
pub ca_file: Option<String>,
|
2019-12-03 17:48:53 -05:00
|
|
|
pub cached_only: bool,
|
2020-04-30 11:23:40 -04:00
|
|
|
pub config_path: Option<String>,
|
|
|
|
pub import_map_path: Option<String>,
|
2020-04-03 13:40:11 -04:00
|
|
|
pub inspect: Option<SocketAddr>,
|
|
|
|
pub inspect_brk: Option<SocketAddr>,
|
2019-11-03 10:39:27 -05:00
|
|
|
pub lock: Option<String>,
|
|
|
|
pub lock_write: bool,
|
2020-04-30 11:23:40 -04:00
|
|
|
pub log_level: Option<Level>,
|
|
|
|
pub net_whitelist: Vec<String>,
|
|
|
|
pub no_prompts: bool,
|
|
|
|
pub no_remote: bool,
|
|
|
|
pub read_whitelist: Vec<PathBuf>,
|
|
|
|
pub reload: bool,
|
|
|
|
pub seed: Option<u64>,
|
|
|
|
pub unstable: bool,
|
|
|
|
pub v8_flags: Option<Vec<String>>,
|
|
|
|
pub version: bool,
|
|
|
|
pub write_whitelist: Vec<PathBuf>,
|
2018-11-15 12:56:17 -05:00
|
|
|
}
|
|
|
|
|
2020-02-11 04:29:36 -05:00
|
|
|
fn join_paths(whitelist: &[PathBuf], d: &str) -> String {
|
|
|
|
whitelist
|
|
|
|
.iter()
|
|
|
|
.map(|path| path.to_str().unwrap().to_string())
|
|
|
|
.collect::<Vec<String>>()
|
|
|
|
.join(d)
|
|
|
|
}
|
|
|
|
|
2020-02-26 05:52:15 -05:00
|
|
|
impl Flags {
|
2020-01-30 18:42:39 -05:00
|
|
|
/// Return list of permission arguments that are equivalent
|
|
|
|
/// to the ones used to create `self`.
|
|
|
|
pub fn to_permission_args(&self) -> Vec<String> {
|
|
|
|
let mut args = vec![];
|
|
|
|
|
|
|
|
if !self.read_whitelist.is_empty() {
|
2020-02-11 04:29:36 -05:00
|
|
|
let s = format!("--allow-read={}", join_paths(&self.read_whitelist, ","));
|
2020-01-30 18:42:39 -05:00
|
|
|
args.push(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
if self.allow_read {
|
|
|
|
args.push("--allow-read".to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
if !self.write_whitelist.is_empty() {
|
2020-02-11 04:29:36 -05:00
|
|
|
let s =
|
|
|
|
format!("--allow-write={}", join_paths(&self.write_whitelist, ","));
|
2020-01-30 18:42:39 -05:00
|
|
|
args.push(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
if self.allow_write {
|
|
|
|
args.push("--allow-write".to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
if !self.net_whitelist.is_empty() {
|
|
|
|
let s = format!("--allow-net={}", self.net_whitelist.join(","));
|
|
|
|
args.push(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
if self.allow_net {
|
|
|
|
args.push("--allow-net".to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
if self.allow_env {
|
|
|
|
args.push("--allow-env".to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
if self.allow_run {
|
|
|
|
args.push("--allow-run".to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
if self.allow_plugin {
|
|
|
|
args.push("--allow-plugin".to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
if self.allow_hrtime {
|
|
|
|
args.push("--allow-hrtime".to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
args
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-13 13:24:15 -04:00
|
|
|
static ENV_VARIABLES_HELP: &str = "ENVIRONMENT VARIABLES:
|
2020-04-16 18:15:42 -04:00
|
|
|
DENO_DIR Set deno's base directory (defaults to $HOME/.deno)
|
|
|
|
DENO_INSTALL_ROOT Set deno install's output directory
|
|
|
|
(defaults to $HOME/.deno/bin)
|
|
|
|
NO_COLOR Set to disable color
|
|
|
|
HTTP_PROXY Proxy address for HTTP requests
|
|
|
|
(module downloads, fetch)
|
|
|
|
HTTPS_PROXY Same but for HTTPS";
|
2019-06-05 13:44:46 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
static DENO_HELP: &str = "A secure JavaScript and TypeScript runtime
|
2019-05-06 10:48:19 -04:00
|
|
|
|
2020-05-17 13:24:39 -04:00
|
|
|
Docs: https://deno.land/manual
|
2020-03-10 19:23:08 -04:00
|
|
|
Modules: https://deno.land/std/ https://deno.land/x/
|
2019-05-23 14:57:44 -04:00
|
|
|
Bugs: https://github.com/denoland/deno/issues
|
|
|
|
|
2020-05-04 07:03:30 -04:00
|
|
|
To start the REPL:
|
2019-05-23 14:57:44 -04:00
|
|
|
deno
|
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
To execute a script:
|
2020-03-10 19:23:08 -04:00
|
|
|
deno run https://deno.land/std/examples/welcome.ts
|
2019-05-23 14:57:44 -04:00
|
|
|
|
2020-03-10 19:23:08 -04:00
|
|
|
To evaluate code in the shell:
|
|
|
|
deno eval \"console.log(30933 + 404)\"
|
2020-05-04 07:03:30 -04:00
|
|
|
";
|
2019-05-23 14:57:44 -04:00
|
|
|
|
2019-12-15 08:38:34 -05:00
|
|
|
lazy_static! {
|
|
|
|
static ref LONG_VERSION: String = format!(
|
|
|
|
"{}\nv8 {}\ntypescript {}",
|
|
|
|
crate::version::DENO,
|
|
|
|
crate::version::v8(),
|
|
|
|
crate::version::TYPESCRIPT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
/// Main entry point for parsing deno's command line flags.
|
|
|
|
/// Exits the process on error.
|
2020-02-26 05:52:15 -05:00
|
|
|
pub fn flags_from_vec(args: Vec<String>) -> Flags {
|
2019-11-26 11:06:32 -05:00
|
|
|
match flags_from_vec_safe(args) {
|
|
|
|
Ok(flags) => flags,
|
|
|
|
Err(err) => err.exit(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Same as flags_from_vec but does not exit on error.
|
2020-02-26 05:52:15 -05:00
|
|
|
pub fn flags_from_vec_safe(args: Vec<String>) -> clap::Result<Flags> {
|
2019-11-26 11:06:32 -05:00
|
|
|
let app = clap_root();
|
|
|
|
let matches = app.get_matches_from_safe(args)?;
|
|
|
|
|
2020-02-26 05:52:15 -05:00
|
|
|
let mut flags = Flags::default();
|
2019-11-26 11:06:32 -05:00
|
|
|
|
|
|
|
if matches.is_present("log-level") {
|
|
|
|
flags.log_level = match matches.value_of("log-level").unwrap() {
|
|
|
|
"debug" => Some(Level::Debug),
|
|
|
|
"info" => Some(Level::Info),
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
}
|
2020-03-10 08:26:17 -04:00
|
|
|
if matches.is_present("quiet") {
|
|
|
|
flags.log_level = Some(Level::Error);
|
|
|
|
}
|
2019-11-26 11:06:32 -05:00
|
|
|
|
|
|
|
if let Some(m) = matches.subcommand_matches("run") {
|
|
|
|
run_parse(&mut flags, m);
|
|
|
|
} else if let Some(m) = matches.subcommand_matches("fmt") {
|
|
|
|
fmt_parse(&mut flags, m);
|
|
|
|
} else if let Some(m) = matches.subcommand_matches("types") {
|
|
|
|
types_parse(&mut flags, m);
|
2020-04-07 11:24:47 -04:00
|
|
|
} else if let Some(m) = matches.subcommand_matches("cache") {
|
|
|
|
cache_parse(&mut flags, m);
|
2019-11-26 11:06:32 -05:00
|
|
|
} else if let Some(m) = matches.subcommand_matches("info") {
|
|
|
|
info_parse(&mut flags, m);
|
|
|
|
} else if let Some(m) = matches.subcommand_matches("eval") {
|
|
|
|
eval_parse(&mut flags, m);
|
|
|
|
} else if let Some(m) = matches.subcommand_matches("repl") {
|
|
|
|
repl_parse(&mut flags, m);
|
|
|
|
} else if let Some(m) = matches.subcommand_matches("bundle") {
|
|
|
|
bundle_parse(&mut flags, m);
|
|
|
|
} else if let Some(m) = matches.subcommand_matches("install") {
|
|
|
|
install_parse(&mut flags, m);
|
|
|
|
} else if let Some(m) = matches.subcommand_matches("completions") {
|
|
|
|
completions_parse(&mut flags, m);
|
|
|
|
} else if let Some(m) = matches.subcommand_matches("test") {
|
|
|
|
test_parse(&mut flags, m);
|
2020-03-23 11:37:24 -04:00
|
|
|
} else if let Some(m) = matches.subcommand_matches("upgrade") {
|
|
|
|
upgrade_parse(&mut flags, m);
|
2020-03-28 14:16:57 -04:00
|
|
|
} else if let Some(m) = matches.subcommand_matches("doc") {
|
|
|
|
doc_parse(&mut flags, m);
|
2019-11-26 11:06:32 -05:00
|
|
|
} else {
|
2020-05-04 07:03:30 -04:00
|
|
|
repl_parse(&mut flags, &matches);
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(flags)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn clap_root<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
clap::App::new("deno")
|
|
|
|
.bin_name("deno")
|
|
|
|
.global_settings(&[
|
|
|
|
AppSettings::UnifiedHelpMessage,
|
|
|
|
AppSettings::ColorNever,
|
|
|
|
AppSettings::VersionlessSubcommands,
|
|
|
|
])
|
|
|
|
// Disable clap's auto-detection of terminal width
|
|
|
|
.set_term_width(0)
|
|
|
|
// Disable each subcommand having its own version.
|
|
|
|
.version(crate::version::DENO)
|
2019-12-15 08:38:34 -05:00
|
|
|
.long_version(LONG_VERSION.as_str())
|
2019-04-06 18:13:06 -04:00
|
|
|
.arg(
|
2019-06-22 12:02:51 -04:00
|
|
|
Arg::with_name("log-level")
|
|
|
|
.short("L")
|
|
|
|
.long("log-level")
|
|
|
|
.help("Set log level")
|
|
|
|
.takes_value(true)
|
|
|
|
.possible_values(&["debug", "info"])
|
2019-05-03 17:15:16 -04:00
|
|
|
.global(true),
|
2019-07-31 11:02:20 -04:00
|
|
|
)
|
2020-03-10 08:26:17 -04:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("quiet")
|
|
|
|
.short("q")
|
|
|
|
.long("quiet")
|
|
|
|
.help("Suppress diagnostic output")
|
|
|
|
.long_help(
|
|
|
|
"Suppress diagnostic output
|
|
|
|
By default, subcommands print human-readable diagnostic messages to stderr.
|
|
|
|
If the flag is set, restrict these messages to errors.",
|
|
|
|
)
|
|
|
|
.global(true),
|
|
|
|
)
|
2019-11-26 11:06:32 -05:00
|
|
|
.subcommand(bundle_subcommand())
|
|
|
|
.subcommand(completions_subcommand())
|
|
|
|
.subcommand(eval_subcommand())
|
2020-04-07 11:24:47 -04:00
|
|
|
.subcommand(cache_subcommand())
|
2019-11-26 11:06:32 -05:00
|
|
|
.subcommand(fmt_subcommand())
|
|
|
|
.subcommand(info_subcommand())
|
|
|
|
.subcommand(install_subcommand())
|
|
|
|
.subcommand(repl_subcommand())
|
|
|
|
.subcommand(run_subcommand())
|
|
|
|
.subcommand(test_subcommand())
|
|
|
|
.subcommand(types_subcommand())
|
2020-03-23 11:37:24 -04:00
|
|
|
.subcommand(upgrade_subcommand())
|
2020-03-28 14:16:57 -04:00
|
|
|
.subcommand(doc_subcommand())
|
2019-11-26 11:06:32 -05:00
|
|
|
.long_about(DENO_HELP)
|
|
|
|
.after_help(ENV_VARIABLES_HELP)
|
|
|
|
}
|
2019-11-13 10:35:56 -05:00
|
|
|
|
2020-04-30 11:23:40 -04:00
|
|
|
fn types_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|
|
|
unstable_arg_parse(flags, matches);
|
2019-11-26 11:06:32 -05:00
|
|
|
flags.subcommand = DenoSubcommand::Types;
|
|
|
|
}
|
2019-06-11 14:38:19 -04:00
|
|
|
|
2020-02-26 05:52:15 -05:00
|
|
|
fn fmt_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
2020-02-13 16:02:18 -05:00
|
|
|
let files = match matches.values_of("files") {
|
|
|
|
Some(f) => f.map(String::from).collect(),
|
|
|
|
None => vec![],
|
2020-01-29 21:16:48 -05:00
|
|
|
};
|
2020-02-13 16:02:18 -05:00
|
|
|
flags.subcommand = DenoSubcommand::Fmt {
|
|
|
|
check: matches.is_present("check"),
|
|
|
|
files,
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
|
|
|
}
|
2019-05-01 19:15:37 -04:00
|
|
|
|
2020-02-26 05:52:15 -05:00
|
|
|
fn install_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
2020-01-30 18:42:39 -05:00
|
|
|
permission_args_parse(flags, matches);
|
2020-02-17 11:59:51 -05:00
|
|
|
ca_file_arg_parse(flags, matches);
|
2020-04-30 11:23:40 -04:00
|
|
|
unstable_arg_parse(flags, matches);
|
2019-11-26 11:06:32 -05:00
|
|
|
|
2020-04-16 18:15:42 -04:00
|
|
|
let root = if matches.is_present("root") {
|
|
|
|
let install_root = matches.value_of("root").unwrap();
|
|
|
|
Some(PathBuf::from(install_root))
|
2019-11-26 11:06:32 -05:00
|
|
|
} else {
|
2020-01-30 18:42:39 -05:00
|
|
|
None
|
|
|
|
};
|
2019-05-01 19:15:37 -04:00
|
|
|
|
2020-02-08 03:49:55 -05:00
|
|
|
let force = matches.is_present("force");
|
2020-05-01 15:33:11 -04:00
|
|
|
let name = matches.value_of("name").map(|s| s.to_string());
|
2020-01-30 18:42:39 -05:00
|
|
|
let cmd_values = matches.values_of("cmd").unwrap();
|
2020-05-01 15:33:11 -04:00
|
|
|
let mut cmd = vec![];
|
2020-01-30 18:42:39 -05:00
|
|
|
for value in cmd_values {
|
2020-05-01 15:33:11 -04:00
|
|
|
cmd.push(value.to_string());
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
2020-01-30 18:42:39 -05:00
|
|
|
|
2020-05-01 15:33:11 -04:00
|
|
|
let module_url = cmd[0].to_string();
|
|
|
|
let args = cmd[1..].to_vec();
|
2020-01-30 18:42:39 -05:00
|
|
|
|
|
|
|
flags.subcommand = DenoSubcommand::Install {
|
2020-05-01 15:33:11 -04:00
|
|
|
name,
|
2020-01-30 18:42:39 -05:00
|
|
|
module_url,
|
|
|
|
args,
|
2020-05-01 15:33:11 -04:00
|
|
|
root,
|
2020-02-08 03:49:55 -05:00
|
|
|
force,
|
2020-01-30 18:42:39 -05:00
|
|
|
};
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
2019-05-01 19:15:37 -04:00
|
|
|
|
2020-02-26 05:52:15 -05:00
|
|
|
fn bundle_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
2020-02-17 11:59:51 -05:00
|
|
|
ca_file_arg_parse(flags, matches);
|
2020-05-07 11:02:03 -04:00
|
|
|
config_arg_parse(flags, matches);
|
2020-04-07 06:32:09 -04:00
|
|
|
importmap_arg_parse(flags, matches);
|
2020-04-27 19:12:38 -04:00
|
|
|
unstable_arg_parse(flags, matches);
|
2020-02-17 11:59:51 -05:00
|
|
|
|
2020-02-04 14:24:33 -05:00
|
|
|
let source_file = matches.value_of("source_file").unwrap().to_string();
|
|
|
|
|
|
|
|
let out_file = if let Some(out_file) = matches.value_of("out_file") {
|
2019-11-26 11:06:32 -05:00
|
|
|
flags.allow_write = true;
|
2020-02-11 04:29:36 -05:00
|
|
|
Some(PathBuf::from(out_file))
|
2020-02-04 14:24:33 -05:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
|
|
|
flags.subcommand = DenoSubcommand::Bundle {
|
|
|
|
source_file,
|
|
|
|
out_file,
|
|
|
|
};
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
2019-05-23 14:57:44 -04:00
|
|
|
|
2020-02-26 05:52:15 -05:00
|
|
|
fn completions_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
2019-11-26 11:06:32 -05:00
|
|
|
let shell: &str = matches.value_of("shell").unwrap();
|
|
|
|
let mut buf: Vec<u8> = vec![];
|
|
|
|
use std::str::FromStr;
|
|
|
|
clap_root().gen_completions_to(
|
|
|
|
"deno",
|
|
|
|
clap::Shell::from_str(shell).unwrap(),
|
|
|
|
&mut buf,
|
|
|
|
);
|
2020-02-04 14:24:33 -05:00
|
|
|
|
|
|
|
flags.subcommand = DenoSubcommand::Completions {
|
|
|
|
buf: buf.into_boxed_slice(),
|
|
|
|
};
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
2019-08-11 20:43:01 -04:00
|
|
|
|
2020-02-26 05:52:15 -05:00
|
|
|
fn repl_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
2019-11-26 23:25:14 -05:00
|
|
|
v8_flags_arg_parse(flags, matches);
|
2020-02-17 11:59:51 -05:00
|
|
|
ca_file_arg_parse(flags, matches);
|
2020-04-01 09:35:34 -04:00
|
|
|
inspect_arg_parse(flags, matches);
|
2020-04-30 11:23:40 -04:00
|
|
|
unstable_arg_parse(flags, matches);
|
2019-11-26 11:06:32 -05:00
|
|
|
flags.subcommand = DenoSubcommand::Repl;
|
|
|
|
flags.allow_net = true;
|
|
|
|
flags.allow_env = true;
|
|
|
|
flags.allow_run = true;
|
|
|
|
flags.allow_read = true;
|
|
|
|
flags.allow_write = true;
|
2019-12-05 15:30:20 -05:00
|
|
|
flags.allow_plugin = true;
|
2019-11-26 11:06:32 -05:00
|
|
|
flags.allow_hrtime = true;
|
|
|
|
}
|
2019-05-01 19:15:37 -04:00
|
|
|
|
2020-02-26 05:52:15 -05:00
|
|
|
fn eval_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
2020-01-26 09:49:34 -05:00
|
|
|
v8_flags_arg_parse(flags, matches);
|
2020-02-17 11:59:51 -05:00
|
|
|
ca_file_arg_parse(flags, matches);
|
2020-04-01 09:35:34 -04:00
|
|
|
inspect_arg_parse(flags, matches);
|
2020-04-30 11:23:40 -04:00
|
|
|
unstable_arg_parse(flags, matches);
|
2019-11-26 11:06:32 -05:00
|
|
|
flags.allow_net = true;
|
|
|
|
flags.allow_env = true;
|
|
|
|
flags.allow_run = true;
|
|
|
|
flags.allow_read = true;
|
|
|
|
flags.allow_write = true;
|
2019-12-05 15:30:20 -05:00
|
|
|
flags.allow_plugin = true;
|
2019-11-26 11:06:32 -05:00
|
|
|
flags.allow_hrtime = true;
|
2020-02-04 14:24:33 -05:00
|
|
|
let code = matches.value_of("code").unwrap().to_string();
|
2020-02-28 09:17:56 -05:00
|
|
|
let as_typescript = matches.is_present("ts");
|
|
|
|
flags.subcommand = DenoSubcommand::Eval {
|
|
|
|
code,
|
|
|
|
as_typescript,
|
|
|
|
}
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
2019-05-01 19:15:37 -04:00
|
|
|
|
2020-02-26 05:52:15 -05:00
|
|
|
fn info_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
2020-02-17 11:59:51 -05:00
|
|
|
ca_file_arg_parse(flags, matches);
|
2020-04-30 11:23:40 -04:00
|
|
|
unstable_arg_parse(flags, matches);
|
2020-02-17 11:59:51 -05:00
|
|
|
|
2020-02-04 14:24:33 -05:00
|
|
|
flags.subcommand = DenoSubcommand::Info {
|
|
|
|
file: matches.value_of("file").map(|f| f.to_string()),
|
|
|
|
};
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
2019-05-01 19:15:37 -04:00
|
|
|
|
2020-04-07 11:24:47 -04:00
|
|
|
fn cache_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
2019-11-26 11:06:32 -05:00
|
|
|
reload_arg_parse(flags, matches);
|
|
|
|
lock_args_parse(flags, matches);
|
|
|
|
importmap_arg_parse(flags, matches);
|
|
|
|
config_arg_parse(flags, matches);
|
2019-12-03 17:48:53 -05:00
|
|
|
no_remote_arg_parse(flags, matches);
|
2020-02-17 11:59:51 -05:00
|
|
|
ca_file_arg_parse(flags, matches);
|
2020-04-27 19:12:38 -04:00
|
|
|
unstable_arg_parse(flags, matches);
|
2020-02-04 14:24:33 -05:00
|
|
|
let files = matches
|
|
|
|
.values_of("file")
|
|
|
|
.unwrap()
|
|
|
|
.map(String::from)
|
|
|
|
.collect();
|
2020-04-07 11:24:47 -04:00
|
|
|
flags.subcommand = DenoSubcommand::Cache { files };
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
2019-05-01 19:15:37 -04:00
|
|
|
|
2020-02-26 05:52:15 -05:00
|
|
|
fn lock_args_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
2019-11-26 11:06:32 -05:00
|
|
|
if matches.is_present("lock") {
|
|
|
|
let lockfile = matches.value_of("lock").unwrap();
|
|
|
|
flags.lock = Some(lockfile.to_string());
|
|
|
|
}
|
|
|
|
if matches.is_present("lock-write") {
|
|
|
|
flags.lock_write = true;
|
|
|
|
}
|
|
|
|
}
|
2019-05-06 10:48:19 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
// Shared between the run and test subcommands. They both take similar options.
|
2020-02-26 05:52:15 -05:00
|
|
|
fn run_test_args_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
2019-11-26 11:06:32 -05:00
|
|
|
reload_arg_parse(flags, matches);
|
|
|
|
lock_args_parse(flags, matches);
|
|
|
|
importmap_arg_parse(flags, matches);
|
|
|
|
config_arg_parse(flags, matches);
|
2019-11-26 23:25:14 -05:00
|
|
|
v8_flags_arg_parse(flags, matches);
|
2019-12-03 17:48:53 -05:00
|
|
|
no_remote_arg_parse(flags, matches);
|
2020-01-30 18:42:39 -05:00
|
|
|
permission_args_parse(flags, matches);
|
2020-02-17 11:59:51 -05:00
|
|
|
ca_file_arg_parse(flags, matches);
|
2020-03-27 16:09:51 -04:00
|
|
|
inspect_arg_parse(flags, matches);
|
2020-04-27 19:12:38 -04:00
|
|
|
unstable_arg_parse(flags, matches);
|
2019-05-23 14:57:44 -04:00
|
|
|
|
2019-12-03 17:48:53 -05:00
|
|
|
if matches.is_present("cached-only") {
|
|
|
|
flags.cached_only = true;
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
2019-05-01 19:15:37 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
if matches.is_present("seed") {
|
|
|
|
let seed_string = matches.value_of("seed").unwrap();
|
|
|
|
let seed = seed_string.parse::<u64>().unwrap();
|
|
|
|
flags.seed = Some(seed);
|
|
|
|
|
|
|
|
let v8_seed_flag = format!("--random-seed={}", seed);
|
|
|
|
|
|
|
|
match flags.v8_flags {
|
|
|
|
Some(ref mut v8_flags) => {
|
|
|
|
v8_flags.push(v8_seed_flag);
|
|
|
|
}
|
|
|
|
None => {
|
|
|
|
flags.v8_flags = Some(svec![v8_seed_flag]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-26 05:52:15 -05:00
|
|
|
fn run_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
2019-11-26 11:06:32 -05:00
|
|
|
run_test_args_parse(flags, matches);
|
2020-02-04 14:24:33 -05:00
|
|
|
|
|
|
|
let mut script: Vec<String> = matches
|
|
|
|
.values_of("script_arg")
|
|
|
|
.unwrap()
|
|
|
|
.map(String::from)
|
|
|
|
.collect();
|
|
|
|
assert!(!script.is_empty());
|
|
|
|
let script_args = script.split_off(1);
|
|
|
|
let script = script[0].to_string();
|
|
|
|
for v in script_args {
|
|
|
|
flags.argv.push(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
flags.subcommand = DenoSubcommand::Run { script };
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
|
|
|
|
2020-02-26 05:52:15 -05:00
|
|
|
fn test_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
2019-11-26 11:06:32 -05:00
|
|
|
run_test_args_parse(flags, matches);
|
|
|
|
|
2020-02-11 06:01:56 -05:00
|
|
|
let failfast = matches.is_present("failfast");
|
|
|
|
let allow_none = matches.is_present("allow_none");
|
2020-04-27 07:05:26 -04:00
|
|
|
let quiet = matches.is_present("quiet");
|
2020-04-02 09:26:40 -04:00
|
|
|
let filter = matches.value_of("filter").map(String::from);
|
2020-02-11 06:01:56 -05:00
|
|
|
let include = if matches.is_present("files") {
|
2019-11-26 11:06:32 -05:00
|
|
|
let files: Vec<String> = matches
|
|
|
|
.values_of("files")
|
|
|
|
.unwrap()
|
|
|
|
.map(String::from)
|
|
|
|
.collect();
|
2020-02-11 06:01:56 -05:00
|
|
|
Some(files)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
|
|
|
flags.subcommand = DenoSubcommand::Test {
|
|
|
|
fail_fast: failfast,
|
2020-04-27 07:05:26 -04:00
|
|
|
quiet,
|
2020-02-11 06:01:56 -05:00
|
|
|
include,
|
2020-04-02 09:26:40 -04:00
|
|
|
filter,
|
2020-02-11 06:01:56 -05:00
|
|
|
allow_none,
|
|
|
|
};
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
|
|
|
|
2020-03-23 11:37:24 -04:00
|
|
|
fn upgrade_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|
|
|
let dry_run = matches.is_present("dry-run");
|
|
|
|
let force = matches.is_present("force");
|
2020-05-09 06:31:15 -04:00
|
|
|
let version = matches.value_of("version").map(|s| s.to_string());
|
|
|
|
flags.subcommand = DenoSubcommand::Upgrade {
|
|
|
|
dry_run,
|
|
|
|
force,
|
|
|
|
version,
|
|
|
|
};
|
2020-03-23 11:37:24 -04:00
|
|
|
}
|
|
|
|
|
2020-03-28 14:16:57 -04:00
|
|
|
fn doc_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|
|
|
reload_arg_parse(flags, matches);
|
2020-04-30 11:23:40 -04:00
|
|
|
unstable_arg_parse(flags, matches);
|
|
|
|
|
2020-04-09 08:34:24 -04:00
|
|
|
let source_file = matches.value_of("source_file").map(String::from);
|
2020-03-28 14:16:57 -04:00
|
|
|
let json = matches.is_present("json");
|
2020-04-02 09:26:40 -04:00
|
|
|
let filter = matches.value_of("filter").map(String::from);
|
2020-03-28 14:16:57 -04:00
|
|
|
flags.subcommand = DenoSubcommand::Doc {
|
|
|
|
source_file,
|
|
|
|
json,
|
|
|
|
filter,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn types_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
SubCommand::with_name("types")
|
2020-04-30 11:23:40 -04:00
|
|
|
.arg(unstable_arg())
|
2019-11-26 11:06:32 -05:00
|
|
|
.about("Print runtime TypeScript declarations")
|
|
|
|
.long_about(
|
|
|
|
"Print runtime TypeScript declarations.
|
2020-04-09 08:34:24 -04:00
|
|
|
deno types > lib.deno.d.ts
|
2019-11-26 11:06:32 -05:00
|
|
|
|
|
|
|
The declaration file could be saved and used for typing information.",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn fmt_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
SubCommand::with_name("fmt")
|
2020-02-13 16:02:18 -05:00
|
|
|
.about("Format source files")
|
2020-01-29 21:16:48 -05:00
|
|
|
.long_about(
|
2020-03-10 19:23:08 -04:00
|
|
|
"Auto-format JavaScript/TypeScript source code.
|
2020-01-29 21:16:48 -05:00
|
|
|
deno fmt
|
|
|
|
deno fmt myfile1.ts myfile2.ts
|
2020-02-09 05:19:05 -05:00
|
|
|
deno fmt --check
|
|
|
|
|
2020-03-10 19:23:08 -04:00
|
|
|
Format stdin and write to stdout:
|
2020-05-04 15:17:15 -04:00
|
|
|
cat file.ts | deno fmt -
|
|
|
|
|
|
|
|
Ignore formatting code by preceding it with an ignore comment:
|
|
|
|
// deno-fmt-ignore
|
|
|
|
|
|
|
|
Ignore formatting a file by adding an ignore comment at the top of the file:
|
|
|
|
// deno-fmt-ignore-file",
|
2020-01-29 21:16:48 -05:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("check")
|
|
|
|
.long("check")
|
|
|
|
.help("Check if the source files are formatted.")
|
|
|
|
.takes_value(false),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("files")
|
|
|
|
.takes_value(true)
|
|
|
|
.multiple(true)
|
|
|
|
.required(false),
|
|
|
|
)
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
2019-08-15 10:11:52 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn repl_subcommand<'a, 'b>() -> App<'a, 'b> {
|
2020-04-01 09:35:34 -04:00
|
|
|
inspect_args(SubCommand::with_name("repl"))
|
2019-11-26 23:25:14 -05:00
|
|
|
.about("Read Eval Print Loop")
|
|
|
|
.arg(v8_flags_arg())
|
2020-02-17 11:59:51 -05:00
|
|
|
.arg(ca_file_arg())
|
2020-04-30 11:23:40 -04:00
|
|
|
.arg(unstable_arg())
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
2019-08-15 10:11:52 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn install_subcommand<'a, 'b>() -> App<'a, 'b> {
|
2020-01-30 18:42:39 -05:00
|
|
|
permission_args(SubCommand::with_name("install"))
|
2019-11-26 11:06:32 -05:00
|
|
|
.setting(AppSettings::TrailingVarArg)
|
2020-05-01 15:33:11 -04:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("cmd")
|
|
|
|
.required(true)
|
|
|
|
.multiple(true)
|
|
|
|
.allow_hyphen_values(true))
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("name")
|
|
|
|
.long("name")
|
|
|
|
.short("n")
|
|
|
|
.help("Executable file name")
|
|
|
|
.takes_value(true)
|
|
|
|
.required(false))
|
2019-11-26 11:06:32 -05:00
|
|
|
.arg(
|
2020-04-16 18:15:42 -04:00
|
|
|
Arg::with_name("root")
|
|
|
|
.long("root")
|
|
|
|
.help("Installation root")
|
2019-08-15 10:11:52 -04:00
|
|
|
.takes_value(true)
|
2019-11-26 11:06:32 -05:00
|
|
|
.multiple(false))
|
2020-02-08 03:49:55 -05:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("force")
|
|
|
|
.long("force")
|
|
|
|
.short("f")
|
|
|
|
.help("Forcefully overwrite existing installation")
|
|
|
|
.takes_value(false))
|
2020-02-17 11:59:51 -05:00
|
|
|
.arg(ca_file_arg())
|
2020-04-30 11:23:40 -04:00
|
|
|
.arg(unstable_arg())
|
2020-04-16 18:15:42 -04:00
|
|
|
.about("Install script as an executable")
|
2019-05-03 17:15:16 -04:00
|
|
|
.long_about(
|
2020-04-16 18:15:42 -04:00
|
|
|
"Installs a script as an executable in the installation root's bin directory.
|
2020-05-01 15:33:11 -04:00
|
|
|
deno install --allow-net --allow-read https://deno.land/std/http/file_server.ts
|
|
|
|
deno install https://deno.land/std/examples/colors.ts
|
|
|
|
|
|
|
|
To change the executable name, use -n/--name:
|
|
|
|
deno install --allow-net --allow-read -n serve https://deno.land/std/http/file_server.ts
|
|
|
|
|
|
|
|
The executable name is inferred by default:
|
|
|
|
- Attempt to take the file stem of the URL path. The above example would
|
|
|
|
become 'file_server'.
|
|
|
|
- If the file stem is something generic like 'main', 'mod', 'index' or 'cli',
|
|
|
|
and the path has no parent, take the file name of the parent path. Otherwise
|
|
|
|
settle with the generic name.
|
2019-05-03 17:15:16 -04:00
|
|
|
|
2020-04-16 18:15:42 -04:00
|
|
|
To change the installation root, use --root:
|
2020-05-01 15:33:11 -04:00
|
|
|
deno install --allow-net --allow-read --root /usr/local https://deno.land/std/http/file_server.ts
|
2020-04-16 18:15:42 -04:00
|
|
|
|
|
|
|
The installation root is determined, in order of precedence:
|
|
|
|
- --root option
|
|
|
|
- DENO_INSTALL_ROOT environment variable
|
|
|
|
- $HOME/.deno
|
|
|
|
|
|
|
|
These must be added to the path manually if required.")
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
2019-05-03 17:15:16 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn bundle_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
SubCommand::with_name("bundle")
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("source_file")
|
|
|
|
.takes_value(true)
|
|
|
|
.required(true),
|
|
|
|
)
|
|
|
|
.arg(Arg::with_name("out_file").takes_value(true).required(false))
|
2020-02-17 11:59:51 -05:00
|
|
|
.arg(ca_file_arg())
|
2020-04-07 06:32:09 -04:00
|
|
|
.arg(importmap_arg())
|
2020-04-27 19:12:38 -04:00
|
|
|
.arg(unstable_arg())
|
2020-05-07 11:02:03 -04:00
|
|
|
.arg(config_arg())
|
2019-11-26 11:06:32 -05:00
|
|
|
.about("Bundle module and dependencies into single file")
|
|
|
|
.long_about(
|
|
|
|
"Output a single JavaScript file with all dependencies.
|
2020-03-10 19:23:08 -04:00
|
|
|
deno bundle https://deno.land/std/examples/colors.ts colors.bundle.js
|
2019-05-16 10:39:19 -04:00
|
|
|
|
2020-03-10 19:23:08 -04:00
|
|
|
If no output file is given, the output is written to standard output:
|
|
|
|
deno bundle https://deno.land/std/examples/colors.ts",
|
2019-11-26 11:06:32 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn completions_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
SubCommand::with_name("completions")
|
|
|
|
.setting(AppSettings::DisableHelpSubcommand)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("shell")
|
|
|
|
.possible_values(&clap::Shell::variants())
|
|
|
|
.required(true),
|
|
|
|
)
|
|
|
|
.about("Generate shell completions")
|
|
|
|
.long_about(
|
|
|
|
"Output shell completion script to standard output.
|
|
|
|
deno completions bash > /usr/local/etc/bash_completion.d/deno.bash
|
|
|
|
source /usr/local/etc/bash_completion.d/deno.bash",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn eval_subcommand<'a, 'b>() -> App<'a, 'b> {
|
2020-04-01 09:35:34 -04:00
|
|
|
inspect_args(SubCommand::with_name("eval"))
|
2020-02-17 11:59:51 -05:00
|
|
|
.arg(ca_file_arg())
|
2020-04-30 11:23:40 -04:00
|
|
|
.arg(unstable_arg())
|
2019-11-26 11:06:32 -05:00
|
|
|
.about("Eval script")
|
|
|
|
.long_about(
|
2020-03-10 19:23:08 -04:00
|
|
|
"Evaluate JavaScript from the command line.
|
2020-02-28 09:17:56 -05:00
|
|
|
deno eval \"console.log('hello world')\"
|
|
|
|
|
|
|
|
To evaluate as TypeScript:
|
|
|
|
deno eval -T \"const v: string = 'hello'; console.log(v)\"
|
2020-03-10 19:23:08 -04:00
|
|
|
|
|
|
|
This command has implicit access to all permissions (--allow-all).",
|
2020-02-28 09:17:56 -05:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("ts")
|
|
|
|
.long("ts")
|
|
|
|
.short("T")
|
|
|
|
.help("Treat eval input as TypeScript")
|
|
|
|
.takes_value(false)
|
|
|
|
.multiple(false),
|
2019-04-17 09:25:51 -04:00
|
|
|
)
|
2019-11-26 11:06:32 -05:00
|
|
|
.arg(Arg::with_name("code").takes_value(true).required(true))
|
2020-01-26 09:49:34 -05:00
|
|
|
.arg(v8_flags_arg())
|
2019-04-13 13:24:15 -04:00
|
|
|
}
|
2019-05-09 12:20:34 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn info_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
SubCommand::with_name("info")
|
|
|
|
.about("Show info about cache or info related to source file")
|
|
|
|
.long_about(
|
2020-03-10 19:23:08 -04:00
|
|
|
"Information about a module or the cache directories.
|
2019-05-09 12:20:34 -04:00
|
|
|
|
2020-03-10 19:23:08 -04:00
|
|
|
Get information about a module:
|
|
|
|
deno info https://deno.land/std/http/file_server.ts
|
2019-10-12 17:13:52 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
The following information is shown:
|
2019-10-12 17:13:52 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
local: Local path of the file.
|
|
|
|
type: JavaScript, TypeScript, or JSON.
|
2020-03-10 19:23:08 -04:00
|
|
|
compiled: Local path of compiled source code. (TypeScript only.)
|
|
|
|
map: Local path of source map. (TypeScript only.)
|
2019-11-26 11:06:32 -05:00
|
|
|
deps: Dependency tree of the source file.
|
2019-10-12 17:13:52 -04:00
|
|
|
|
2020-03-10 19:23:08 -04:00
|
|
|
Without any additional arguments, 'deno info' shows:
|
2019-10-12 17:13:52 -04:00
|
|
|
|
2020-03-10 19:23:08 -04:00
|
|
|
DENO_DIR: Directory containing Deno-managed files.
|
|
|
|
Remote modules cache: Subdirectory containing downloaded remote modules.
|
|
|
|
TypeScript compiler cache: Subdirectory containing TS compiler output.",
|
2019-11-26 11:06:32 -05:00
|
|
|
)
|
|
|
|
.arg(Arg::with_name("file").takes_value(true).required(false))
|
2020-02-17 11:59:51 -05:00
|
|
|
.arg(ca_file_arg())
|
2020-04-30 11:23:40 -04:00
|
|
|
.arg(unstable_arg())
|
2019-10-12 17:13:52 -04:00
|
|
|
}
|
|
|
|
|
2020-04-07 11:24:47 -04:00
|
|
|
fn cache_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
SubCommand::with_name("cache")
|
2019-11-26 11:06:32 -05:00
|
|
|
.arg(reload_arg())
|
|
|
|
.arg(lock_arg())
|
|
|
|
.arg(lock_write_arg())
|
|
|
|
.arg(importmap_arg())
|
2020-04-27 19:12:38 -04:00
|
|
|
.arg(unstable_arg())
|
2019-11-26 11:06:32 -05:00
|
|
|
.arg(config_arg())
|
2019-12-03 17:48:53 -05:00
|
|
|
.arg(no_remote_arg())
|
2020-01-31 16:07:37 -05:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("file")
|
|
|
|
.takes_value(true)
|
|
|
|
.required(true)
|
|
|
|
.min_values(1),
|
|
|
|
)
|
2020-02-17 11:59:51 -05:00
|
|
|
.arg(ca_file_arg())
|
2020-04-07 11:24:47 -04:00
|
|
|
.about("Cache the dependencies")
|
2019-11-26 11:06:32 -05:00
|
|
|
.long_about(
|
2020-04-07 11:24:47 -04:00
|
|
|
"Cache and compile remote dependencies recursively.
|
2019-04-06 18:13:06 -04:00
|
|
|
|
2020-03-10 19:23:08 -04:00
|
|
|
Download and compile a module with all of its static dependencies and save them
|
|
|
|
in the local cache, without running any code:
|
2020-04-07 11:24:47 -04:00
|
|
|
deno cache https://deno.land/std/http/file_server.ts
|
2019-04-06 18:13:06 -04:00
|
|
|
|
2020-03-10 19:23:08 -04:00
|
|
|
Future runs of this module will trigger no downloads or compilation unless
|
|
|
|
--reload is specified.",
|
2019-11-26 11:06:32 -05:00
|
|
|
)
|
2019-06-05 13:44:46 -04:00
|
|
|
}
|
|
|
|
|
2020-03-23 11:37:24 -04:00
|
|
|
fn upgrade_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
SubCommand::with_name("upgrade")
|
2020-05-09 06:31:15 -04:00
|
|
|
.about("Upgrade deno executable to given version")
|
2020-03-23 11:37:24 -04:00
|
|
|
.long_about(
|
2020-05-09 06:31:15 -04:00
|
|
|
"Upgrade deno executable to the given version.
|
|
|
|
Defaults to latest.
|
2020-03-23 11:37:24 -04:00
|
|
|
|
2020-05-09 06:31:15 -04:00
|
|
|
The version is downloaded from
|
2020-03-23 11:37:24 -04:00
|
|
|
https://github.com/denoland/deno/releases
|
|
|
|
and is used to replace the current executable.",
|
|
|
|
)
|
2020-05-09 06:31:15 -04:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("version")
|
|
|
|
.long("version")
|
|
|
|
.help("The version to upgrade to")
|
|
|
|
.takes_value(true),
|
|
|
|
)
|
2020-03-23 11:37:24 -04:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("dry-run")
|
|
|
|
.long("dry-run")
|
|
|
|
.help("Perform all checks without replacing old exe"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("force")
|
|
|
|
.long("force")
|
|
|
|
.short("f")
|
|
|
|
.help("Replace current exe even if not out-of-date"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-03-28 14:16:57 -04:00
|
|
|
fn doc_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
SubCommand::with_name("doc")
|
2020-04-30 11:23:40 -04:00
|
|
|
.arg(unstable_arg())
|
2020-04-09 08:34:24 -04:00
|
|
|
.about("Show documentation for a module")
|
2020-03-28 14:16:57 -04:00
|
|
|
.long_about(
|
2020-04-09 08:34:24 -04:00
|
|
|
"Show documentation for a module.
|
2020-03-28 14:16:57 -04:00
|
|
|
|
2020-04-09 08:34:24 -04:00
|
|
|
Output documentation to standard output:
|
2020-03-28 14:16:57 -04:00
|
|
|
deno doc ./path/to/module.ts
|
|
|
|
|
2020-04-09 08:34:24 -04:00
|
|
|
Output documentation in JSON format:
|
|
|
|
deno doc --json ./path/to/module.ts
|
|
|
|
|
|
|
|
Target a specific symbol:
|
2020-03-28 14:16:57 -04:00
|
|
|
deno doc ./path/to/module.ts MyClass.someField
|
|
|
|
|
2020-04-09 08:34:24 -04:00
|
|
|
Show documentation for runtime built-ins:
|
|
|
|
deno doc
|
|
|
|
deno doc --builtin Deno.Listener",
|
2020-03-28 14:16:57 -04:00
|
|
|
)
|
|
|
|
.arg(reload_arg())
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("json")
|
|
|
|
.long("json")
|
|
|
|
.help("Output documentation in JSON format.")
|
|
|
|
.takes_value(false),
|
|
|
|
)
|
2020-04-09 08:34:24 -04:00
|
|
|
// TODO(nayeemrmn): Make `--builtin` a proper option. Blocked by
|
|
|
|
// https://github.com/clap-rs/clap/issues/1794. Currently `--builtin` is
|
|
|
|
// just a possible value of `source_file` so leading hyphens must be
|
|
|
|
// enabled.
|
|
|
|
.setting(clap::AppSettings::AllowLeadingHyphen)
|
|
|
|
.arg(Arg::with_name("source_file").takes_value(true))
|
2020-03-28 14:16:57 -04:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("filter")
|
|
|
|
.help("Dot separated path to symbol.")
|
|
|
|
.takes_value(true)
|
|
|
|
.required(false)
|
|
|
|
.conflicts_with("json")
|
|
|
|
.conflicts_with("pretty"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-01-30 18:42:39 -05:00
|
|
|
fn permission_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
|
2019-11-26 11:06:32 -05:00
|
|
|
app
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("allow-read")
|
|
|
|
.long("allow-read")
|
|
|
|
.min_values(0)
|
|
|
|
.takes_value(true)
|
|
|
|
.use_delimiter(true)
|
|
|
|
.require_equals(true)
|
|
|
|
.help("Allow file system read access"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("allow-write")
|
|
|
|
.long("allow-write")
|
|
|
|
.min_values(0)
|
|
|
|
.takes_value(true)
|
|
|
|
.use_delimiter(true)
|
|
|
|
.require_equals(true)
|
|
|
|
.help("Allow file system write access"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("allow-net")
|
|
|
|
.long("allow-net")
|
|
|
|
.min_values(0)
|
|
|
|
.takes_value(true)
|
|
|
|
.use_delimiter(true)
|
|
|
|
.require_equals(true)
|
|
|
|
.help("Allow network access"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("allow-env")
|
|
|
|
.long("allow-env")
|
|
|
|
.help("Allow environment access"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("allow-run")
|
|
|
|
.long("allow-run")
|
|
|
|
.help("Allow running subprocesses"),
|
|
|
|
)
|
2019-12-05 15:30:20 -05:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("allow-plugin")
|
|
|
|
.long("allow-plugin")
|
|
|
|
.help("Allow loading plugins"),
|
|
|
|
)
|
2019-11-26 11:06:32 -05:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("allow-hrtime")
|
|
|
|
.long("allow-hrtime")
|
|
|
|
.help("Allow high resolution time measurement"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("allow-all")
|
|
|
|
.short("A")
|
|
|
|
.long("allow-all")
|
|
|
|
.help("Allow all permissions"),
|
|
|
|
)
|
2020-01-30 18:42:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn run_test_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
|
2020-03-27 16:09:51 -04:00
|
|
|
permission_args(inspect_args(app))
|
2020-01-30 18:42:39 -05:00
|
|
|
.arg(importmap_arg())
|
2020-04-27 19:12:38 -04:00
|
|
|
.arg(unstable_arg())
|
2020-01-30 18:42:39 -05:00
|
|
|
.arg(reload_arg())
|
|
|
|
.arg(config_arg())
|
|
|
|
.arg(lock_arg())
|
|
|
|
.arg(lock_write_arg())
|
|
|
|
.arg(no_remote_arg())
|
|
|
|
.arg(v8_flags_arg())
|
2020-02-17 11:59:51 -05:00
|
|
|
.arg(ca_file_arg())
|
2019-11-26 11:06:32 -05:00
|
|
|
.arg(
|
2019-12-03 17:48:53 -05:00
|
|
|
Arg::with_name("cached-only")
|
|
|
|
.long("cached-only")
|
|
|
|
.help("Require that remote dependencies are already cached"),
|
2019-11-26 11:06:32 -05:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("seed")
|
|
|
|
.long("seed")
|
|
|
|
.value_name("NUMBER")
|
|
|
|
.help("Seed Math.random()")
|
|
|
|
.takes_value(true)
|
|
|
|
.validator(|val: String| match val.parse::<u64>() {
|
|
|
|
Ok(_) => Ok(()),
|
|
|
|
Err(_) => Err("Seed should be a number".to_string()),
|
|
|
|
}),
|
|
|
|
)
|
2018-08-17 16:34:30 -04:00
|
|
|
}
|
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn run_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
run_test_args(SubCommand::with_name("run"))
|
|
|
|
.setting(AppSettings::TrailingVarArg)
|
|
|
|
.arg(script_arg())
|
2020-03-10 19:23:08 -04:00
|
|
|
.about("Run a program given a filename or url to the module")
|
2019-11-26 11:06:32 -05:00
|
|
|
.long_about(
|
2020-03-10 19:23:08 -04:00
|
|
|
"Run a program given a filename or url to the module.
|
2019-06-29 18:32:54 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
By default all programs are run in sandbox without access to disk, network or
|
|
|
|
ability to spawn subprocesses.
|
|
|
|
deno run https://deno.land/std/examples/welcome.ts
|
2019-06-29 18:32:54 -04:00
|
|
|
|
2020-03-10 19:23:08 -04:00
|
|
|
Grant all permissions:
|
2019-11-26 11:06:32 -05:00
|
|
|
deno run -A https://deno.land/std/http/file_server.ts
|
2019-06-29 18:32:54 -04:00
|
|
|
|
2020-03-10 19:23:08 -04:00
|
|
|
Grant permission to read from disk and listen to network:
|
|
|
|
deno run --allow-read --allow-net https://deno.land/std/http/file_server.ts
|
2019-11-26 11:06:32 -05:00
|
|
|
|
2020-03-10 19:23:08 -04:00
|
|
|
Grant permission to read whitelisted files from disk:
|
2020-01-15 19:21:35 -05:00
|
|
|
deno run --allow-read=/etc https://deno.land/std/http/file_server.ts",
|
2019-11-26 11:06:32 -05:00
|
|
|
)
|
2019-04-29 19:43:06 -04:00
|
|
|
}
|
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn test_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
run_test_args(SubCommand::with_name("test"))
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("failfast")
|
|
|
|
.long("failfast")
|
|
|
|
.help("Stop on first error")
|
|
|
|
.takes_value(false),
|
|
|
|
)
|
|
|
|
.arg(
|
2020-02-11 06:01:56 -05:00
|
|
|
Arg::with_name("allow_none")
|
|
|
|
.long("allow-none")
|
|
|
|
.help("Don't return error code if no test files are found")
|
|
|
|
.takes_value(false),
|
2019-11-26 11:06:32 -05:00
|
|
|
)
|
2020-04-02 09:26:40 -04:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("filter")
|
|
|
|
.long("filter")
|
|
|
|
.takes_value(true)
|
|
|
|
.help("A pattern to filter the tests to run by"),
|
|
|
|
)
|
2019-11-26 11:06:32 -05:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("files")
|
|
|
|
.help("List of file names to run")
|
|
|
|
.takes_value(true)
|
|
|
|
.multiple(true),
|
|
|
|
)
|
|
|
|
.about("Run tests")
|
|
|
|
.long_about(
|
2020-03-10 19:23:08 -04:00
|
|
|
"Run tests using Deno's built-in test runner.
|
2019-04-29 19:43:06 -04:00
|
|
|
|
2020-03-10 19:23:08 -04:00
|
|
|
Evaluate the given modules, run all tests declared with 'Deno.test()' and
|
|
|
|
report results to standard output:
|
|
|
|
deno test src/fetch_test.ts src/signal_test.ts
|
2019-07-27 05:20:40 -04:00
|
|
|
|
2020-03-10 19:23:08 -04:00
|
|
|
Directory arguments are expanded to all contained files matching the glob
|
2020-06-05 17:01:44 -04:00
|
|
|
{*_,*.,}test.{js,mjs,ts,jsx,tsx}:
|
2019-11-26 11:06:32 -05:00
|
|
|
deno test src/",
|
|
|
|
)
|
|
|
|
}
|
2019-05-16 10:11:35 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn script_arg<'a, 'b>() -> Arg<'a, 'b> {
|
2020-01-15 19:21:35 -05:00
|
|
|
Arg::with_name("script_arg")
|
|
|
|
.multiple(true)
|
2020-02-04 14:24:33 -05:00
|
|
|
.required(true)
|
2020-01-08 14:59:53 -05:00
|
|
|
.help("script args")
|
2020-01-15 19:21:35 -05:00
|
|
|
.value_name("SCRIPT_ARG")
|
2020-01-08 14:59:53 -05:00
|
|
|
}
|
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn lock_arg<'a, 'b>() -> Arg<'a, 'b> {
|
|
|
|
Arg::with_name("lock")
|
|
|
|
.long("lock")
|
|
|
|
.value_name("FILE")
|
|
|
|
.help("Check the specified lock file")
|
|
|
|
.takes_value(true)
|
|
|
|
}
|
2019-08-15 10:11:52 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn lock_write_arg<'a, 'b>() -> Arg<'a, 'b> {
|
|
|
|
Arg::with_name("lock-write")
|
|
|
|
.long("lock-write")
|
|
|
|
.help("Write lock file. Use with --lock.")
|
|
|
|
}
|
2019-08-15 10:11:52 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn config_arg<'a, 'b>() -> Arg<'a, 'b> {
|
|
|
|
Arg::with_name("config")
|
|
|
|
.short("c")
|
|
|
|
.long("config")
|
|
|
|
.value_name("FILE")
|
|
|
|
.help("Load tsconfig.json configuration file")
|
|
|
|
.takes_value(true)
|
|
|
|
}
|
2019-08-15 10:11:52 -04:00
|
|
|
|
2020-02-26 05:52:15 -05:00
|
|
|
fn config_arg_parse(flags: &mut Flags, matches: &ArgMatches) {
|
2019-11-26 11:06:32 -05:00
|
|
|
flags.config_path = matches.value_of("config").map(ToOwned::to_owned);
|
|
|
|
}
|
2019-08-15 10:11:52 -04:00
|
|
|
|
2020-02-17 11:59:51 -05:00
|
|
|
fn ca_file_arg<'a, 'b>() -> Arg<'a, 'b> {
|
|
|
|
Arg::with_name("cert")
|
|
|
|
.long("cert")
|
|
|
|
.value_name("FILE")
|
|
|
|
.help("Load certificate authority from PEM encoded file")
|
|
|
|
.takes_value(true)
|
|
|
|
}
|
2020-04-03 13:40:11 -04:00
|
|
|
|
2020-02-26 05:52:15 -05:00
|
|
|
fn ca_file_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
2020-02-17 11:59:51 -05:00
|
|
|
flags.ca_file = matches.value_of("cert").map(ToOwned::to_owned);
|
|
|
|
}
|
|
|
|
|
2020-04-27 19:12:38 -04:00
|
|
|
fn unstable_arg<'a, 'b>() -> Arg<'a, 'b> {
|
|
|
|
Arg::with_name("unstable")
|
|
|
|
.long("unstable")
|
|
|
|
.help("Enable unstable APIs")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn unstable_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|
|
|
if matches.is_present("unstable") {
|
|
|
|
flags.unstable = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-27 16:09:51 -04:00
|
|
|
fn inspect_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
|
|
|
|
app
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("inspect")
|
|
|
|
.long("inspect")
|
|
|
|
.value_name("HOST:PORT")
|
|
|
|
.help("activate inspector on host:port (default: 127.0.0.1:9229)")
|
|
|
|
.min_values(0)
|
|
|
|
.max_values(1)
|
|
|
|
.require_equals(true)
|
2020-04-03 13:40:11 -04:00
|
|
|
.takes_value(true)
|
|
|
|
.validator(inspect_arg_validate),
|
2020-03-27 16:09:51 -04:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("inspect-brk")
|
|
|
|
.long("inspect-brk")
|
|
|
|
.value_name("HOST:PORT")
|
|
|
|
.help(
|
|
|
|
"activate inspector on host:port and break at start of user script",
|
|
|
|
)
|
|
|
|
.min_values(0)
|
|
|
|
.max_values(1)
|
|
|
|
.require_equals(true)
|
2020-04-03 13:40:11 -04:00
|
|
|
.takes_value(true)
|
|
|
|
.validator(inspect_arg_validate),
|
2020-03-27 16:09:51 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-04-03 13:40:11 -04:00
|
|
|
fn inspect_arg_validate(val: String) -> Result<(), String> {
|
|
|
|
match val.parse::<SocketAddr>() {
|
|
|
|
Ok(_) => Ok(()),
|
|
|
|
Err(e) => Err(e.to_string()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-27 16:09:51 -04:00
|
|
|
fn inspect_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
2020-04-03 13:40:11 -04:00
|
|
|
let default = || "127.0.0.1:9229".parse::<SocketAddr>().unwrap();
|
2020-03-27 16:09:51 -04:00
|
|
|
flags.inspect = if matches.is_present("inspect") {
|
|
|
|
if let Some(host) = matches.value_of("inspect") {
|
2020-04-03 13:40:11 -04:00
|
|
|
Some(host.parse().unwrap())
|
2020-03-27 16:09:51 -04:00
|
|
|
} else {
|
2020-04-03 13:40:11 -04:00
|
|
|
Some(default())
|
2020-03-27 16:09:51 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
flags.inspect_brk = if matches.is_present("inspect-brk") {
|
|
|
|
if let Some(host) = matches.value_of("inspect-brk") {
|
2020-04-03 13:40:11 -04:00
|
|
|
Some(host.parse().unwrap())
|
2020-03-27 16:09:51 -04:00
|
|
|
} else {
|
2020-04-03 13:40:11 -04:00
|
|
|
Some(default())
|
2020-03-27 16:09:51 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn reload_arg<'a, 'b>() -> Arg<'a, 'b> {
|
|
|
|
Arg::with_name("reload")
|
|
|
|
.short("r")
|
|
|
|
.min_values(0)
|
|
|
|
.takes_value(true)
|
|
|
|
.use_delimiter(true)
|
|
|
|
.require_equals(true)
|
|
|
|
.long("reload")
|
|
|
|
.help("Reload source code cache (recompile TypeScript)")
|
|
|
|
.value_name("CACHE_BLACKLIST")
|
|
|
|
.long_help(
|
|
|
|
"Reload source code cache (recompile TypeScript)
|
|
|
|
--reload
|
|
|
|
Reload everything
|
|
|
|
--reload=https://deno.land/std
|
|
|
|
Reload only standard modules
|
|
|
|
--reload=https://deno.land/std/fs/utils.ts,https://deno.land/std/fmt/colors.ts
|
|
|
|
Reloads specific modules",
|
|
|
|
)
|
|
|
|
}
|
2019-08-15 10:11:52 -04:00
|
|
|
|
2020-02-26 05:52:15 -05:00
|
|
|
fn reload_arg_parse(flags: &mut Flags, matches: &ArgMatches) {
|
2020-05-16 09:41:32 -04:00
|
|
|
if let Some(cache_bl) = matches.values_of("reload") {
|
|
|
|
let raw_cache_blacklist: Vec<String> =
|
|
|
|
cache_bl.map(std::string::ToString::to_string).collect();
|
|
|
|
if raw_cache_blacklist.is_empty() {
|
|
|
|
flags.reload = true;
|
|
|
|
} else {
|
2019-11-26 11:06:32 -05:00
|
|
|
flags.cache_blacklist = resolve_urls(raw_cache_blacklist);
|
|
|
|
debug!("cache blacklist: {:#?}", &flags.cache_blacklist);
|
|
|
|
flags.reload = false;
|
2019-05-03 17:15:16 -04:00
|
|
|
}
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
|
|
|
}
|
2019-10-04 09:02:36 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn importmap_arg<'a, 'b>() -> Arg<'a, 'b> {
|
|
|
|
Arg::with_name("importmap")
|
|
|
|
.long("importmap")
|
|
|
|
.value_name("FILE")
|
2020-04-27 19:12:38 -04:00
|
|
|
.help("UNSTABLE: Load import map file")
|
2019-11-26 11:06:32 -05:00
|
|
|
.long_help(
|
2020-04-27 19:12:38 -04:00
|
|
|
"UNSTABLE:
|
|
|
|
Load import map file
|
2020-05-17 13:24:39 -04:00
|
|
|
Docs: https://deno.land/manual/linking_to_external_code/import_maps
|
2019-11-26 11:06:32 -05:00
|
|
|
Specification: https://wicg.github.io/import-maps/
|
|
|
|
Examples: https://github.com/WICG/import-maps#the-import-map",
|
|
|
|
)
|
|
|
|
.takes_value(true)
|
|
|
|
}
|
2019-10-04 09:02:36 -04:00
|
|
|
|
2020-02-26 05:52:15 -05:00
|
|
|
fn importmap_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
2019-11-26 11:06:32 -05:00
|
|
|
flags.import_map_path = matches.value_of("importmap").map(ToOwned::to_owned);
|
|
|
|
}
|
2019-10-04 09:02:36 -04:00
|
|
|
|
2019-11-26 23:25:14 -05:00
|
|
|
fn v8_flags_arg<'a, 'b>() -> Arg<'a, 'b> {
|
|
|
|
Arg::with_name("v8-flags")
|
|
|
|
.long("v8-flags")
|
|
|
|
.takes_value(true)
|
|
|
|
.use_delimiter(true)
|
|
|
|
.require_equals(true)
|
|
|
|
.help("Set V8 command line options. For help: --v8-flags=--help")
|
|
|
|
}
|
|
|
|
|
2020-02-26 05:52:15 -05:00
|
|
|
fn v8_flags_arg_parse(flags: &mut Flags, matches: &ArgMatches) {
|
2019-11-26 23:25:14 -05:00
|
|
|
if let Some(v8_flags) = matches.values_of("v8-flags") {
|
|
|
|
let s: Vec<String> = v8_flags.map(String::from).collect();
|
|
|
|
flags.v8_flags = Some(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-03 17:48:53 -05:00
|
|
|
fn no_remote_arg<'a, 'b>() -> Arg<'a, 'b> {
|
|
|
|
Arg::with_name("no-remote")
|
|
|
|
.long("no-remote")
|
|
|
|
.help("Do not resolve remote modules")
|
|
|
|
}
|
|
|
|
|
2020-02-26 05:52:15 -05:00
|
|
|
fn no_remote_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
2019-12-03 17:48:53 -05:00
|
|
|
if matches.is_present("no-remote") {
|
|
|
|
flags.no_remote = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-26 05:52:15 -05:00
|
|
|
fn permission_args_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
2020-05-16 09:41:32 -04:00
|
|
|
if let Some(read_wl) = matches.values_of("allow-read") {
|
2020-05-29 11:27:43 -04:00
|
|
|
let read_whitelist: Vec<PathBuf> = read_wl.map(PathBuf::from).collect();
|
2020-05-16 09:41:32 -04:00
|
|
|
|
2020-05-29 11:27:43 -04:00
|
|
|
if read_whitelist.is_empty() {
|
2020-05-16 09:41:32 -04:00
|
|
|
flags.allow_read = true;
|
|
|
|
} else {
|
2020-05-29 11:27:43 -04:00
|
|
|
flags.read_whitelist = read_whitelist;
|
2020-01-30 18:42:39 -05:00
|
|
|
}
|
|
|
|
}
|
2020-05-16 09:41:32 -04:00
|
|
|
|
|
|
|
if let Some(write_wl) = matches.values_of("allow-write") {
|
2020-05-29 11:27:43 -04:00
|
|
|
let write_whitelist: Vec<PathBuf> = write_wl.map(PathBuf::from).collect();
|
2020-05-16 09:41:32 -04:00
|
|
|
|
2020-05-29 11:27:43 -04:00
|
|
|
if write_whitelist.is_empty() {
|
2020-05-16 09:41:32 -04:00
|
|
|
flags.allow_write = true;
|
|
|
|
} else {
|
2020-05-29 11:27:43 -04:00
|
|
|
flags.write_whitelist = write_whitelist;
|
2020-01-30 18:42:39 -05:00
|
|
|
}
|
|
|
|
}
|
2020-05-16 09:41:32 -04:00
|
|
|
|
|
|
|
if let Some(net_wl) = matches.values_of("allow-net") {
|
|
|
|
let raw_net_whitelist: Vec<String> =
|
|
|
|
net_wl.map(std::string::ToString::to_string).collect();
|
|
|
|
if raw_net_whitelist.is_empty() {
|
|
|
|
flags.allow_net = true;
|
|
|
|
} else {
|
2020-01-30 18:42:39 -05:00
|
|
|
flags.net_whitelist = resolve_hosts(raw_net_whitelist);
|
|
|
|
debug!("net whitelist: {:#?}", &flags.net_whitelist);
|
|
|
|
}
|
|
|
|
}
|
2020-05-16 09:41:32 -04:00
|
|
|
|
2020-01-30 18:42:39 -05:00
|
|
|
if matches.is_present("allow-env") {
|
|
|
|
flags.allow_env = true;
|
|
|
|
}
|
|
|
|
if matches.is_present("allow-run") {
|
|
|
|
flags.allow_run = true;
|
|
|
|
}
|
|
|
|
if matches.is_present("allow-plugin") {
|
|
|
|
flags.allow_plugin = true;
|
|
|
|
}
|
|
|
|
if matches.is_present("allow-hrtime") {
|
|
|
|
flags.allow_hrtime = true;
|
|
|
|
}
|
|
|
|
if matches.is_present("allow-all") {
|
|
|
|
flags.allow_read = true;
|
|
|
|
flags.allow_env = true;
|
|
|
|
flags.allow_net = true;
|
|
|
|
flags.allow_run = true;
|
|
|
|
flags.allow_read = true;
|
|
|
|
flags.allow_write = true;
|
|
|
|
flags.allow_plugin = true;
|
|
|
|
flags.allow_hrtime = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
// TODO(ry) move this to utility module and add test.
|
|
|
|
/// Strips fragment part of URL. Panics on bad URL.
|
|
|
|
pub fn resolve_urls(urls: Vec<String>) -> Vec<String> {
|
|
|
|
use url::Url;
|
|
|
|
let mut out: Vec<String> = vec![];
|
|
|
|
for urlstr in urls.iter() {
|
|
|
|
use std::str::FromStr;
|
|
|
|
let result = Url::from_str(urlstr);
|
|
|
|
if result.is_err() {
|
|
|
|
panic!("Bad Url: {}", urlstr);
|
2019-06-05 13:44:46 -04:00
|
|
|
}
|
2019-11-26 11:06:32 -05:00
|
|
|
let mut url = result.unwrap();
|
|
|
|
url.set_fragment(None);
|
|
|
|
let mut full_url = String::from(url.as_str());
|
|
|
|
if full_url.len() > 1 && full_url.ends_with('/') {
|
|
|
|
full_url.pop();
|
2019-04-29 19:43:06 -04:00
|
|
|
}
|
2019-11-26 11:06:32 -05:00
|
|
|
out.push(full_url);
|
|
|
|
}
|
|
|
|
out
|
2019-04-29 19:43:06 -04:00
|
|
|
}
|
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
/// Expands "bare port" paths (eg. ":8080") into full paths with hosts. It
|
|
|
|
/// expands to such paths into 3 paths with following hosts: `0.0.0.0:port`,
|
|
|
|
/// `127.0.0.1:port` and `localhost:port`.
|
|
|
|
fn resolve_hosts(paths: Vec<String>) -> Vec<String> {
|
|
|
|
let mut out: Vec<String> = vec![];
|
|
|
|
for host_and_port in paths.iter() {
|
|
|
|
let parts = host_and_port.split(':').collect::<Vec<&str>>();
|
2018-08-17 16:34:30 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
match parts.len() {
|
|
|
|
// host only
|
|
|
|
1 => {
|
|
|
|
out.push(host_and_port.to_owned());
|
2019-04-21 11:34:18 -04:00
|
|
|
}
|
2019-11-26 11:06:32 -05:00
|
|
|
// host and port (NOTE: host might be empty string)
|
|
|
|
2 => {
|
|
|
|
let host = parts[0];
|
|
|
|
let port = parts[1];
|
2019-07-27 05:20:40 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
if !host.is_empty() {
|
|
|
|
out.push(host_and_port.to_owned());
|
|
|
|
continue;
|
|
|
|
}
|
2019-07-27 05:20:40 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
// we got bare port, let's add default hosts
|
|
|
|
for host in ["0.0.0.0", "127.0.0.1", "localhost"].iter() {
|
|
|
|
out.push(format!("{}:{}", host, port));
|
|
|
|
}
|
2019-07-27 05:20:40 -04:00
|
|
|
}
|
2019-11-26 11:06:32 -05:00
|
|
|
_ => panic!("Bad host:port pair: {}", host_and_port),
|
|
|
|
}
|
2019-04-21 11:34:18 -04:00
|
|
|
}
|
2018-08-17 16:34:30 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
out
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
2020-03-23 11:37:24 -04:00
|
|
|
#[test]
|
|
|
|
fn upgrade() {
|
|
|
|
let r =
|
|
|
|
flags_from_vec_safe(svec!["deno", "upgrade", "--dry-run", "--force"]);
|
|
|
|
let flags = r.unwrap();
|
|
|
|
assert_eq!(
|
|
|
|
flags,
|
|
|
|
Flags {
|
|
|
|
subcommand: DenoSubcommand::Upgrade {
|
|
|
|
force: true,
|
|
|
|
dry_run: true,
|
2020-05-09 06:31:15 -04:00
|
|
|
version: None
|
2020-03-23 11:37:24 -04:00
|
|
|
},
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
#[test]
|
|
|
|
fn version() {
|
|
|
|
let r = flags_from_vec_safe(svec!["deno", "--version"]);
|
|
|
|
assert_eq!(r.unwrap_err().kind, clap::ErrorKind::VersionDisplayed);
|
|
|
|
let r = flags_from_vec_safe(svec!["deno", "-V"]);
|
|
|
|
assert_eq!(r.unwrap_err().kind, clap::ErrorKind::VersionDisplayed);
|
2019-04-21 11:34:18 -04:00
|
|
|
}
|
2018-08-24 15:26:40 -04:00
|
|
|
|
2019-04-21 11:34:18 -04:00
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn run_reload() {
|
|
|
|
let r = flags_from_vec_safe(svec!["deno", "run", "-r", "script.ts"]);
|
|
|
|
let flags = r.unwrap();
|
2019-04-21 11:34:18 -04:00
|
|
|
assert_eq!(
|
|
|
|
flags,
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Run {
|
|
|
|
script: "script.ts".to_string(),
|
|
|
|
},
|
2019-04-21 11:34:18 -04:00
|
|
|
reload: true,
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-04-21 11:34:18 -04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2018-10-11 17:23:22 -04:00
|
|
|
|
2019-04-21 11:34:18 -04:00
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn run_reload_allow_write() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
|
|
|
"deno",
|
|
|
|
"run",
|
|
|
|
"-r",
|
|
|
|
"--allow-write",
|
|
|
|
"script.ts"
|
|
|
|
]);
|
2019-04-21 11:34:18 -04:00
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2019-04-21 11:34:18 -04:00
|
|
|
reload: true,
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Run {
|
|
|
|
script: "script.ts".to_string(),
|
|
|
|
},
|
2019-04-21 11:34:18 -04:00
|
|
|
allow_write: true,
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-04-21 11:34:18 -04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2018-10-15 14:26:22 -04:00
|
|
|
|
2019-04-21 11:34:18 -04:00
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn run_v8_flags() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
|
|
|
"deno",
|
|
|
|
"run",
|
|
|
|
"--v8-flags=--help",
|
|
|
|
"script.ts"
|
|
|
|
]);
|
2019-04-21 11:34:18 -04:00
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Run {
|
|
|
|
script: "script.ts".to_string(),
|
|
|
|
},
|
2019-11-26 11:06:32 -05:00
|
|
|
v8_flags: Some(svec!["--help"]),
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-04-21 11:34:18 -04:00
|
|
|
}
|
|
|
|
);
|
2019-01-09 11:59:54 -05:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
let r = flags_from_vec_safe(svec![
|
2019-05-03 17:15:16 -04:00
|
|
|
"deno",
|
|
|
|
"run",
|
2019-11-26 11:06:32 -05:00
|
|
|
"--v8-flags=--expose-gc,--gc-stats=1",
|
2019-05-03 17:15:16 -04:00
|
|
|
"script.ts"
|
|
|
|
]);
|
2019-04-21 11:34:18 -04:00
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Run {
|
|
|
|
script: "script.ts".to_string(),
|
|
|
|
},
|
2019-11-26 11:06:32 -05:00
|
|
|
v8_flags: Some(svec!["--expose-gc", "--gc-stats=1"]),
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-04-21 11:34:18 -04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn script_args() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
2019-05-03 17:15:16 -04:00
|
|
|
"deno",
|
|
|
|
"run",
|
|
|
|
"--allow-net",
|
|
|
|
"gist.ts",
|
|
|
|
"--title",
|
|
|
|
"X"
|
|
|
|
]);
|
2019-04-21 11:34:18 -04:00
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Run {
|
|
|
|
script: "gist.ts".to_string(),
|
|
|
|
},
|
|
|
|
argv: svec!["--title", "X"],
|
2019-04-21 11:34:18 -04:00
|
|
|
allow_net: true,
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-04-21 11:34:18 -04:00
|
|
|
}
|
2019-04-29 19:43:06 -04:00
|
|
|
);
|
2019-04-21 11:34:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn allow_all() {
|
|
|
|
let r = flags_from_vec_safe(svec!["deno", "run", "--allow-all", "gist.ts"]);
|
2019-04-21 11:34:18 -04:00
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Run {
|
|
|
|
script: "gist.ts".to_string(),
|
|
|
|
},
|
2019-04-21 11:34:18 -04:00
|
|
|
allow_net: true,
|
|
|
|
allow_env: true,
|
|
|
|
allow_run: true,
|
|
|
|
allow_read: true,
|
|
|
|
allow_write: true,
|
2019-12-05 15:30:20 -05:00
|
|
|
allow_plugin: true,
|
2019-05-23 12:28:29 -04:00
|
|
|
allow_hrtime: true,
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-04-21 11:34:18 -04:00
|
|
|
}
|
2019-04-29 19:43:06 -04:00
|
|
|
);
|
2019-04-21 11:34:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn allow_read() {
|
|
|
|
let r =
|
|
|
|
flags_from_vec_safe(svec!["deno", "run", "--allow-read", "gist.ts"]);
|
2019-04-21 11:34:18 -04:00
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Run {
|
|
|
|
script: "gist.ts".to_string(),
|
|
|
|
},
|
2019-04-21 11:34:18 -04:00
|
|
|
allow_read: true,
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-04-21 11:34:18 -04:00
|
|
|
}
|
2019-04-29 19:43:06 -04:00
|
|
|
);
|
2019-04-21 11:34:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn allow_hrtime() {
|
|
|
|
let r =
|
|
|
|
flags_from_vec_safe(svec!["deno", "run", "--allow-hrtime", "gist.ts"]);
|
2019-04-21 11:34:18 -04:00
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Run {
|
|
|
|
script: "gist.ts".to_string(),
|
|
|
|
},
|
2019-05-23 12:28:29 -04:00
|
|
|
allow_hrtime: true,
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-04-21 11:34:18 -04:00
|
|
|
}
|
2019-04-29 19:43:06 -04:00
|
|
|
);
|
2019-04-21 11:34:18 -04:00
|
|
|
}
|
2019-04-08 16:22:40 -04:00
|
|
|
|
2019-04-21 11:34:18 -04:00
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn double_hyphen() {
|
2019-06-29 18:32:54 -04:00
|
|
|
// notice that flags passed after double dash will not
|
2020-02-26 05:52:15 -05:00
|
|
|
// be parsed to Flags but instead forwarded to
|
2019-04-21 11:34:18 -04:00
|
|
|
// script args as Deno.args
|
2019-11-26 11:06:32 -05:00
|
|
|
let r = flags_from_vec_safe(svec![
|
2019-04-21 11:34:18 -04:00
|
|
|
"deno",
|
2019-05-03 17:15:16 -04:00
|
|
|
"run",
|
2019-04-21 11:34:18 -04:00
|
|
|
"--allow-write",
|
|
|
|
"script.ts",
|
2019-06-29 18:32:54 -04:00
|
|
|
"--",
|
2019-04-21 11:34:18 -04:00
|
|
|
"-D",
|
|
|
|
"--allow-net"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Run {
|
|
|
|
script: "script.ts".to_string(),
|
|
|
|
},
|
|
|
|
argv: svec!["--", "-D", "--allow-net"],
|
2019-04-21 11:34:18 -04:00
|
|
|
allow_write: true,
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-04-21 11:34:18 -04:00
|
|
|
}
|
2019-04-29 19:43:06 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn fmt() {
|
|
|
|
let r =
|
|
|
|
flags_from_vec_safe(svec!["deno", "fmt", "script_1.ts", "script_2.ts"]);
|
2019-04-29 19:43:06 -04:00
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-13 16:02:18 -05:00
|
|
|
subcommand: DenoSubcommand::Fmt {
|
2020-01-29 21:16:48 -05:00
|
|
|
check: false,
|
2020-02-13 16:02:18 -05:00
|
|
|
files: vec!["script_1.ts".to_string(), "script_2.ts".to_string()]
|
2020-01-29 21:16:48 -05:00
|
|
|
},
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2020-01-29 21:16:48 -05:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
let r = flags_from_vec_safe(svec!["deno", "fmt", "--check"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-13 16:02:18 -05:00
|
|
|
subcommand: DenoSubcommand::Fmt {
|
2020-01-29 21:16:48 -05:00
|
|
|
check: true,
|
2020-02-13 16:02:18 -05:00
|
|
|
files: vec![],
|
2020-01-29 21:16:48 -05:00
|
|
|
},
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-04-29 19:43:06 -04:00
|
|
|
}
|
|
|
|
);
|
2020-02-09 05:19:05 -05:00
|
|
|
|
|
|
|
let r = flags_from_vec_safe(svec!["deno", "fmt"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-13 16:02:18 -05:00
|
|
|
subcommand: DenoSubcommand::Fmt {
|
2020-02-09 05:19:05 -05:00
|
|
|
check: false,
|
2020-02-13 16:02:18 -05:00
|
|
|
files: vec![],
|
2020-02-09 05:19:05 -05:00
|
|
|
},
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2020-02-09 05:19:05 -05:00
|
|
|
}
|
|
|
|
);
|
2019-04-29 19:43:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn types() {
|
|
|
|
let r = flags_from_vec_safe(svec!["deno", "types"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Types,
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
|
|
|
);
|
2019-04-29 19:43:06 -04:00
|
|
|
}
|
|
|
|
|
2020-04-30 11:23:40 -04:00
|
|
|
#[test]
|
|
|
|
fn types_unstable() {
|
|
|
|
let r = flags_from_vec_safe(svec!["deno", "types", "--unstable"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
unstable: true,
|
|
|
|
subcommand: DenoSubcommand::Types,
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-04-29 19:43:06 -04:00
|
|
|
#[test]
|
2020-04-07 11:24:47 -04:00
|
|
|
fn cache() {
|
|
|
|
let r = flags_from_vec_safe(svec!["deno", "cache", "script.ts"]);
|
2019-11-26 11:06:32 -05:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-04-07 11:24:47 -04:00
|
|
|
subcommand: DenoSubcommand::Cache {
|
2020-02-04 14:24:33 -05:00
|
|
|
files: svec!["script.ts"],
|
|
|
|
},
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
|
|
|
);
|
2019-04-29 19:43:06 -04:00
|
|
|
}
|
|
|
|
|
2020-04-30 11:23:40 -04:00
|
|
|
#[test]
|
|
|
|
fn cache_unstable() {
|
|
|
|
let r =
|
|
|
|
flags_from_vec_safe(svec!["deno", "cache", "--unstable", "script.ts"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
unstable: true,
|
|
|
|
subcommand: DenoSubcommand::Cache {
|
|
|
|
files: svec!["script.ts"],
|
|
|
|
},
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-04-29 19:43:06 -04:00
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn info() {
|
|
|
|
let r = flags_from_vec_safe(svec!["deno", "info", "script.ts"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Info {
|
|
|
|
file: Some("script.ts".to_string()),
|
|
|
|
},
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
|
|
|
);
|
2019-08-11 20:43:01 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
let r = flags_from_vec_safe(svec!["deno", "info"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Info { file: None },
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
|
|
|
);
|
2019-04-21 11:34:18 -04:00
|
|
|
}
|
2019-04-29 10:58:31 -04:00
|
|
|
|
2019-05-03 16:24:09 -04:00
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn tsconfig() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
|
|
|
"deno",
|
|
|
|
"run",
|
|
|
|
"-c",
|
|
|
|
"tsconfig.json",
|
|
|
|
"script.ts"
|
|
|
|
]);
|
2019-05-03 17:15:16 -04:00
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Run {
|
|
|
|
script: "script.ts".to_string(),
|
|
|
|
},
|
2019-05-03 17:15:16 -04:00
|
|
|
config_path: Some("tsconfig.json".to_owned()),
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-05-03 17:15:16 -04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn eval() {
|
|
|
|
let r =
|
|
|
|
flags_from_vec_safe(svec!["deno", "eval", "'console.log(\"hello\")'"]);
|
2019-05-03 17:15:16 -04:00
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Eval {
|
|
|
|
code: "'console.log(\"hello\")'".to_string(),
|
2020-02-28 09:17:56 -05:00
|
|
|
as_typescript: false,
|
|
|
|
},
|
|
|
|
allow_net: true,
|
|
|
|
allow_env: true,
|
|
|
|
allow_run: true,
|
|
|
|
allow_read: true,
|
|
|
|
allow_write: true,
|
|
|
|
allow_plugin: true,
|
|
|
|
allow_hrtime: true,
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-04-30 11:23:40 -04:00
|
|
|
#[test]
|
|
|
|
fn eval_unstable() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
|
|
|
"deno",
|
|
|
|
"eval",
|
|
|
|
"--unstable",
|
|
|
|
"'console.log(\"hello\")'"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
unstable: true,
|
|
|
|
subcommand: DenoSubcommand::Eval {
|
|
|
|
code: "'console.log(\"hello\")'".to_string(),
|
|
|
|
as_typescript: false,
|
|
|
|
},
|
|
|
|
allow_net: true,
|
|
|
|
allow_env: true,
|
|
|
|
allow_run: true,
|
|
|
|
allow_read: true,
|
|
|
|
allow_write: true,
|
|
|
|
allow_plugin: true,
|
|
|
|
allow_hrtime: true,
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-02-28 09:17:56 -05:00
|
|
|
#[test]
|
|
|
|
fn eval_typescript() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
|
|
|
"deno",
|
|
|
|
"eval",
|
|
|
|
"-T",
|
|
|
|
"'console.log(\"hello\")'"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
subcommand: DenoSubcommand::Eval {
|
|
|
|
code: "'console.log(\"hello\")'".to_string(),
|
|
|
|
as_typescript: true,
|
2020-02-04 14:24:33 -05:00
|
|
|
},
|
2019-05-03 17:15:16 -04:00
|
|
|
allow_net: true,
|
|
|
|
allow_env: true,
|
|
|
|
allow_run: true,
|
|
|
|
allow_read: true,
|
|
|
|
allow_write: true,
|
2019-12-05 15:30:20 -05:00
|
|
|
allow_plugin: true,
|
2019-05-23 12:28:29 -04:00
|
|
|
allow_hrtime: true,
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-05-03 17:15:16 -04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-01-26 09:49:34 -05:00
|
|
|
#[test]
|
|
|
|
fn eval_with_v8_flags() {
|
|
|
|
let r =
|
|
|
|
flags_from_vec_safe(svec!["deno", "eval", "--v8-flags=--help", "42"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Eval {
|
|
|
|
code: "42".to_string(),
|
2020-02-28 09:17:56 -05:00
|
|
|
as_typescript: false,
|
2020-02-04 14:24:33 -05:00
|
|
|
},
|
2020-01-26 09:49:34 -05:00
|
|
|
v8_flags: Some(svec!["--help"]),
|
|
|
|
allow_net: true,
|
|
|
|
allow_env: true,
|
|
|
|
allow_run: true,
|
|
|
|
allow_read: true,
|
|
|
|
allow_write: true,
|
|
|
|
allow_plugin: true,
|
|
|
|
allow_hrtime: true,
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2020-01-26 09:49:34 -05:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-05-03 17:15:16 -04:00
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn repl() {
|
|
|
|
let r = flags_from_vec_safe(svec!["deno"]);
|
2019-05-03 17:15:16 -04:00
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Repl,
|
2019-05-03 17:15:16 -04:00
|
|
|
allow_net: true,
|
|
|
|
allow_env: true,
|
|
|
|
allow_run: true,
|
|
|
|
allow_read: true,
|
|
|
|
allow_write: true,
|
2019-12-05 15:30:20 -05:00
|
|
|
allow_plugin: true,
|
2019-05-23 12:28:29 -04:00
|
|
|
allow_hrtime: true,
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-05-03 17:15:16 -04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-04-30 11:23:40 -04:00
|
|
|
#[test]
|
|
|
|
fn repl_unstable() {
|
|
|
|
let r = flags_from_vec_safe(svec!["deno", "repl", "--unstable"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
unstable: true,
|
|
|
|
subcommand: DenoSubcommand::Repl,
|
|
|
|
allow_net: true,
|
|
|
|
allow_env: true,
|
|
|
|
allow_run: true,
|
|
|
|
allow_read: true,
|
|
|
|
allow_write: true,
|
|
|
|
allow_plugin: true,
|
|
|
|
allow_hrtime: true,
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-05-08 19:20:30 -04:00
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn allow_read_whitelist() {
|
2019-05-09 12:20:34 -04:00
|
|
|
use tempfile::TempDir;
|
2020-02-11 04:29:36 -05:00
|
|
|
let temp_dir = TempDir::new().expect("tempdir fail").path().to_path_buf();
|
2019-05-09 12:20:34 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
let r = flags_from_vec_safe(svec![
|
2019-05-08 19:20:30 -04:00
|
|
|
"deno",
|
|
|
|
"run",
|
2020-02-11 04:29:36 -05:00
|
|
|
format!("--allow-read=.,{}", temp_dir.to_str().unwrap()),
|
2019-05-08 19:20:30 -04:00
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2019-05-08 19:20:30 -04:00
|
|
|
allow_read: false,
|
2020-05-29 11:27:43 -04:00
|
|
|
read_whitelist: vec![PathBuf::from("."), temp_dir],
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Run {
|
|
|
|
script: "script.ts".to_string(),
|
|
|
|
},
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-05-08 19:20:30 -04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2019-06-09 09:08:20 -04:00
|
|
|
|
2019-05-08 19:20:30 -04:00
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn allow_write_whitelist() {
|
2019-05-09 12:20:34 -04:00
|
|
|
use tempfile::TempDir;
|
2020-02-11 04:29:36 -05:00
|
|
|
let temp_dir = TempDir::new().expect("tempdir fail").path().to_path_buf();
|
2019-05-09 12:20:34 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
let r = flags_from_vec_safe(svec![
|
2019-05-08 19:20:30 -04:00
|
|
|
"deno",
|
|
|
|
"run",
|
2020-02-11 04:29:36 -05:00
|
|
|
format!("--allow-write=.,{}", temp_dir.to_str().unwrap()),
|
2019-05-08 19:20:30 -04:00
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2019-05-08 19:20:30 -04:00
|
|
|
allow_write: false,
|
2020-05-29 11:27:43 -04:00
|
|
|
write_whitelist: vec![PathBuf::from("."), temp_dir],
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Run {
|
|
|
|
script: "script.ts".to_string(),
|
|
|
|
},
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-05-08 19:20:30 -04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2019-06-09 09:08:20 -04:00
|
|
|
|
2019-05-08 19:20:30 -04:00
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn allow_net_whitelist() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
2019-05-08 19:20:30 -04:00
|
|
|
"deno",
|
|
|
|
"run",
|
|
|
|
"--allow-net=127.0.0.1",
|
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Run {
|
|
|
|
script: "script.ts".to_string(),
|
|
|
|
},
|
2019-05-08 19:20:30 -04:00
|
|
|
allow_net: false,
|
|
|
|
net_whitelist: svec!["127.0.0.1"],
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-05-08 19:20:30 -04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2019-06-01 08:54:32 -04:00
|
|
|
|
2019-06-08 14:42:28 -04:00
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn bundle() {
|
|
|
|
let r = flags_from_vec_safe(svec!["deno", "bundle", "source.ts"]);
|
2019-06-08 14:42:28 -04:00
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Bundle {
|
|
|
|
source_file: "source.ts".to_string(),
|
|
|
|
out_file: None,
|
|
|
|
},
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-04-30 11:23:40 -04:00
|
|
|
#[test]
|
|
|
|
fn bundle_unstable() {
|
|
|
|
let r =
|
|
|
|
flags_from_vec_safe(svec!["deno", "bundle", "--unstable", "source.ts"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
unstable: true,
|
|
|
|
subcommand: DenoSubcommand::Bundle {
|
|
|
|
source_file: "source.ts".to_string(),
|
|
|
|
out_file: None,
|
|
|
|
},
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:02:03 -04:00
|
|
|
#[test]
|
|
|
|
fn bundle_with_config() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
|
|
|
"deno",
|
|
|
|
"bundle",
|
|
|
|
"--config",
|
|
|
|
"tsconfig.json",
|
|
|
|
"source.ts",
|
|
|
|
"bundle.js"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
subcommand: DenoSubcommand::Bundle {
|
|
|
|
source_file: "source.ts".to_string(),
|
|
|
|
out_file: Some(PathBuf::from("bundle.js")),
|
|
|
|
},
|
|
|
|
allow_write: true,
|
|
|
|
config_path: Some("tsconfig.json".to_owned()),
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
#[test]
|
|
|
|
fn bundle_with_output() {
|
|
|
|
let r =
|
|
|
|
flags_from_vec_safe(svec!["deno", "bundle", "source.ts", "bundle.js"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Bundle {
|
|
|
|
source_file: "source.ts".to_string(),
|
2020-02-11 04:29:36 -05:00
|
|
|
out_file: Some(PathBuf::from("bundle.js")),
|
2020-02-04 14:24:33 -05:00
|
|
|
},
|
2019-06-08 14:42:28 -04:00
|
|
|
allow_write: true,
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-06-08 14:42:28 -04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2019-06-09 09:08:20 -04:00
|
|
|
|
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn run_importmap() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
2019-06-09 09:08:20 -04:00
|
|
|
"deno",
|
|
|
|
"run",
|
|
|
|
"--importmap=importmap.json",
|
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Run {
|
|
|
|
script: "script.ts".to_string(),
|
|
|
|
},
|
2019-06-09 09:08:20 -04:00
|
|
|
import_map_path: Some("importmap.json".to_owned()),
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-06-09 09:08:20 -04:00
|
|
|
}
|
|
|
|
);
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
2019-06-09 09:08:20 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
#[test]
|
2020-04-07 11:24:47 -04:00
|
|
|
fn cache_importmap() {
|
2019-11-26 11:06:32 -05:00
|
|
|
let r = flags_from_vec_safe(svec![
|
2019-07-27 10:37:03 -04:00
|
|
|
"deno",
|
2020-04-07 11:24:47 -04:00
|
|
|
"cache",
|
2019-07-27 10:37:03 -04:00
|
|
|
"--importmap=importmap.json",
|
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-04-07 11:24:47 -04:00
|
|
|
subcommand: DenoSubcommand::Cache {
|
2020-02-04 14:24:33 -05:00
|
|
|
files: svec!["script.ts"],
|
|
|
|
},
|
2019-07-27 10:37:03 -04:00
|
|
|
import_map_path: Some("importmap.json".to_owned()),
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-07-27 10:37:03 -04:00
|
|
|
}
|
|
|
|
);
|
2019-06-09 09:08:20 -04:00
|
|
|
}
|
2019-06-11 10:34:39 -04:00
|
|
|
|
2020-01-31 16:07:37 -05:00
|
|
|
#[test]
|
2020-04-07 11:24:47 -04:00
|
|
|
fn cache_multiple() {
|
2020-01-31 16:07:37 -05:00
|
|
|
let r =
|
2020-04-07 11:24:47 -04:00
|
|
|
flags_from_vec_safe(svec!["deno", "cache", "script.ts", "script_two.ts"]);
|
2020-01-31 16:07:37 -05:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-04-07 11:24:47 -04:00
|
|
|
subcommand: DenoSubcommand::Cache {
|
2020-02-04 14:24:33 -05:00
|
|
|
files: svec!["script.ts", "script_two.ts"],
|
|
|
|
},
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2020-01-31 16:07:37 -05:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-11 10:34:39 -04:00
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn run_seed() {
|
|
|
|
let r =
|
|
|
|
flags_from_vec_safe(svec!["deno", "run", "--seed", "250", "script.ts"]);
|
2019-06-11 10:34:39 -04:00
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Run {
|
|
|
|
script: "script.ts".to_string(),
|
|
|
|
},
|
2019-06-11 10:34:39 -04:00
|
|
|
seed: Some(250 as u64),
|
2019-11-26 11:06:32 -05:00
|
|
|
v8_flags: Some(svec!["--random-seed=250"]),
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-06-11 10:34:39 -04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn run_seed_with_v8_flags() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
2019-06-11 10:34:39 -04:00
|
|
|
"deno",
|
2019-11-26 11:06:32 -05:00
|
|
|
"run",
|
2019-06-11 10:34:39 -04:00
|
|
|
"--seed",
|
|
|
|
"250",
|
|
|
|
"--v8-flags=--expose-gc",
|
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Run {
|
|
|
|
script: "script.ts".to_string(),
|
|
|
|
},
|
2019-06-11 10:34:39 -04:00
|
|
|
seed: Some(250 as u64),
|
2019-11-26 11:06:32 -05:00
|
|
|
v8_flags: Some(svec!["--expose-gc", "--random-seed=250"]),
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-06-11 10:34:39 -04:00
|
|
|
}
|
|
|
|
);
|
2019-06-15 10:08:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn install() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
2019-06-15 10:08:11 -04:00
|
|
|
"deno",
|
|
|
|
"install",
|
|
|
|
"https://deno.land/std/examples/colors.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-01-30 18:42:39 -05:00
|
|
|
subcommand: DenoSubcommand::Install {
|
2020-05-01 15:33:11 -04:00
|
|
|
name: None,
|
2020-01-30 18:42:39 -05:00
|
|
|
module_url: "https://deno.land/std/examples/colors.ts".to_string(),
|
|
|
|
args: vec![],
|
2020-05-01 15:33:11 -04:00
|
|
|
root: None,
|
2020-02-08 03:49:55 -05:00
|
|
|
force: false,
|
2020-01-30 18:42:39 -05:00
|
|
|
},
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-06-15 10:08:11 -04:00
|
|
|
}
|
|
|
|
);
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
2019-06-15 10:08:11 -04:00
|
|
|
|
2020-05-04 07:35:00 -04:00
|
|
|
#[test]
|
|
|
|
fn install_unstable() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
|
|
|
"deno",
|
|
|
|
"install",
|
|
|
|
"--unstable",
|
|
|
|
"https://deno.land/std/examples/colors.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
unstable: true,
|
|
|
|
subcommand: DenoSubcommand::Install {
|
|
|
|
name: None,
|
|
|
|
module_url: "https://deno.land/std/examples/colors.ts".to_string(),
|
|
|
|
args: svec![],
|
|
|
|
root: None,
|
|
|
|
force: false,
|
|
|
|
},
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
#[test]
|
|
|
|
fn install_with_args() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
2019-06-15 10:08:11 -04:00
|
|
|
"deno",
|
|
|
|
"install",
|
|
|
|
"--allow-net",
|
2020-01-30 18:42:39 -05:00
|
|
|
"--allow-read",
|
2020-05-01 15:33:11 -04:00
|
|
|
"-n",
|
2020-01-30 18:42:39 -05:00
|
|
|
"file_server",
|
|
|
|
"https://deno.land/std/http/file_server.ts"
|
2019-06-15 10:08:11 -04:00
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-01-30 18:42:39 -05:00
|
|
|
subcommand: DenoSubcommand::Install {
|
2020-05-01 15:33:11 -04:00
|
|
|
name: Some("file_server".to_string()),
|
2020-01-30 18:42:39 -05:00
|
|
|
module_url: "https://deno.land/std/http/file_server.ts".to_string(),
|
|
|
|
args: vec![],
|
2020-05-01 15:33:11 -04:00
|
|
|
root: None,
|
2020-02-08 03:49:55 -05:00
|
|
|
force: false,
|
2020-01-30 18:42:39 -05:00
|
|
|
},
|
2019-06-15 10:08:11 -04:00
|
|
|
allow_net: true,
|
|
|
|
allow_read: true,
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-06-15 10:08:11 -04:00
|
|
|
}
|
|
|
|
);
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
2019-06-20 14:25:13 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
#[test]
|
2020-02-08 03:49:55 -05:00
|
|
|
fn install_with_args_and_dir_and_force() {
|
2019-11-26 11:06:32 -05:00
|
|
|
let r = flags_from_vec_safe(svec![
|
2019-06-20 14:25:13 -04:00
|
|
|
"deno",
|
|
|
|
"install",
|
2020-04-16 18:15:42 -04:00
|
|
|
"--root",
|
|
|
|
"/usr/local",
|
2020-02-08 03:49:55 -05:00
|
|
|
"-f",
|
2020-01-30 18:42:39 -05:00
|
|
|
"--allow-net",
|
|
|
|
"--allow-read",
|
2020-05-01 15:33:11 -04:00
|
|
|
"-n",
|
2019-06-20 14:25:13 -04:00
|
|
|
"file_server",
|
|
|
|
"https://deno.land/std/http/file_server.ts",
|
2020-01-30 18:42:39 -05:00
|
|
|
"arg1",
|
|
|
|
"arg2"
|
2019-06-20 14:25:13 -04:00
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-01-30 18:42:39 -05:00
|
|
|
subcommand: DenoSubcommand::Install {
|
2020-05-01 15:33:11 -04:00
|
|
|
name: Some("file_server".to_string()),
|
2020-01-30 18:42:39 -05:00
|
|
|
module_url: "https://deno.land/std/http/file_server.ts".to_string(),
|
|
|
|
args: svec!["arg1", "arg2"],
|
2020-05-01 15:33:11 -04:00
|
|
|
root: Some(PathBuf::from("/usr/local")),
|
2020-02-08 03:49:55 -05:00
|
|
|
force: true,
|
2020-01-30 18:42:39 -05:00
|
|
|
},
|
2019-06-20 14:25:13 -04:00
|
|
|
allow_net: true,
|
|
|
|
allow_read: true,
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-06-20 14:25:13 -04:00
|
|
|
}
|
|
|
|
);
|
2019-06-11 10:34:39 -04:00
|
|
|
}
|
2019-06-22 12:02:51 -04:00
|
|
|
|
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn log_level() {
|
2020-05-04 07:03:30 -04:00
|
|
|
let r = flags_from_vec_safe(svec![
|
|
|
|
"deno",
|
|
|
|
"run",
|
|
|
|
"--log-level=debug",
|
|
|
|
"script.ts"
|
|
|
|
]);
|
2019-06-22 12:02:51 -04:00
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Run {
|
|
|
|
script: "script.ts".to_string(),
|
|
|
|
},
|
2019-06-22 12:02:51 -04:00
|
|
|
log_level: Some(Level::Debug),
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-06-22 12:02:51 -04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2019-06-26 06:02:13 -04:00
|
|
|
|
2020-03-10 08:26:17 -04:00
|
|
|
#[test]
|
|
|
|
fn quiet() {
|
2020-05-04 07:03:30 -04:00
|
|
|
let r = flags_from_vec_safe(svec!["deno", "run", "-q", "script.ts"]);
|
2020-03-10 08:26:17 -04:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
subcommand: DenoSubcommand::Run {
|
|
|
|
script: "script.ts".to_string(),
|
|
|
|
},
|
|
|
|
log_level: Some(Level::Error),
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-26 06:02:13 -04:00
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn completions() {
|
2020-02-04 14:24:33 -05:00
|
|
|
let r = flags_from_vec_safe(svec!["deno", "completions", "bash"]).unwrap();
|
|
|
|
|
|
|
|
match r.subcommand {
|
|
|
|
DenoSubcommand::Completions { buf } => assert!(!buf.is_empty()),
|
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
2019-06-26 06:02:13 -04:00
|
|
|
}
|
2019-06-29 18:32:54 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
/* TODO(ry) Fix this test
|
2019-06-29 18:32:54 -04:00
|
|
|
#[test]
|
|
|
|
fn test_flags_from_vec_33() {
|
|
|
|
let (flags, subcommand, argv) =
|
2019-11-26 11:06:32 -05:00
|
|
|
flags_from_vec_safe(svec!["deno", "script.ts", "--allow-read", "--allow-net"]);
|
2019-06-29 18:32:54 -04:00
|
|
|
assert_eq!(
|
|
|
|
flags,
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2019-06-29 18:32:54 -04:00
|
|
|
allow_net: true,
|
|
|
|
allow_read: true,
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-06-29 18:32:54 -04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
assert_eq!(subcommand, DenoSubcommand::Run);
|
2020-02-04 14:24:33 -05:00
|
|
|
assert_eq!(argv, svec!["script.ts"]);
|
2019-06-29 18:32:54 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
let (flags, subcommand, argv) = flags_from_vec_safe(svec![
|
2019-06-29 18:32:54 -04:00
|
|
|
"deno",
|
|
|
|
"run",
|
2019-11-26 11:06:32 -05:00
|
|
|
"--allow-read",
|
2019-06-29 18:32:54 -04:00
|
|
|
"script.ts",
|
|
|
|
"--allow-net",
|
|
|
|
"-r",
|
|
|
|
"--help",
|
|
|
|
"--foo",
|
|
|
|
"bar"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
flags,
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2019-06-29 18:32:54 -04:00
|
|
|
allow_net: true,
|
|
|
|
allow_read: true,
|
|
|
|
reload: true,
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-06-29 18:32:54 -04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
assert_eq!(subcommand, DenoSubcommand::Run);
|
|
|
|
assert_eq!(argv, svec!["deno", "script.ts", "--help", "--foo", "bar"]);
|
2019-07-10 20:26:01 -04:00
|
|
|
|
|
|
|
let (flags, subcommand, argv) =
|
2020-02-04 14:24:33 -05:00
|
|
|
flags_from_vec_safe(svec!["deno""script.ts", "foo", "bar"]);
|
2020-02-26 05:52:15 -05:00
|
|
|
assert_eq!(flags, Flags::default());
|
2019-07-10 20:26:01 -04:00
|
|
|
assert_eq!(subcommand, DenoSubcommand::Run);
|
2020-02-04 14:24:33 -05:00
|
|
|
assert_eq!(argv, svec!["script.ts", "foo", "bar"]);
|
2019-07-10 20:26:01 -04:00
|
|
|
|
|
|
|
let (flags, subcommand, argv) =
|
2020-02-04 14:24:33 -05:00
|
|
|
flags_from_vec_safe(svec!["deno""script.ts", "-"]);
|
2020-02-26 05:52:15 -05:00
|
|
|
assert_eq!(flags, Flags::default());
|
2019-07-10 20:26:01 -04:00
|
|
|
assert_eq!(subcommand, DenoSubcommand::Run);
|
2020-02-04 14:24:33 -05:00
|
|
|
assert_eq!(argv, svec!["script.ts", "-"]);
|
2019-07-10 20:26:01 -04:00
|
|
|
|
|
|
|
let (flags, subcommand, argv) =
|
2020-02-04 14:24:33 -05:00
|
|
|
flags_from_vec_safe(svec!["deno""script.ts", "-", "foo", "bar"]);
|
2020-02-26 05:52:15 -05:00
|
|
|
assert_eq!(flags, Flags::default());
|
2019-07-10 20:26:01 -04:00
|
|
|
assert_eq!(subcommand, DenoSubcommand::Run);
|
2020-02-04 14:24:33 -05:00
|
|
|
assert_eq!(argv, svec!["script.ts", "-", "foo", "bar"]);
|
2019-06-29 18:32:54 -04:00
|
|
|
}
|
2019-11-26 11:06:32 -05:00
|
|
|
*/
|
2019-07-20 09:19:06 -04:00
|
|
|
|
|
|
|
#[test]
|
2019-12-03 17:48:53 -05:00
|
|
|
fn no_remote() {
|
2020-05-04 07:03:30 -04:00
|
|
|
let r =
|
|
|
|
flags_from_vec_safe(svec!["deno", "run", "--no-remote", "script.ts"]);
|
2019-12-03 17:48:53 -05:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Run {
|
|
|
|
script: "script.ts".to_string(),
|
|
|
|
},
|
2019-12-03 17:48:53 -05:00
|
|
|
no_remote: true,
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-12-03 17:48:53 -05:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn cached_only() {
|
2020-05-04 07:03:30 -04:00
|
|
|
let r =
|
|
|
|
flags_from_vec_safe(svec!["deno", "run", "--cached-only", "script.ts"]);
|
2019-07-20 09:19:06 -04:00
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Run {
|
|
|
|
script: "script.ts".to_string(),
|
|
|
|
},
|
2019-12-03 17:48:53 -05:00
|
|
|
cached_only: true,
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-07-20 09:19:06 -04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2019-07-31 11:02:20 -04:00
|
|
|
|
2019-10-12 17:13:52 -04:00
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn allow_net_whitelist_with_ports() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
2019-10-12 17:13:52 -04:00
|
|
|
"deno",
|
2020-05-04 07:03:30 -04:00
|
|
|
"run",
|
2019-10-12 17:13:52 -04:00
|
|
|
"--allow-net=deno.land,:8000,:4545",
|
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Run {
|
|
|
|
script: "script.ts".to_string(),
|
|
|
|
},
|
2019-10-12 17:13:52 -04:00
|
|
|
net_whitelist: svec![
|
|
|
|
"deno.land",
|
|
|
|
"0.0.0.0:8000",
|
|
|
|
"127.0.0.1:8000",
|
|
|
|
"localhost:8000",
|
|
|
|
"0.0.0.0:4545",
|
|
|
|
"127.0.0.1:4545",
|
|
|
|
"localhost:4545"
|
|
|
|
],
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-10-12 17:13:52 -04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2019-11-03 10:39:27 -05:00
|
|
|
|
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn lock_write() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
2019-11-03 10:39:27 -05:00
|
|
|
"deno",
|
2020-05-04 07:03:30 -04:00
|
|
|
"run",
|
2019-11-03 10:39:27 -05:00
|
|
|
"--lock-write",
|
|
|
|
"--lock=lock.json",
|
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-04 14:24:33 -05:00
|
|
|
subcommand: DenoSubcommand::Run {
|
|
|
|
script: "script.ts".to_string(),
|
|
|
|
},
|
2019-11-03 10:39:27 -05:00
|
|
|
lock_write: true,
|
|
|
|
lock: Some("lock.json".to_string()),
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-11-03 10:39:27 -05:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2019-11-13 11:21:17 -05:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
#[test]
|
|
|
|
fn test_with_allow_net() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
|
|
|
"deno",
|
|
|
|
"test",
|
|
|
|
"--allow-net",
|
2020-02-11 06:01:56 -05:00
|
|
|
"--allow-none",
|
2019-11-26 11:06:32 -05:00
|
|
|
"dir1/",
|
|
|
|
"dir2/"
|
|
|
|
]);
|
2019-11-13 11:21:17 -05:00
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2020-02-26 05:52:15 -05:00
|
|
|
Flags {
|
2020-02-11 06:01:56 -05:00
|
|
|
subcommand: DenoSubcommand::Test {
|
|
|
|
fail_fast: false,
|
2020-04-02 09:26:40 -04:00
|
|
|
filter: None,
|
2020-02-11 06:01:56 -05:00
|
|
|
allow_none: true,
|
2020-04-27 07:05:26 -04:00
|
|
|
quiet: false,
|
2020-02-11 06:01:56 -05:00
|
|
|
include: Some(svec!["dir1/", "dir2/"]),
|
2020-02-04 14:24:33 -05:00
|
|
|
},
|
2019-11-26 11:06:32 -05:00
|
|
|
allow_net: true,
|
2020-02-26 05:52:15 -05:00
|
|
|
..Flags::default()
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
2019-11-13 11:21:17 -05:00
|
|
|
);
|
|
|
|
}
|
2020-02-17 11:59:51 -05:00
|
|
|
|
2020-04-02 09:26:40 -04:00
|
|
|
#[test]
|
|
|
|
fn test_filter() {
|
|
|
|
let r = flags_from_vec_safe(svec!["deno", "test", "--filter=foo", "dir1"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
subcommand: DenoSubcommand::Test {
|
|
|
|
fail_fast: false,
|
|
|
|
allow_none: false,
|
2020-04-27 07:05:26 -04:00
|
|
|
quiet: false,
|
2020-04-02 09:26:40 -04:00
|
|
|
filter: Some("foo".to_string()),
|
|
|
|
include: Some(svec!["dir1"]),
|
|
|
|
},
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-02-17 11:59:51 -05:00
|
|
|
|
2020-04-02 09:26:40 -04:00
|
|
|
#[test]
|
|
|
|
fn run_with_cafile() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
|
|
|
"deno",
|
|
|
|
"run",
|
|
|
|
"--cert",
|
|
|
|
"example.crt",
|
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
subcommand: DenoSubcommand::Run {
|
|
|
|
script: "script.ts".to_string(),
|
|
|
|
},
|
|
|
|
ca_file: Some("example.crt".to_owned()),
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-02-17 11:59:51 -05:00
|
|
|
|
2020-04-02 09:26:40 -04:00
|
|
|
#[test]
|
|
|
|
fn bundle_with_cafile() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
|
|
|
"deno",
|
|
|
|
"bundle",
|
|
|
|
"--cert",
|
|
|
|
"example.crt",
|
|
|
|
"source.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
subcommand: DenoSubcommand::Bundle {
|
|
|
|
source_file: "source.ts".to_string(),
|
|
|
|
out_file: None,
|
|
|
|
},
|
|
|
|
ca_file: Some("example.crt".to_owned()),
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-02-17 11:59:51 -05:00
|
|
|
|
2020-04-02 09:26:40 -04:00
|
|
|
#[test]
|
|
|
|
fn eval_with_cafile() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
|
|
|
"deno",
|
|
|
|
"eval",
|
|
|
|
"--cert",
|
|
|
|
"example.crt",
|
|
|
|
"console.log('hello world')"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
subcommand: DenoSubcommand::Eval {
|
|
|
|
code: "console.log('hello world')".to_string(),
|
|
|
|
as_typescript: false,
|
|
|
|
},
|
|
|
|
ca_file: Some("example.crt".to_owned()),
|
|
|
|
allow_net: true,
|
|
|
|
allow_env: true,
|
|
|
|
allow_run: true,
|
|
|
|
allow_read: true,
|
|
|
|
allow_write: true,
|
|
|
|
allow_plugin: true,
|
|
|
|
allow_hrtime: true,
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-04-01 09:35:34 -04:00
|
|
|
|
2020-04-02 09:26:40 -04:00
|
|
|
#[test]
|
|
|
|
fn eval_with_inspect() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
|
|
|
"deno",
|
|
|
|
"eval",
|
|
|
|
"--inspect",
|
|
|
|
"const foo = 'bar'"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
subcommand: DenoSubcommand::Eval {
|
|
|
|
code: "const foo = 'bar'".to_string(),
|
|
|
|
as_typescript: false,
|
|
|
|
},
|
2020-04-03 13:40:11 -04:00
|
|
|
inspect: Some("127.0.0.1:9229".parse().unwrap()),
|
2020-04-02 09:26:40 -04:00
|
|
|
allow_net: true,
|
|
|
|
allow_env: true,
|
|
|
|
allow_run: true,
|
|
|
|
allow_read: true,
|
|
|
|
allow_write: true,
|
|
|
|
allow_plugin: true,
|
|
|
|
allow_hrtime: true,
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-02-17 11:59:51 -05:00
|
|
|
|
2020-04-02 09:26:40 -04:00
|
|
|
#[test]
|
2020-04-07 11:24:47 -04:00
|
|
|
fn cache_with_cafile() {
|
2020-04-02 09:26:40 -04:00
|
|
|
let r = flags_from_vec_safe(svec![
|
|
|
|
"deno",
|
2020-04-07 11:24:47 -04:00
|
|
|
"cache",
|
2020-04-02 09:26:40 -04:00
|
|
|
"--cert",
|
|
|
|
"example.crt",
|
|
|
|
"script.ts",
|
|
|
|
"script_two.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2020-04-07 11:24:47 -04:00
|
|
|
subcommand: DenoSubcommand::Cache {
|
2020-04-02 09:26:40 -04:00
|
|
|
files: svec!["script.ts", "script_two.ts"],
|
|
|
|
},
|
|
|
|
ca_file: Some("example.crt".to_owned()),
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-02-17 11:59:51 -05:00
|
|
|
|
2020-04-02 09:26:40 -04:00
|
|
|
#[test]
|
|
|
|
fn info_with_cafile() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
|
|
|
"deno",
|
|
|
|
"info",
|
|
|
|
"--cert",
|
|
|
|
"example.crt",
|
|
|
|
"https://example.com"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
subcommand: DenoSubcommand::Info {
|
|
|
|
file: Some("https://example.com".to_string()),
|
|
|
|
},
|
|
|
|
ca_file: Some("example.crt".to_owned()),
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-02-17 11:59:51 -05:00
|
|
|
|
2020-04-02 09:26:40 -04:00
|
|
|
#[test]
|
|
|
|
fn install_with_cafile() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
|
|
|
"deno",
|
|
|
|
"install",
|
|
|
|
"--cert",
|
|
|
|
"example.crt",
|
2020-05-01 15:33:11 -04:00
|
|
|
"-n",
|
2020-04-02 09:26:40 -04:00
|
|
|
"deno_colors",
|
|
|
|
"https://deno.land/std/examples/colors.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
subcommand: DenoSubcommand::Install {
|
2020-05-01 15:33:11 -04:00
|
|
|
name: Some("deno_colors".to_string()),
|
2020-04-02 09:26:40 -04:00
|
|
|
module_url: "https://deno.land/std/examples/colors.ts".to_string(),
|
|
|
|
args: vec![],
|
2020-05-01 15:33:11 -04:00
|
|
|
root: None,
|
2020-04-02 09:26:40 -04:00
|
|
|
force: false,
|
|
|
|
},
|
|
|
|
ca_file: Some("example.crt".to_owned()),
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-03-27 16:09:51 -04:00
|
|
|
|
2020-04-02 09:26:40 -04:00
|
|
|
#[test]
|
|
|
|
fn repl_with_cafile() {
|
|
|
|
let r = flags_from_vec_safe(svec!["deno", "repl", "--cert", "example.crt"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
subcommand: DenoSubcommand::Repl {},
|
|
|
|
ca_file: Some("example.crt".to_owned()),
|
|
|
|
allow_read: true,
|
|
|
|
allow_write: true,
|
|
|
|
allow_net: true,
|
|
|
|
allow_env: true,
|
|
|
|
allow_run: true,
|
|
|
|
allow_plugin: true,
|
|
|
|
allow_hrtime: true,
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-04-01 09:35:34 -04:00
|
|
|
|
2020-04-02 09:26:40 -04:00
|
|
|
#[test]
|
|
|
|
fn repl_with_inspect() {
|
|
|
|
let r = flags_from_vec_safe(svec!["deno", "repl", "--inspect"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
subcommand: DenoSubcommand::Repl {},
|
2020-04-03 13:40:11 -04:00
|
|
|
inspect: Some("127.0.0.1:9229".parse().unwrap()),
|
2020-04-02 09:26:40 -04:00
|
|
|
allow_read: true,
|
|
|
|
allow_write: true,
|
|
|
|
allow_net: true,
|
|
|
|
allow_env: true,
|
|
|
|
allow_run: true,
|
|
|
|
allow_plugin: true,
|
|
|
|
allow_hrtime: true,
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-03-28 14:16:57 -04:00
|
|
|
|
2020-04-02 09:26:40 -04:00
|
|
|
#[test]
|
|
|
|
fn doc() {
|
|
|
|
let r =
|
|
|
|
flags_from_vec_safe(svec!["deno", "doc", "--json", "path/to/module.ts"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
subcommand: DenoSubcommand::Doc {
|
|
|
|
json: true,
|
2020-04-09 08:34:24 -04:00
|
|
|
source_file: Some("path/to/module.ts".to_string()),
|
2020-04-02 09:26:40 -04:00
|
|
|
filter: None,
|
|
|
|
},
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
2020-03-28 14:16:57 -04:00
|
|
|
|
2020-04-02 09:26:40 -04:00
|
|
|
let r = flags_from_vec_safe(svec![
|
|
|
|
"deno",
|
|
|
|
"doc",
|
|
|
|
"path/to/module.ts",
|
|
|
|
"SomeClass.someField"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
subcommand: DenoSubcommand::Doc {
|
|
|
|
json: false,
|
2020-04-09 08:34:24 -04:00
|
|
|
source_file: Some("path/to/module.ts".to_string()),
|
2020-04-02 09:26:40 -04:00
|
|
|
filter: Some("SomeClass.someField".to_string()),
|
|
|
|
},
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
2020-04-09 08:34:24 -04:00
|
|
|
|
|
|
|
let r = flags_from_vec_safe(svec!["deno", "doc"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
subcommand: DenoSubcommand::Doc {
|
|
|
|
json: false,
|
|
|
|
source_file: None,
|
|
|
|
filter: None,
|
|
|
|
},
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
let r =
|
|
|
|
flags_from_vec_safe(svec!["deno", "doc", "--builtin", "Deno.Listener"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
subcommand: DenoSubcommand::Doc {
|
|
|
|
json: false,
|
|
|
|
source_file: Some("--builtin".to_string()),
|
|
|
|
filter: Some("Deno.Listener".to_string()),
|
|
|
|
},
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
2020-04-02 09:26:40 -04:00
|
|
|
}
|
2020-03-27 16:09:51 -04:00
|
|
|
|
2020-04-02 09:26:40 -04:00
|
|
|
#[test]
|
|
|
|
fn inspect_default_host() {
|
|
|
|
let r = flags_from_vec_safe(svec!["deno", "run", "--inspect", "foo.js"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
subcommand: DenoSubcommand::Run {
|
|
|
|
script: "foo.js".to_string(),
|
|
|
|
},
|
2020-04-03 13:40:11 -04:00
|
|
|
inspect: Some("127.0.0.1:9229".parse().unwrap()),
|
2020-04-02 09:26:40 -04:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-03-27 16:09:51 -04:00
|
|
|
}
|