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;
|
2019-11-26 23:25:14 -05:00
|
|
|
use std::collections::HashSet;
|
2019-11-26 11:06:32 -05:00
|
|
|
|
|
|
|
/// Creates vector of strings, Vec<String>
|
|
|
|
macro_rules! svec {
|
|
|
|
($($x:expr),*) => (vec![$($x.to_string()),*]);
|
|
|
|
}
|
2019-11-26 23:25:14 -05:00
|
|
|
/// Creates HashSet<String> from string literals
|
|
|
|
macro_rules! sset {
|
|
|
|
($($x:expr),*) => {{
|
|
|
|
let _v = svec![$($x.to_string()),*];
|
|
|
|
let hash_set: HashSet<String> = _v.iter().cloned().collect();
|
|
|
|
hash_set
|
|
|
|
}}
|
|
|
|
}
|
2018-08-17 16:34:30 -04:00
|
|
|
|
2019-09-12 12:56:53 -04:00
|
|
|
macro_rules! std_url {
|
|
|
|
($x:expr) => {
|
2020-01-07 19:05:52 -05:00
|
|
|
concat!("https://deno.land/std@v0.28.1/", $x)
|
2019-09-12 12:56:53 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Used for `deno fmt <files>...` subcommand
|
|
|
|
const PRETTIER_URL: &str = std_url!("prettier/main.ts");
|
|
|
|
/// Used for `deno install...` subcommand
|
|
|
|
const INSTALLER_URL: &str = std_url!("installer/mod.ts");
|
|
|
|
/// Used for `deno test...` subcommand
|
|
|
|
const TEST_RUNNER_URL: &str = std_url!("testing/runner.ts");
|
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
|
|
pub enum DenoSubcommand {
|
|
|
|
Bundle,
|
|
|
|
Completions,
|
|
|
|
Eval,
|
|
|
|
Fetch,
|
|
|
|
Help,
|
|
|
|
Info,
|
|
|
|
Install,
|
|
|
|
Repl,
|
|
|
|
Run,
|
|
|
|
Types,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for DenoSubcommand {
|
|
|
|
fn default() -> DenoSubcommand {
|
|
|
|
DenoSubcommand::Run
|
|
|
|
}
|
2018-08-17 16:34:30 -04:00
|
|
|
}
|
|
|
|
|
2019-01-08 14:44:06 -05:00
|
|
|
#[derive(Clone, Debug, PartialEq, Default)]
|
2018-08-17 16:34:30 -04:00
|
|
|
pub struct DenoFlags {
|
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,
|
|
|
|
|
2019-06-22 12:02:51 -04:00
|
|
|
pub log_level: Option<Level>,
|
2018-08-17 16:34:30 -04:00
|
|
|
pub version: bool,
|
|
|
|
pub reload: bool,
|
2019-04-29 10:58:31 -04:00
|
|
|
pub config_path: Option<String>,
|
2019-06-09 09:08:20 -04:00
|
|
|
pub import_map_path: Option<String>,
|
2019-02-08 15:59:38 -05:00
|
|
|
pub allow_read: bool,
|
2019-05-08 19:20:30 -04:00
|
|
|
pub read_whitelist: Vec<String>,
|
2019-10-17 10:29:06 -04:00
|
|
|
pub cache_blacklist: Vec<String>,
|
2018-08-17 16:34:30 -04:00
|
|
|
pub allow_write: bool,
|
2019-05-08 19:20:30 -04:00
|
|
|
pub write_whitelist: Vec<String>,
|
2018-08-17 16:34:30 -04:00
|
|
|
pub allow_net: bool,
|
2019-05-08 19:20:30 -04:00
|
|
|
pub net_whitelist: Vec<String>,
|
2018-08-31 07:51:12 -04:00
|
|
|
pub allow_env: bool,
|
2018-11-15 23:07:40 -05:00
|
|
|
pub allow_run: bool,
|
2019-12-05 15:30:20 -05:00
|
|
|
pub allow_plugin: bool,
|
2019-05-23 12:28:29 -04:00
|
|
|
pub allow_hrtime: bool,
|
2019-03-13 12:43:47 -04:00
|
|
|
pub no_prompts: bool,
|
2019-12-03 17:48:53 -05:00
|
|
|
pub no_remote: bool,
|
|
|
|
pub cached_only: bool,
|
2019-06-11 10:34:39 -04:00
|
|
|
pub seed: Option<u64>,
|
2019-04-21 11:34:18 -04:00
|
|
|
pub v8_flags: Option<Vec<String>>,
|
2019-07-31 11:02:20 -04:00
|
|
|
// Use tokio::runtime::current_thread
|
|
|
|
pub current_thread: bool,
|
2019-11-03 10:39:27 -05:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
pub bundle_output: Option<String>,
|
|
|
|
|
2019-11-03 10:39:27 -05:00
|
|
|
pub lock: Option<String>,
|
|
|
|
pub lock_write: bool,
|
2018-11-15 12:56:17 -05:00
|
|
|
}
|
|
|
|
|
2019-04-13 13:24:15 -04:00
|
|
|
static ENV_VARIABLES_HELP: &str = "ENVIRONMENT VARIABLES:
|
2019-11-26 11:06:32 -05:00
|
|
|
DENO_DIR Set deno's base directory
|
|
|
|
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
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
Docs: https://deno.land/std/manual.md
|
2019-10-12 15:23:58 -04:00
|
|
|
Modules: https://deno.land/x/
|
2019-05-23 14:57:44 -04:00
|
|
|
Bugs: https://github.com/denoland/deno/issues
|
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
To run the REPL supply no arguments:
|
2019-05-23 14:57:44 -04:00
|
|
|
|
|
|
|
deno
|
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
To evaluate code from the command line:
|
|
|
|
|
|
|
|
deno eval \"console.log(30933 + 404)\"
|
|
|
|
|
|
|
|
To execute a script:
|
2019-05-23 14:57:44 -04:00
|
|
|
|
2019-11-03 10:39:27 -05:00
|
|
|
deno https://deno.land/std/examples/welcome.ts
|
2019-05-23 14:57:44 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
The default subcommand is 'run'. The above is equivalent to
|
2019-05-23 14:57:44 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
deno run https://deno.land/std/examples/welcome.ts
|
2019-05-23 14:57:44 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
See 'deno help run' for run specific flags.";
|
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.
|
|
|
|
pub fn flags_from_vec(args: Vec<String>) -> DenoFlags {
|
|
|
|
match flags_from_vec_safe(args) {
|
|
|
|
Ok(flags) => flags,
|
|
|
|
Err(err) => err.exit(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Same as flags_from_vec but does not exit on error.
|
|
|
|
pub fn flags_from_vec_safe(args: Vec<String>) -> clap::Result<DenoFlags> {
|
|
|
|
let args0 = args[0].clone();
|
|
|
|
let args = arg_hacks(args);
|
|
|
|
let app = clap_root();
|
|
|
|
let matches = app.get_matches_from_safe(args)?;
|
|
|
|
|
|
|
|
let mut flags = DenoFlags::default();
|
|
|
|
|
|
|
|
flags.argv.push(args0);
|
|
|
|
|
|
|
|
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!(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
} else if let Some(m) = matches.subcommand_matches("fetch") {
|
|
|
|
fetch_parse(&mut flags, m);
|
|
|
|
} 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);
|
|
|
|
} else {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
)
|
2019-11-26 11:06:32 -05:00
|
|
|
.subcommand(bundle_subcommand())
|
|
|
|
.subcommand(completions_subcommand())
|
|
|
|
.subcommand(eval_subcommand())
|
|
|
|
.subcommand(fetch_subcommand())
|
|
|
|
.subcommand(fmt_subcommand())
|
|
|
|
.subcommand(info_subcommand())
|
|
|
|
.subcommand(install_subcommand())
|
|
|
|
.subcommand(repl_subcommand())
|
|
|
|
.subcommand(run_subcommand())
|
|
|
|
.subcommand(test_subcommand())
|
|
|
|
.subcommand(types_subcommand())
|
|
|
|
.long_about(DENO_HELP)
|
|
|
|
.after_help(ENV_VARIABLES_HELP)
|
|
|
|
}
|
2019-11-13 10:35:56 -05:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn types_parse(flags: &mut DenoFlags, _matches: &clap::ArgMatches) {
|
|
|
|
flags.subcommand = DenoSubcommand::Types;
|
|
|
|
}
|
2019-06-11 14:38:19 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn fmt_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
|
|
|
|
flags.subcommand = DenoSubcommand::Run;
|
|
|
|
flags.allow_read = true;
|
|
|
|
flags.allow_write = true;
|
|
|
|
flags.argv.push(PRETTIER_URL.to_string());
|
|
|
|
|
|
|
|
let files: Vec<String> = matches
|
|
|
|
.values_of("files")
|
|
|
|
.unwrap()
|
|
|
|
.map(String::from)
|
|
|
|
.collect();
|
|
|
|
flags.argv.extend(files);
|
|
|
|
|
|
|
|
if !matches.is_present("stdout") {
|
|
|
|
// `deno fmt` writes to the files by default
|
|
|
|
flags.argv.push("--write".to_string());
|
|
|
|
}
|
2019-06-11 14:38:19 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
let prettier_flags = [
|
|
|
|
["0", "check"],
|
|
|
|
["1", "prettierrc"],
|
|
|
|
["1", "ignore-path"],
|
|
|
|
["1", "print-width"],
|
|
|
|
["1", "tab-width"],
|
|
|
|
["0", "use-tabs"],
|
|
|
|
["0", "no-semi"],
|
|
|
|
["0", "single-quote"],
|
|
|
|
["1", "quote-props"],
|
|
|
|
["0", "jsx-single-quote"],
|
|
|
|
["0", "jsx-bracket-same-line"],
|
|
|
|
["0", "trailing-comma"],
|
|
|
|
["0", "no-bracket-spacing"],
|
|
|
|
["1", "arrow-parens"],
|
|
|
|
["1", "prose-wrap"],
|
|
|
|
["1", "end-of-line"],
|
|
|
|
];
|
|
|
|
|
|
|
|
for opt in &prettier_flags {
|
|
|
|
let t = opt[0];
|
|
|
|
let keyword = opt[1];
|
|
|
|
|
|
|
|
if matches.is_present(&keyword) {
|
|
|
|
if t == "0" {
|
|
|
|
flags.argv.push(format!("--{}", keyword));
|
|
|
|
} else {
|
|
|
|
if keyword == "prettierrc" {
|
|
|
|
flags.argv.push("--config".to_string());
|
|
|
|
} else {
|
|
|
|
flags.argv.push(format!("--{}", keyword));
|
|
|
|
}
|
|
|
|
flags
|
|
|
|
.argv
|
|
|
|
.push(matches.value_of(keyword).unwrap().to_string());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-01 19:15:37 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn install_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
|
|
|
|
flags.subcommand = DenoSubcommand::Run;
|
|
|
|
flags.allow_read = true;
|
|
|
|
flags.allow_write = true;
|
|
|
|
flags.allow_net = true;
|
|
|
|
flags.allow_env = true;
|
|
|
|
flags.allow_run = true;
|
|
|
|
flags.argv.push(INSTALLER_URL.to_string());
|
|
|
|
|
|
|
|
if matches.is_present("dir") {
|
|
|
|
let install_dir = matches.value_of("dir").unwrap();
|
|
|
|
flags.argv.push("--dir".to_string());
|
|
|
|
println!("dir {}", install_dir);
|
|
|
|
flags.argv.push(install_dir.to_string());
|
|
|
|
} else {
|
|
|
|
println!("no dir");
|
|
|
|
}
|
2019-05-01 19:15:37 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
let exe_name = matches.value_of("exe_name").unwrap();
|
|
|
|
flags.argv.push(String::from(exe_name));
|
2019-05-23 14:57:44 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
let cmd = matches.values_of("cmd").unwrap();
|
|
|
|
for arg in cmd {
|
|
|
|
flags.argv.push(String::from(arg));
|
|
|
|
}
|
|
|
|
}
|
2019-05-01 19:15:37 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn bundle_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
|
|
|
|
flags.subcommand = DenoSubcommand::Bundle;
|
|
|
|
let source_file: &str = matches.value_of("source_file").unwrap();
|
|
|
|
flags.argv.push(source_file.into());
|
|
|
|
if let Some(out_file) = matches.value_of("out_file") {
|
|
|
|
flags.allow_write = true;
|
|
|
|
flags.bundle_output = Some(out_file.to_string());
|
|
|
|
}
|
|
|
|
}
|
2019-05-23 14:57:44 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn completions_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
|
|
|
|
flags.subcommand = DenoSubcommand::Completions;
|
|
|
|
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,
|
|
|
|
);
|
|
|
|
// TODO(ry) This flags module should only be for parsing flags, not actually
|
|
|
|
// acting upon the flags. Although this print is innocent, it breaks the
|
|
|
|
// model. The print should be moved out.
|
|
|
|
print!("{}", std::str::from_utf8(&buf).unwrap());
|
|
|
|
}
|
2019-08-11 20:43:01 -04:00
|
|
|
|
2019-11-26 23:25:14 -05:00
|
|
|
fn repl_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
|
|
|
|
v8_flags_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
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn eval_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
|
|
|
|
flags.subcommand = DenoSubcommand::Eval;
|
|
|
|
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;
|
|
|
|
let code: &str = matches.value_of("code").unwrap();
|
|
|
|
flags.argv.extend(vec![code.to_string()]);
|
|
|
|
}
|
2019-05-01 19:15:37 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn info_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
|
|
|
|
flags.subcommand = DenoSubcommand::Info;
|
|
|
|
if let Some(file) = matches.value_of("file") {
|
|
|
|
flags.argv.push(file.into());
|
|
|
|
}
|
|
|
|
}
|
2019-05-01 19:15:37 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn fetch_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
|
|
|
|
flags.subcommand = DenoSubcommand::Fetch;
|
|
|
|
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);
|
2019-11-26 11:06:32 -05:00
|
|
|
if let Some(file) = matches.value_of("file") {
|
|
|
|
flags.argv.push(file.into());
|
|
|
|
}
|
|
|
|
}
|
2019-05-01 19:15:37 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn lock_args_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
|
|
|
|
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.
|
|
|
|
fn run_test_args_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
|
|
|
|
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);
|
2019-05-23 14:57:44 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
if matches.is_present("allow-read") {
|
|
|
|
if matches.value_of("allow-read").is_some() {
|
|
|
|
let read_wl = matches.values_of("allow-read").unwrap();
|
|
|
|
let raw_read_whitelist: Vec<String> =
|
|
|
|
read_wl.map(std::string::ToString::to_string).collect();
|
|
|
|
flags.read_whitelist = raw_read_whitelist;
|
|
|
|
debug!("read whitelist: {:#?}", &flags.read_whitelist);
|
|
|
|
} else {
|
|
|
|
flags.allow_read = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if matches.is_present("allow-write") {
|
|
|
|
if matches.value_of("allow-write").is_some() {
|
|
|
|
let write_wl = matches.values_of("allow-write").unwrap();
|
|
|
|
let raw_write_whitelist =
|
|
|
|
write_wl.map(std::string::ToString::to_string).collect();
|
|
|
|
flags.write_whitelist = raw_write_whitelist;
|
|
|
|
debug!("write whitelist: {:#?}", &flags.write_whitelist);
|
|
|
|
} else {
|
|
|
|
flags.allow_write = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if matches.is_present("allow-net") {
|
|
|
|
if matches.value_of("allow-net").is_some() {
|
|
|
|
let net_wl = matches.values_of("allow-net").unwrap();
|
|
|
|
let raw_net_whitelist =
|
|
|
|
net_wl.map(std::string::ToString::to_string).collect();
|
|
|
|
flags.net_whitelist = resolve_hosts(raw_net_whitelist);
|
|
|
|
debug!("net whitelist: {:#?}", &flags.net_whitelist);
|
|
|
|
} else {
|
|
|
|
flags.allow_net = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if matches.is_present("allow-env") {
|
|
|
|
flags.allow_env = true;
|
|
|
|
}
|
|
|
|
if matches.is_present("allow-run") {
|
|
|
|
flags.allow_run = true;
|
|
|
|
}
|
2019-12-05 15:30:20 -05:00
|
|
|
if matches.is_present("allow-plugin") {
|
|
|
|
flags.allow_plugin = true;
|
|
|
|
}
|
2019-11-26 11:06:32 -05:00
|
|
|
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;
|
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-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("current-thread") {
|
|
|
|
flags.current_thread = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
|
|
|
|
flags.subcommand = DenoSubcommand::Run;
|
|
|
|
script_arg_parse(flags, matches);
|
2020-01-08 14:59:53 -05:00
|
|
|
args_parse(flags, matches);
|
2019-11-26 11:06:32 -05:00
|
|
|
run_test_args_parse(flags, matches);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
|
|
|
|
flags.subcommand = DenoSubcommand::Run;
|
|
|
|
flags.allow_read = true;
|
|
|
|
|
|
|
|
flags.argv.push(TEST_RUNNER_URL.to_string());
|
|
|
|
|
|
|
|
run_test_args_parse(flags, matches);
|
|
|
|
|
|
|
|
if matches.is_present("quiet") {
|
|
|
|
flags.argv.push("--quiet".to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
if matches.is_present("failfast") {
|
|
|
|
flags.argv.push("--failfast".to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
if matches.is_present("exclude") {
|
|
|
|
flags.argv.push("--exclude".to_string());
|
|
|
|
let exclude: Vec<String> = matches
|
|
|
|
.values_of("exclude")
|
|
|
|
.unwrap()
|
|
|
|
.map(String::from)
|
|
|
|
.collect();
|
|
|
|
flags.argv.extend(exclude);
|
|
|
|
}
|
|
|
|
|
|
|
|
if matches.is_present("files") {
|
|
|
|
flags.argv.push("--".to_string());
|
|
|
|
let files: Vec<String> = matches
|
|
|
|
.values_of("files")
|
|
|
|
.unwrap()
|
|
|
|
.map(String::from)
|
|
|
|
.collect();
|
|
|
|
flags.argv.extend(files);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn types_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
SubCommand::with_name("types")
|
|
|
|
.about("Print runtime TypeScript declarations")
|
|
|
|
.long_about(
|
|
|
|
"Print runtime TypeScript declarations.
|
|
|
|
|
|
|
|
deno types > lib.deno_runtime.d.ts
|
|
|
|
|
|
|
|
The declaration file could be saved and used for typing information.",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn fmt_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
SubCommand::with_name("fmt")
|
|
|
|
.about("Format files")
|
|
|
|
.long_about(
|
|
|
|
"Auto-format JavaScript/TypeScript source code using Prettier
|
|
|
|
|
|
|
|
Automatically downloads Prettier dependencies on first run.
|
|
|
|
|
|
|
|
deno fmt myfile1.ts myfile2.ts",
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("check")
|
|
|
|
.long("check")
|
|
|
|
.help("Check if the source files are formatted.")
|
|
|
|
.takes_value(false),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("prettierrc")
|
|
|
|
.long("prettierrc")
|
|
|
|
.value_name("auto|disable|FILE")
|
2019-11-16 11:48:45 -05:00
|
|
|
.help("Specify the configuration file of the prettier.
|
|
|
|
auto: Auto detect prettier configuration file in current working dir.
|
|
|
|
disable: Disable load configuration file.
|
|
|
|
FILE: Load specified prettier configuration file. support .json/.toml/.js/.ts file
|
|
|
|
")
|
|
|
|
.takes_value(true)
|
|
|
|
.require_equals(true)
|
|
|
|
.default_value("auto")
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("ignore-path")
|
|
|
|
.long("ignore-path")
|
|
|
|
.value_name("auto|disable|FILE")
|
|
|
|
.help("Path to a file containing patterns that describe files to ignore.
|
|
|
|
auto: Auto detect .pretierignore file in current working dir.
|
|
|
|
disable: Disable load .prettierignore file.
|
|
|
|
FILE: Load specified prettier ignore file.
|
|
|
|
")
|
|
|
|
.takes_value(true)
|
|
|
|
.require_equals(true)
|
|
|
|
.default_value("auto")
|
|
|
|
)
|
2019-11-13 11:21:17 -05:00
|
|
|
.arg(
|
2019-06-01 08:54:32 -04:00
|
|
|
Arg::with_name("stdout")
|
|
|
|
.long("stdout")
|
|
|
|
.help("Output formated code to stdout")
|
|
|
|
.takes_value(false),
|
2019-11-13 11:21:17 -05:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("print-width")
|
|
|
|
.long("print-width")
|
|
|
|
.value_name("int")
|
|
|
|
.help("Specify the line length that the printer will wrap on.")
|
|
|
|
.takes_value(true)
|
|
|
|
.require_equals(true)
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("tab-width")
|
|
|
|
.long("tab-width")
|
|
|
|
.value_name("int")
|
|
|
|
.help("Specify the number of spaces per indentation-level.")
|
|
|
|
.takes_value(true)
|
|
|
|
.require_equals(true)
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("use-tabs")
|
|
|
|
.long("use-tabs")
|
|
|
|
.help("Indent lines with tabs instead of spaces.")
|
|
|
|
.takes_value(false)
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("no-semi")
|
|
|
|
.long("no-semi")
|
|
|
|
.help("Print semicolons at the ends of statements.")
|
|
|
|
.takes_value(false)
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("single-quote")
|
|
|
|
.long("single-quote")
|
|
|
|
.help("Use single quotes instead of double quotes.")
|
|
|
|
.takes_value(false)
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("quote-props")
|
|
|
|
.long("quote-props")
|
|
|
|
.value_name("as-needed|consistent|preserve")
|
|
|
|
.help("Change when properties in objects are quoted.")
|
|
|
|
.takes_value(true)
|
|
|
|
.possible_values(&["as-needed", "consistent", "preserve"])
|
|
|
|
.require_equals(true)
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("jsx-single-quote")
|
|
|
|
.long("jsx-single-quote")
|
|
|
|
.help("Use single quotes instead of double quotes in JSX.")
|
|
|
|
.takes_value(false)
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("jsx-bracket-same-line")
|
|
|
|
.long("jsx-bracket-same-line")
|
|
|
|
.help(
|
|
|
|
"Put the > of a multi-line JSX element at the end of the last line
|
|
|
|
instead of being alone on the next line (does not apply to self closing elements)."
|
|
|
|
)
|
|
|
|
.takes_value(false)
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("trailing-comma")
|
|
|
|
.long("trailing-comma")
|
|
|
|
.help("Print trailing commas wherever possible when multi-line.")
|
|
|
|
.takes_value(false)
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("no-bracket-spacing")
|
|
|
|
.long("no-bracket-spacing")
|
|
|
|
.help("Print spaces between brackets in object literals.")
|
|
|
|
.takes_value(false)
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("arrow-parens")
|
|
|
|
.long("arrow-parens")
|
|
|
|
.value_name("avoid|always")
|
|
|
|
.help("Include parentheses around a sole arrow function parameter.")
|
|
|
|
.takes_value(true)
|
|
|
|
.possible_values(&["avoid", "always"])
|
|
|
|
.require_equals(true)
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("prose-wrap")
|
|
|
|
.long("prose-wrap")
|
|
|
|
.value_name("always|never|preserve")
|
|
|
|
.help("How to wrap prose.")
|
|
|
|
.takes_value(true)
|
|
|
|
.possible_values(&["always", "never", "preserve"])
|
|
|
|
.require_equals(true)
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("end-of-line")
|
|
|
|
.long("end-of-line")
|
|
|
|
.value_name("auto|lf|crlf|cr")
|
|
|
|
.help("Which end of line characters to apply.")
|
|
|
|
.takes_value(true)
|
|
|
|
.possible_values(&["auto", "lf", "crlf", "cr"])
|
|
|
|
.require_equals(true)
|
|
|
|
)
|
|
|
|
.arg(
|
2019-04-13 13:24:15 -04:00
|
|
|
Arg::with_name("files")
|
|
|
|
.takes_value(true)
|
|
|
|
.multiple(true)
|
|
|
|
.required(true),
|
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> {
|
2019-11-26 23:25:14 -05:00
|
|
|
SubCommand::with_name("repl")
|
|
|
|
.about("Read Eval Print Loop")
|
|
|
|
.arg(v8_flags_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> {
|
|
|
|
SubCommand::with_name("install")
|
|
|
|
.setting(AppSettings::TrailingVarArg)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("dir")
|
|
|
|
.long("dir")
|
|
|
|
.short("d")
|
|
|
|
.help("Installation directory (defaults to $HOME/.deno/bin)")
|
2019-08-15 10:11:52 -04:00
|
|
|
.takes_value(true)
|
2019-11-26 11:06:32 -05:00
|
|
|
.multiple(false))
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("exe_name")
|
|
|
|
.required(true)
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("cmd")
|
|
|
|
.required(true)
|
2019-08-15 10:11:52 -04:00
|
|
|
.multiple(true)
|
2019-11-26 11:06:32 -05:00
|
|
|
.allow_hyphen_values(true)
|
|
|
|
)
|
|
|
|
.about("Install script as executable")
|
2019-05-03 17:15:16 -04:00
|
|
|
.long_about(
|
2019-11-26 11:06:32 -05:00
|
|
|
"Installs a script as executable. The default installation directory is
|
|
|
|
$HOME/.deno/bin and it must be added to the path manually.
|
2019-05-03 17:15:16 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
deno install file_server https://deno.land/std/http/file_server.ts --allow-net --allow-read
|
|
|
|
|
|
|
|
deno install colors https://deno.land/std/examples/colors.ts
|
2019-05-03 17:15:16 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
To change installation directory use -d/--dir flag
|
2019-05-03 17:15:16 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
deno install -d /usr/local/bin file_server https://deno.land/std/http/file_server.ts --allow-net --allow-read")
|
|
|
|
}
|
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))
|
|
|
|
.about("Bundle module and dependencies into single file")
|
|
|
|
.long_about(
|
|
|
|
"Output a single JavaScript file with all dependencies.
|
2019-05-16 10:39:19 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
If a out_file argument is omitted, the output of the bundle will be sent to
|
|
|
|
standard out. Examples:
|
|
|
|
|
|
|
|
deno bundle https://deno.land/std/examples/colors.ts
|
|
|
|
|
|
|
|
deno bundle https://deno.land/std/examples/colors.ts colors.bundle.js",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
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> {
|
|
|
|
SubCommand::with_name("eval")
|
|
|
|
.about("Eval script")
|
|
|
|
.long_about(
|
|
|
|
"Evaluate JavaScript from command-line
|
2019-06-26 06:02:13 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
This command has implicit access to all permissions (--allow-all)
|
2019-06-26 06:02:13 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
deno eval \"console.log('hello world')\"",
|
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))
|
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(
|
|
|
|
"Information about source file and cache
|
2019-05-09 12:20:34 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
Example: 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.
|
|
|
|
compiled: Local path of compiled source code (TypeScript only)
|
|
|
|
map: Local path of source map (TypeScript only)
|
|
|
|
deps: Dependency tree of the source file.
|
2019-10-12 17:13:52 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
Without any additional arguments 'deno info' shows:
|
2019-10-12 17:13:52 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
DENO_DIR: directory containing Deno-related files
|
|
|
|
Remote modules cache: directory containing remote modules
|
|
|
|
TypeScript compiler cache: directory containing TS compiler output",
|
|
|
|
)
|
|
|
|
.arg(Arg::with_name("file").takes_value(true).required(false))
|
2019-10-12 17:13:52 -04:00
|
|
|
}
|
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn fetch_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
SubCommand::with_name("fetch")
|
|
|
|
.arg(reload_arg())
|
|
|
|
.arg(lock_arg())
|
|
|
|
.arg(lock_write_arg())
|
|
|
|
.arg(importmap_arg())
|
|
|
|
.arg(config_arg())
|
2019-12-03 17:48:53 -05:00
|
|
|
.arg(no_remote_arg())
|
2019-11-26 11:06:32 -05:00
|
|
|
.arg(Arg::with_name("file").takes_value(true).required(true))
|
|
|
|
.about("Fetch the dependencies")
|
|
|
|
.long_about(
|
|
|
|
"Fetch and compile remote dependencies recursively.
|
2019-04-06 18:13:06 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
Downloads all statically imported scripts and save them in local
|
|
|
|
cache, without running the code. No future import network requests
|
|
|
|
would be made unless --reload is specified.
|
2019-06-11 10:34:39 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
Downloads all dependencies
|
2019-06-11 10:34:39 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
deno fetch https://deno.land/std/http/file_server.ts
|
2019-04-06 18:13:06 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
Once cached, static imports no longer send network requests
|
2019-06-05 13:44:46 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
deno run -A https://deno.land/std/http/file_server.ts",
|
|
|
|
)
|
2019-06-05 13:44:46 -04:00
|
|
|
}
|
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn run_test_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
|
|
|
|
app
|
|
|
|
.arg(importmap_arg())
|
|
|
|
.arg(reload_arg())
|
|
|
|
.arg(config_arg())
|
|
|
|
.arg(lock_arg())
|
|
|
|
.arg(lock_write_arg())
|
2019-12-03 17:48:53 -05:00
|
|
|
.arg(no_remote_arg())
|
2019-11-26 23:25:14 -05:00
|
|
|
.arg(v8_flags_arg())
|
2019-11-26 11:06:32 -05:00
|
|
|
.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"),
|
|
|
|
)
|
|
|
|
.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("current-thread")
|
|
|
|
.long("current-thread")
|
|
|
|
.help("Use tokio::runtime::current_thread"),
|
|
|
|
)
|
|
|
|
.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-01-08 14:59:53 -05:00
|
|
|
.arg(args_arg())
|
2019-11-26 11:06:32 -05:00
|
|
|
.about("Run a program given a filename or url to the source code")
|
|
|
|
.long_about(
|
|
|
|
"Run a program given a filename or url to the source code.
|
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.
|
2019-06-29 18:32:54 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
deno run https://deno.land/std/examples/welcome.ts
|
2019-06-29 18:32:54 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
With all permissions
|
2019-06-29 18:32:54 -04:00
|
|
|
|
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
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
With only permission to read from disk and listen to network
|
2019-06-29 18:32:54 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
deno run --allow-net --allow-read https://deno.land/std/http/file_server.ts
|
|
|
|
|
|
|
|
With only permission to read whitelist files from disk
|
|
|
|
|
2020-01-08 14:59:53 -05:00
|
|
|
deno run --allow-read=/etc https://deno.land/std/http/file_server.ts
|
|
|
|
|
|
|
|
Any arguments that should be passed to the script should be prefixed by '--'
|
|
|
|
|
|
|
|
deno run -A https://deno.land/std/examples/cat.ts -- /etc/passwd",
|
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")
|
|
|
|
.short("f")
|
|
|
|
.long("failfast")
|
|
|
|
.help("Stop on first error")
|
|
|
|
.takes_value(false),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("quiet")
|
|
|
|
.short("q")
|
|
|
|
.long("quiet")
|
|
|
|
.help("Don't show output from test cases")
|
|
|
|
.takes_value(false),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("exclude")
|
|
|
|
.short("e")
|
|
|
|
.long("exclude")
|
|
|
|
.help("List of file names to exclude from run")
|
|
|
|
.takes_value(true),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("files")
|
|
|
|
.help("List of file names to run")
|
|
|
|
.takes_value(true)
|
|
|
|
.multiple(true),
|
|
|
|
)
|
|
|
|
.about("Run tests")
|
|
|
|
.long_about(
|
|
|
|
"Run tests using test runner
|
2019-04-29 19:43:06 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
Searches the specified directories for all files that end in _test.ts or
|
|
|
|
_test.js and executes them.
|
2019-07-27 05:20:40 -04:00
|
|
|
|
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-08 14:59:53 -05:00
|
|
|
Arg::with_name("script").help("script").value_name("SCRIPT")
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
2019-11-13 11:21:17 -05:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn script_arg_parse(flags: &mut DenoFlags, matches: &ArgMatches) {
|
2020-01-08 14:59:53 -05:00
|
|
|
if let Some(script_value) = matches.value_of("script") {
|
|
|
|
debug_assert!(flags.argv.len() == 1);
|
|
|
|
flags.argv.push(String::from(script_value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn args_arg<'a, 'b>() -> Arg<'a, 'b> {
|
|
|
|
Arg::with_name("script_args")
|
|
|
|
.raw(true)
|
|
|
|
.help("script args")
|
|
|
|
.value_name("SCRIPT_ARGS")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn args_parse(flags: &mut DenoFlags, matches: &ArgMatches) {
|
|
|
|
if let Some(values) = matches.values_of("script_args") {
|
|
|
|
for v in values {
|
2019-11-26 11:06:32 -05:00
|
|
|
flags.argv.push(String::from(v));
|
2019-04-29 19:43:06 -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
|
|
|
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
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn config_arg_parse(flags: &mut DenoFlags, matches: &ArgMatches) {
|
|
|
|
flags.config_path = matches.value_of("config").map(ToOwned::to_owned);
|
|
|
|
}
|
2019-08-15 10:11:52 -04:00
|
|
|
|
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
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn reload_arg_parse(flags: &mut DenoFlags, matches: &ArgMatches) {
|
|
|
|
if matches.is_present("reload") {
|
|
|
|
if matches.value_of("reload").is_some() {
|
|
|
|
let cache_bl = matches.values_of("reload").unwrap();
|
|
|
|
let raw_cache_blacklist: Vec<String> =
|
|
|
|
cache_bl.map(std::string::ToString::to_string).collect();
|
|
|
|
flags.cache_blacklist = resolve_urls(raw_cache_blacklist);
|
|
|
|
debug!("cache blacklist: {:#?}", &flags.cache_blacklist);
|
|
|
|
flags.reload = false;
|
|
|
|
} else {
|
|
|
|
flags.reload = true;
|
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")
|
|
|
|
.help("Load import map file")
|
|
|
|
.long_help(
|
|
|
|
"Load import map file
|
|
|
|
Docs: https://deno.land/std/manual.md#import-maps
|
|
|
|
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
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
fn importmap_arg_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn v8_flags_arg_parse(flags: &mut DenoFlags, matches: &ArgMatches) {
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn no_remote_arg_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
|
|
|
|
if matches.is_present("no-remote") {
|
|
|
|
flags.no_remote = 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
|
|
|
|
}
|
|
|
|
|
|
|
|
fn arg_hacks(mut args: Vec<String>) -> Vec<String> {
|
|
|
|
// Hack #1 We want to default the subcommand to "run"
|
|
|
|
// Clap does not let us have a default sub-command. But we want to allow users
|
|
|
|
// to do "deno script.js" instead of "deno run script.js".
|
|
|
|
// This function insert the "run" into the second position of the args.
|
|
|
|
assert!(!args.is_empty());
|
2019-11-26 23:25:14 -05:00
|
|
|
// Rational:
|
|
|
|
// deno -> deno repl
|
2019-11-26 11:06:32 -05:00
|
|
|
if args.len() == 1 {
|
|
|
|
args.insert(1, "repl".to_string());
|
2019-11-26 23:25:14 -05:00
|
|
|
return args;
|
|
|
|
}
|
|
|
|
let subcommands = sset![
|
|
|
|
"bundle",
|
|
|
|
"completions",
|
|
|
|
"eval",
|
|
|
|
"fetch",
|
|
|
|
"fmt",
|
|
|
|
"test",
|
|
|
|
"info",
|
|
|
|
"repl",
|
|
|
|
"run",
|
|
|
|
"types",
|
|
|
|
"install",
|
|
|
|
"help",
|
2020-01-08 17:40:59 -05:00
|
|
|
"version"
|
2019-11-26 23:25:14 -05:00
|
|
|
];
|
|
|
|
let modifier_flags = sset!["-h", "--help", "-V", "--version"];
|
|
|
|
// deno [subcommand|behavior modifier flags] -> do nothing
|
|
|
|
if subcommands.contains(&args[1]) || modifier_flags.contains(&args[1]) {
|
|
|
|
return args;
|
|
|
|
}
|
|
|
|
// This is not perfect either, since originally we should also
|
|
|
|
// support e.g. `-L debug` which `debug` would be treated as main module.
|
|
|
|
// Instead `-L=debug` must be used
|
|
|
|
let mut has_main_module = false;
|
|
|
|
for arg in args.iter().skip(1) {
|
|
|
|
if !arg.starts_with('-') {
|
|
|
|
has_main_module = true;
|
|
|
|
break;
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
|
|
|
}
|
2019-11-26 23:25:14 -05:00
|
|
|
if has_main_module {
|
|
|
|
// deno ...-[flags] NAME ... -> deno run ...-[flags] NAME ...
|
|
|
|
args.insert(1, "run".to_string());
|
|
|
|
} else {
|
|
|
|
// deno ...-[flags] -> deno repl ...-[flags]
|
|
|
|
args.insert(1, "repl".to_string());
|
|
|
|
}
|
2019-11-26 11:06:32 -05:00
|
|
|
args
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
2019-11-26 23:25:14 -05:00
|
|
|
#[test]
|
|
|
|
fn arg_hacks_test() {
|
|
|
|
let args0 = arg_hacks(svec!["deno", "--version"]);
|
|
|
|
assert_eq!(args0, ["deno", "--version"]);
|
|
|
|
let args1 = arg_hacks(svec!["deno"]);
|
|
|
|
assert_eq!(args1, ["deno", "repl"]);
|
|
|
|
let args2 = arg_hacks(svec!["deno", "-L=debug", "-h"]);
|
|
|
|
assert_eq!(args2, ["deno", "repl", "-L=debug", "-h"]);
|
|
|
|
let args3 = arg_hacks(svec!["deno", "script.js"]);
|
|
|
|
assert_eq!(args3, ["deno", "run", "script.js"]);
|
|
|
|
let args4 = arg_hacks(svec!["deno", "-A", "script.js", "-L=info"]);
|
|
|
|
assert_eq!(args4, ["deno", "run", "-A", "script.js", "-L=info"]);
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec!["deno", "script.ts"],
|
2019-04-21 11:34:18 -04:00
|
|
|
reload: true,
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
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(),
|
2019-04-21 11:34:18 -04:00
|
|
|
DenoFlags {
|
|
|
|
reload: true,
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec!["deno", "script.ts"],
|
2019-04-21 11:34:18 -04:00
|
|
|
allow_write: true,
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
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(),
|
2019-04-21 11:34:18 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec!["deno", "script.ts"],
|
|
|
|
v8_flags: Some(svec!["--help"]),
|
2019-04-21 11:34:18 -04:00
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
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(),
|
2019-04-21 11:34:18 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec!["deno", "script.ts"],
|
|
|
|
v8_flags: Some(svec!["--expose-gc", "--gc-stats=1"]),
|
2019-04-21 11:34:18 -04:00
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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",
|
2020-01-08 14:59:53 -05:00
|
|
|
"--",
|
2019-05-03 17:15:16 -04:00
|
|
|
"--title",
|
|
|
|
"X"
|
|
|
|
]);
|
2019-04-21 11:34:18 -04:00
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2019-04-21 11:34:18 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec!["deno", "gist.ts", "--title", "X"],
|
2019-04-21 11:34:18 -04:00
|
|
|
allow_net: true,
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
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(),
|
2019-04-21 11:34:18 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec!["deno", "gist.ts"],
|
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,
|
2019-04-21 11:34:18 -04:00
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
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(),
|
2019-04-21 11:34:18 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec!["deno", "gist.ts"],
|
2019-04-21 11:34:18 -04:00
|
|
|
allow_read: true,
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
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(),
|
2019-04-21 11:34:18 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec!["deno", "gist.ts"],
|
2019-05-23 12:28:29 -04:00
|
|
|
allow_hrtime: true,
|
2019-04-21 11:34:18 -04:00
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
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
|
2019-04-21 11:34:18 -04:00
|
|
|
// be parsed to DenoFlags but instead forwarded to
|
|
|
|
// 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(),
|
2019-04-21 11:34:18 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
2020-01-08 14:59:53 -05:00
|
|
|
argv: svec!["deno", "script.ts", "-D", "--allow-net"],
|
2019-04-21 11:34:18 -04:00
|
|
|
allow_write: true,
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
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(),
|
2019-04-29 19:43:06 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
2019-04-29 19:43:06 -04:00
|
|
|
allow_write: true,
|
|
|
|
allow_read: true,
|
2019-11-26 11:06:32 -05:00
|
|
|
argv: svec![
|
|
|
|
"deno",
|
|
|
|
PRETTIER_URL,
|
|
|
|
"script_1.ts",
|
|
|
|
"script_2.ts",
|
|
|
|
"--write",
|
|
|
|
"--config",
|
|
|
|
"auto",
|
|
|
|
"--ignore-path",
|
|
|
|
"auto"
|
|
|
|
],
|
2019-04-29 19:43:06 -04:00
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn types() {
|
|
|
|
let r = flags_from_vec_safe(svec!["deno", "types"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
DenoFlags {
|
|
|
|
subcommand: DenoSubcommand::Types,
|
|
|
|
argv: svec!["deno"],
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
2019-04-29 19:43:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn fetch() {
|
|
|
|
let r = flags_from_vec_safe(svec!["deno", "fetch", "script.ts"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
DenoFlags {
|
|
|
|
subcommand: DenoSubcommand::Fetch,
|
|
|
|
argv: svec!["deno", "script.ts"],
|
|
|
|
..DenoFlags::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(),
|
|
|
|
DenoFlags {
|
|
|
|
subcommand: DenoSubcommand::Info,
|
|
|
|
// TODO(ry) I'm not sure the argv values in this case make sense.
|
|
|
|
// Nothing is being executed. Shouldn't argv be empty?
|
|
|
|
argv: svec!["deno", "script.ts"],
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
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(),
|
|
|
|
DenoFlags {
|
|
|
|
subcommand: DenoSubcommand::Info,
|
2020-01-02 07:48:46 -05:00
|
|
|
argv: svec!["deno"], // TODO(ry) Ditto argv unnecessary?
|
2019-11-26 11:06:32 -05:00
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
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(),
|
2019-05-03 17:15:16 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec!["deno", "script.ts"],
|
2019-05-03 17:15:16 -04:00
|
|
|
config_path: Some("tsconfig.json".to_owned()),
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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(),
|
2019-05-03 17:15:16 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Eval,
|
|
|
|
// TODO(ry) argv in this test seems odd and potentially not correct.
|
|
|
|
argv: svec!["deno", "'console.log(\"hello\")'"],
|
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,
|
2019-05-03 17:15:16 -04:00
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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(),
|
2019-05-03 17:15:16 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Repl,
|
|
|
|
argv: svec!["deno"],
|
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,
|
2019-05-03 17:15:16 -04:00
|
|
|
..DenoFlags::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;
|
|
|
|
let temp_dir = TempDir::new().expect("tempdir fail");
|
2019-11-26 11:06:32 -05:00
|
|
|
let temp_dir_path = temp_dir.path().to_str().unwrap();
|
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",
|
2019-05-09 12:20:34 -04:00
|
|
|
format!("--allow-read={}", &temp_dir_path),
|
2019-05-08 19:20:30 -04:00
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2019-05-08 19:20:30 -04:00
|
|
|
DenoFlags {
|
|
|
|
allow_read: false,
|
2019-05-09 12:20:34 -04:00
|
|
|
read_whitelist: svec![&temp_dir_path],
|
2019-11-26 11:06:32 -05:00
|
|
|
argv: svec!["deno", "script.ts"],
|
|
|
|
subcommand: DenoSubcommand::Run,
|
2019-05-08 19:20:30 -04:00
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
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;
|
|
|
|
let temp_dir = TempDir::new().expect("tempdir fail");
|
2019-11-26 11:06:32 -05:00
|
|
|
let temp_dir_path = temp_dir.path().to_str().unwrap();
|
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",
|
2019-05-09 12:20:34 -04:00
|
|
|
format!("--allow-write={}", &temp_dir_path),
|
2019-05-08 19:20:30 -04:00
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2019-05-08 19:20:30 -04:00
|
|
|
DenoFlags {
|
|
|
|
allow_write: false,
|
2019-05-09 12:20:34 -04:00
|
|
|
write_whitelist: svec![&temp_dir_path],
|
2019-11-26 11:06:32 -05:00
|
|
|
argv: svec!["deno", "script.ts"],
|
|
|
|
subcommand: DenoSubcommand::Run,
|
2019-05-08 19:20:30 -04:00
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
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(),
|
2019-05-08 19:20:30 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec!["deno", "script.ts"],
|
2019-05-08 19:20:30 -04:00
|
|
|
allow_net: false,
|
|
|
|
net_whitelist: svec!["127.0.0.1"],
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2019-06-01 08:54:32 -04:00
|
|
|
|
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn fmt_stdout() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
2019-06-01 08:54:32 -04:00
|
|
|
"deno",
|
|
|
|
"fmt",
|
|
|
|
"--stdout",
|
|
|
|
"script_1.ts",
|
|
|
|
"script_2.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2019-06-01 08:54:32 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec![
|
|
|
|
"deno",
|
|
|
|
PRETTIER_URL,
|
|
|
|
"script_1.ts",
|
|
|
|
"script_2.ts",
|
|
|
|
"--config",
|
|
|
|
"auto",
|
|
|
|
"--ignore-path",
|
|
|
|
"auto"
|
|
|
|
],
|
2019-06-01 08:54:32 -04:00
|
|
|
allow_write: true,
|
|
|
|
allow_read: true,
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
2019-06-05 13:44:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn default_to_run() {
|
|
|
|
let r = flags_from_vec_safe(svec!["deno", "script.ts"]);
|
2019-06-05 13:44:46 -04:00
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2019-06-05 13:44:46 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec!["deno", "script.ts"],
|
2019-06-05 13:44:46 -04:00
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn default_to_run_with_permissions() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
2019-06-05 13:44:46 -04:00
|
|
|
"deno",
|
|
|
|
"--allow-net",
|
|
|
|
"--allow-read",
|
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2019-06-05 13:44:46 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec!["deno", "script.ts"],
|
2019-06-05 13:44:46 -04:00
|
|
|
allow_net: true,
|
|
|
|
allow_read: true,
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
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(),
|
|
|
|
DenoFlags {
|
|
|
|
subcommand: DenoSubcommand::Bundle,
|
|
|
|
argv: svec!["deno", "source.ts"],
|
|
|
|
bundle_output: None,
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn bundle_with_output() {
|
|
|
|
let r =
|
|
|
|
flags_from_vec_safe(svec!["deno", "bundle", "source.ts", "bundle.js"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
2019-06-08 14:42:28 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Bundle,
|
|
|
|
argv: svec!["deno", "source.ts"],
|
|
|
|
bundle_output: Some("bundle.js".to_string()),
|
2019-06-08 14:42:28 -04:00
|
|
|
allow_write: true,
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
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(),
|
2019-06-09 09:08:20 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec!["deno", "script.ts"],
|
2019-06-09 09:08:20 -04:00
|
|
|
import_map_path: Some("importmap.json".to_owned()),
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
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]
|
|
|
|
fn default_to_run_importmap() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
|
|
|
"deno",
|
|
|
|
"--importmap=importmap.json",
|
|
|
|
"script.ts"
|
|
|
|
]);
|
2019-06-09 09:08:20 -04:00
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2019-06-09 09:08:20 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec!["deno", "script.ts"],
|
2019-06-09 09:08:20 -04:00
|
|
|
import_map_path: Some("importmap.json".to_owned()),
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
2019-07-27 10:37:03 -04:00
|
|
|
|
2019-11-26 11:06:32 -05:00
|
|
|
#[test]
|
|
|
|
fn fetch_importmap() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
2019-07-27 10:37:03 -04:00
|
|
|
"deno",
|
|
|
|
"fetch",
|
|
|
|
"--importmap=importmap.json",
|
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2019-07-27 10:37:03 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Fetch,
|
|
|
|
argv: svec!["deno", "script.ts"],
|
2019-07-27 10:37:03 -04:00
|
|
|
import_map_path: Some("importmap.json".to_owned()),
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
2019-06-09 09:08:20 -04: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(),
|
2019-06-11 10:34:39 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec!["deno", "script.ts"],
|
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"]),
|
2019-06-11 10:34:39 -04:00
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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(),
|
2019-06-11 10:34:39 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec!["deno", "script.ts"],
|
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"]),
|
2019-06-11 10:34:39 -04:00
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
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",
|
|
|
|
"deno_colors",
|
|
|
|
"https://deno.land/std/examples/colors.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2019-06-15 10:08:11 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec![
|
|
|
|
"deno",
|
|
|
|
INSTALLER_URL,
|
|
|
|
"deno_colors",
|
|
|
|
"https://deno.land/std/examples/colors.ts"
|
|
|
|
],
|
2019-06-15 10:08:11 -04:00
|
|
|
allow_write: true,
|
|
|
|
allow_net: true,
|
|
|
|
allow_read: true,
|
|
|
|
allow_env: true,
|
|
|
|
allow_run: true,
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
2019-06-15 10:08:11 -04:00
|
|
|
|
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",
|
|
|
|
"file_server",
|
|
|
|
"https://deno.land/std/http/file_server.ts",
|
|
|
|
"--allow-net",
|
|
|
|
"--allow-read"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2019-06-15 10:08:11 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec![
|
|
|
|
"deno",
|
|
|
|
INSTALLER_URL,
|
|
|
|
"file_server",
|
|
|
|
"https://deno.land/std/http/file_server.ts",
|
|
|
|
"--allow-net",
|
|
|
|
"--allow-read"
|
|
|
|
],
|
2019-06-15 10:08:11 -04:00
|
|
|
allow_write: true,
|
|
|
|
allow_net: true,
|
|
|
|
allow_read: true,
|
|
|
|
allow_env: true,
|
|
|
|
allow_run: true,
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
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]
|
|
|
|
fn install_with_args_and_dir() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
2019-06-20 14:25:13 -04:00
|
|
|
"deno",
|
|
|
|
"install",
|
|
|
|
"-d",
|
|
|
|
"/usr/local/bin",
|
|
|
|
"file_server",
|
|
|
|
"https://deno.land/std/http/file_server.ts",
|
|
|
|
"--allow-net",
|
|
|
|
"--allow-read"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2019-06-20 14:25:13 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec![
|
|
|
|
"deno",
|
|
|
|
INSTALLER_URL,
|
|
|
|
"--dir",
|
|
|
|
"/usr/local/bin",
|
|
|
|
"file_server",
|
|
|
|
"https://deno.land/std/http/file_server.ts",
|
|
|
|
"--allow-net",
|
|
|
|
"--allow-read"
|
|
|
|
],
|
2019-06-20 14:25:13 -04:00
|
|
|
allow_write: true,
|
|
|
|
allow_net: true,
|
|
|
|
allow_read: true,
|
|
|
|
allow_env: true,
|
|
|
|
allow_run: true,
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
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() {
|
|
|
|
let r =
|
|
|
|
flags_from_vec_safe(svec!["deno", "--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(),
|
2019-06-22 12:02:51 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec!["deno", "script.ts"],
|
2019-06-22 12:02:51 -04:00
|
|
|
log_level: Some(Level::Debug),
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2019-06-26 06:02:13 -04:00
|
|
|
|
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn completions() {
|
|
|
|
let r = flags_from_vec_safe(svec!["deno", "completions", "bash"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
DenoFlags {
|
|
|
|
subcommand: DenoSubcommand::Completions,
|
|
|
|
argv: svec!["deno"], // TODO(ry) argv doesn't make sense here. Make it Option.
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
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,
|
|
|
|
DenoFlags {
|
|
|
|
allow_net: true,
|
|
|
|
allow_read: true,
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
assert_eq!(subcommand, DenoSubcommand::Run);
|
|
|
|
assert_eq!(argv, svec!["deno", "script.ts"]);
|
|
|
|
|
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,
|
|
|
|
DenoFlags {
|
|
|
|
allow_net: true,
|
|
|
|
allow_read: true,
|
|
|
|
reload: true,
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
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) =
|
2019-11-26 11:06:32 -05:00
|
|
|
flags_from_vec_safe(svec!["deno", "script.ts", "foo", "bar"]);
|
2019-07-10 20:26:01 -04:00
|
|
|
assert_eq!(flags, DenoFlags::default());
|
|
|
|
assert_eq!(subcommand, DenoSubcommand::Run);
|
|
|
|
assert_eq!(argv, svec!["deno", "script.ts", "foo", "bar"]);
|
|
|
|
|
|
|
|
let (flags, subcommand, argv) =
|
2019-11-26 11:06:32 -05:00
|
|
|
flags_from_vec_safe(svec!["deno", "script.ts", "-"]);
|
2019-07-10 20:26:01 -04:00
|
|
|
assert_eq!(flags, DenoFlags::default());
|
|
|
|
assert_eq!(subcommand, DenoSubcommand::Run);
|
|
|
|
assert_eq!(argv, svec!["deno", "script.ts", "-"]);
|
|
|
|
|
|
|
|
let (flags, subcommand, argv) =
|
2019-11-26 11:06:32 -05:00
|
|
|
flags_from_vec_safe(svec!["deno", "script.ts", "-", "foo", "bar"]);
|
2019-07-10 20:26:01 -04:00
|
|
|
assert_eq!(flags, DenoFlags::default());
|
|
|
|
assert_eq!(subcommand, DenoSubcommand::Run);
|
|
|
|
assert_eq!(argv, svec!["deno", "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() {
|
|
|
|
let r = flags_from_vec_safe(svec!["deno", "--no-remote", "script.ts"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
DenoFlags {
|
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec!["deno", "script.ts"],
|
|
|
|
no_remote: true,
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn cached_only() {
|
|
|
|
let r = flags_from_vec_safe(svec!["deno", "--cached-only", "script.ts"]);
|
2019-07-20 09:19:06 -04:00
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2019-07-20 09:19:06 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec!["deno", "script.ts"],
|
2019-12-03 17:48:53 -05:00
|
|
|
cached_only: true,
|
2019-07-20 09:19:06 -04:00
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2019-07-31 11:02:20 -04:00
|
|
|
|
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn current_thread() {
|
|
|
|
let r = flags_from_vec_safe(svec!["deno", "--current-thread", "script.ts"]);
|
2019-07-31 11:02:20 -04:00
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2019-07-31 11:02:20 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec!["deno", "script.ts"],
|
2019-07-31 11:02:20 -04:00
|
|
|
current_thread: true,
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
2019-08-16 18:20:36 -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",
|
|
|
|
"--allow-net=deno.land,:8000,:4545",
|
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2019-10-12 17:13:52 -04:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec!["deno", "script.ts"],
|
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"
|
|
|
|
],
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
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",
|
|
|
|
"--lock-write",
|
|
|
|
"--lock=lock.json",
|
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2019-11-03 10:39:27 -05:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec!["deno", "script.ts"],
|
2019-11-03 10:39:27 -05:00
|
|
|
lock_write: true,
|
|
|
|
lock: Some("lock.json".to_string()),
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2019-11-13 11:21:17 -05:00
|
|
|
|
|
|
|
#[test]
|
2019-11-26 11:06:32 -05:00
|
|
|
fn fmt_args() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
2019-11-13 11:21:17 -05:00
|
|
|
"deno",
|
|
|
|
"fmt",
|
2019-11-18 13:19:59 -05:00
|
|
|
"--check",
|
2019-11-16 11:48:45 -05:00
|
|
|
"--prettierrc=auto",
|
2019-11-13 11:21:17 -05:00
|
|
|
"--print-width=100",
|
|
|
|
"--tab-width=4",
|
|
|
|
"--use-tabs",
|
|
|
|
"--no-semi",
|
|
|
|
"--single-quote",
|
|
|
|
"--arrow-parens=always",
|
|
|
|
"--prose-wrap=preserve",
|
|
|
|
"--end-of-line=crlf",
|
|
|
|
"--quote-props=preserve",
|
|
|
|
"--jsx-single-quote",
|
|
|
|
"--jsx-bracket-same-line",
|
2019-11-16 11:48:45 -05:00
|
|
|
"--ignore-path=.prettier-ignore",
|
2019-11-13 11:21:17 -05:00
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
2019-11-13 11:21:17 -05:00
|
|
|
DenoFlags {
|
2019-11-26 11:06:32 -05:00
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec![
|
|
|
|
"deno",
|
|
|
|
PRETTIER_URL,
|
|
|
|
"script.ts",
|
|
|
|
"--write",
|
|
|
|
"--check",
|
|
|
|
"--config",
|
|
|
|
"auto",
|
|
|
|
"--ignore-path",
|
|
|
|
".prettier-ignore",
|
|
|
|
"--print-width",
|
|
|
|
"100",
|
|
|
|
"--tab-width",
|
|
|
|
"4",
|
|
|
|
"--use-tabs",
|
|
|
|
"--no-semi",
|
|
|
|
"--single-quote",
|
|
|
|
"--quote-props",
|
|
|
|
"preserve",
|
|
|
|
"--jsx-single-quote",
|
|
|
|
"--jsx-bracket-same-line",
|
|
|
|
"--arrow-parens",
|
|
|
|
"always",
|
|
|
|
"--prose-wrap",
|
|
|
|
"preserve",
|
|
|
|
"--end-of-line",
|
|
|
|
"crlf"
|
|
|
|
],
|
2019-11-13 11:21:17 -05:00
|
|
|
allow_write: true,
|
|
|
|
allow_read: true,
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
2019-11-26 11:06:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_with_exclude() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
|
|
|
"deno",
|
|
|
|
"test",
|
|
|
|
"--exclude",
|
|
|
|
"some_dir/",
|
|
|
|
"dir1/",
|
|
|
|
"dir2/"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
DenoFlags {
|
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec![
|
|
|
|
"deno",
|
|
|
|
TEST_RUNNER_URL,
|
|
|
|
"--exclude",
|
|
|
|
"some_dir/",
|
|
|
|
"--",
|
|
|
|
"dir1/",
|
|
|
|
"dir2/"
|
|
|
|
],
|
|
|
|
allow_read: true,
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_with_allow_net() {
|
|
|
|
let r = flags_from_vec_safe(svec![
|
|
|
|
"deno",
|
|
|
|
"test",
|
|
|
|
"--allow-net",
|
|
|
|
"dir1/",
|
|
|
|
"dir2/"
|
|
|
|
]);
|
2019-11-13 11:21:17 -05:00
|
|
|
assert_eq!(
|
2019-11-26 11:06:32 -05:00
|
|
|
r.unwrap(),
|
|
|
|
DenoFlags {
|
|
|
|
subcommand: DenoSubcommand::Run,
|
|
|
|
argv: svec!["deno", TEST_RUNNER_URL, "--", "dir1/", "dir2/"],
|
|
|
|
allow_read: true,
|
|
|
|
allow_net: true,
|
|
|
|
..DenoFlags::default()
|
|
|
|
}
|
2019-11-13 11:21:17 -05:00
|
|
|
);
|
|
|
|
}
|
2019-04-08 16:22:40 -04:00
|
|
|
}
|