2021-01-11 17:13:41 +00:00
|
|
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
2020-09-06 00:34:02 +00:00
|
|
|
|
2019-06-26 10:02:13 +00:00
|
|
|
use clap::App;
|
|
|
|
use clap::AppSettings;
|
|
|
|
use clap::Arg;
|
|
|
|
use clap::ArgMatches;
|
2020-08-14 17:45:22 +00:00
|
|
|
use clap::ArgSettings;
|
2019-06-26 10:02:13 +00:00
|
|
|
use clap::SubCommand;
|
2021-01-04 23:15:52 +00:00
|
|
|
use deno_core::serde::Deserialize;
|
|
|
|
use deno_core::serde::Serialize;
|
2021-01-07 18:06:08 +00:00
|
|
|
use deno_core::url::Url;
|
2020-12-29 18:34:35 +00:00
|
|
|
use deno_runtime::permissions::PermissionsOptions;
|
2021-03-26 16:34:25 +00:00
|
|
|
use log::debug;
|
2019-06-22 16:02:51 +00:00
|
|
|
use log::Level;
|
2021-12-18 21:14:42 +00:00
|
|
|
use once_cell::sync::Lazy;
|
2020-04-03 17:40:11 +00:00
|
|
|
use std::net::SocketAddr;
|
2021-09-13 20:06:45 +00:00
|
|
|
use std::num::NonZeroU32;
|
|
|
|
use std::num::NonZeroU8;
|
2021-08-23 10:35:38 +00:00
|
|
|
use std::num::NonZeroUsize;
|
2020-05-29 15:27:43 +00:00
|
|
|
use std::path::PathBuf;
|
2020-11-12 22:17:31 +00:00
|
|
|
use std::str::FromStr;
|
2019-11-26 16:06:32 +00:00
|
|
|
|
2021-12-18 21:14:42 +00:00
|
|
|
static LONG_VERSION: Lazy<String> = Lazy::new(|| {
|
|
|
|
format!(
|
2021-03-26 16:34:25 +00:00
|
|
|
"{} ({}, {})\nv8 {}\ntypescript {}",
|
|
|
|
crate::version::deno(),
|
|
|
|
if crate::version::is_canary() {
|
|
|
|
"canary"
|
|
|
|
} else {
|
|
|
|
env!("PROFILE")
|
|
|
|
},
|
|
|
|
env!("TARGET"),
|
|
|
|
deno_core::v8_version(),
|
|
|
|
crate::version::TYPESCRIPT
|
2021-12-18 21:14:42 +00:00
|
|
|
)
|
|
|
|
});
|
2021-03-26 16:34:25 +00:00
|
|
|
|
2021-09-03 23:33:35 +00:00
|
|
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
|
|
|
pub struct BundleFlags {
|
|
|
|
pub source_file: String,
|
|
|
|
pub out_file: Option<PathBuf>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
|
|
|
pub struct CacheFlags {
|
|
|
|
pub files: Vec<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
|
|
|
pub struct CompileFlags {
|
|
|
|
pub source_file: String,
|
|
|
|
pub output: Option<PathBuf>,
|
|
|
|
pub args: Vec<String>,
|
|
|
|
pub target: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
|
|
|
pub struct CompletionsFlags {
|
|
|
|
pub buf: Box<[u8]>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
|
|
|
pub struct CoverageFlags {
|
|
|
|
pub files: Vec<PathBuf>,
|
|
|
|
pub ignore: Vec<PathBuf>,
|
|
|
|
pub include: Vec<String>,
|
|
|
|
pub exclude: Vec<String>,
|
|
|
|
pub lcov: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
|
|
|
pub struct DocFlags {
|
|
|
|
pub private: bool,
|
|
|
|
pub json: bool,
|
|
|
|
pub source_file: Option<String>,
|
|
|
|
pub filter: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
|
|
|
pub struct EvalFlags {
|
|
|
|
pub print: bool,
|
|
|
|
pub code: String,
|
|
|
|
pub ext: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
|
|
|
pub struct FmtFlags {
|
|
|
|
pub check: bool,
|
|
|
|
pub files: Vec<PathBuf>,
|
|
|
|
pub ignore: Vec<PathBuf>,
|
|
|
|
pub ext: String,
|
2021-09-13 20:06:45 +00:00
|
|
|
pub use_tabs: Option<bool>,
|
|
|
|
pub line_width: Option<NonZeroU32>,
|
|
|
|
pub indent_width: Option<NonZeroU8>,
|
|
|
|
pub single_quote: Option<bool>,
|
|
|
|
pub prose_wrap: Option<String>,
|
2021-09-03 23:33:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
|
|
|
pub struct InfoFlags {
|
|
|
|
pub json: bool,
|
|
|
|
pub file: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
|
|
|
pub struct InstallFlags {
|
|
|
|
pub module_url: String,
|
|
|
|
pub args: Vec<String>,
|
|
|
|
pub name: Option<String>,
|
|
|
|
pub root: Option<PathBuf>,
|
|
|
|
pub force: bool,
|
|
|
|
}
|
|
|
|
|
2021-09-30 15:38:07 +00:00
|
|
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
|
|
|
pub struct UninstallFlags {
|
|
|
|
pub name: String,
|
|
|
|
pub root: Option<PathBuf>,
|
|
|
|
}
|
|
|
|
|
2021-09-03 23:33:35 +00:00
|
|
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
|
|
|
pub struct LintFlags {
|
|
|
|
pub files: Vec<PathBuf>,
|
|
|
|
pub ignore: Vec<PathBuf>,
|
|
|
|
pub rules: bool,
|
2021-11-04 15:12:12 +00:00
|
|
|
pub maybe_rules_tags: Option<Vec<String>>,
|
|
|
|
pub maybe_rules_include: Option<Vec<String>>,
|
|
|
|
pub maybe_rules_exclude: Option<Vec<String>>,
|
2021-09-03 23:33:35 +00:00
|
|
|
pub json: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
|
|
|
pub struct ReplFlags {
|
|
|
|
pub eval: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
|
|
|
pub struct RunFlags {
|
|
|
|
pub script: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
|
|
|
pub struct TestFlags {
|
|
|
|
pub ignore: Vec<PathBuf>,
|
|
|
|
pub doc: bool,
|
|
|
|
pub no_run: bool,
|
|
|
|
pub fail_fast: Option<NonZeroUsize>,
|
|
|
|
pub allow_none: bool,
|
|
|
|
pub include: Option<Vec<String>>,
|
|
|
|
pub filter: Option<String>,
|
|
|
|
pub shuffle: Option<u64>,
|
|
|
|
pub concurrent_jobs: NonZeroUsize,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
|
|
|
pub struct UpgradeFlags {
|
|
|
|
pub dry_run: bool,
|
|
|
|
pub force: bool,
|
|
|
|
pub canary: bool,
|
|
|
|
pub version: Option<String>,
|
|
|
|
pub output: Option<PathBuf>,
|
|
|
|
pub ca_file: Option<String>,
|
|
|
|
}
|
|
|
|
|
2021-01-04 23:15:52 +00:00
|
|
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
2019-11-26 16:06:32 +00:00
|
|
|
pub enum DenoSubcommand {
|
2021-09-03 23:33:35 +00:00
|
|
|
Bundle(BundleFlags),
|
|
|
|
Cache(CacheFlags),
|
|
|
|
Compile(CompileFlags),
|
|
|
|
Completions(CompletionsFlags),
|
|
|
|
Coverage(CoverageFlags),
|
|
|
|
Doc(DocFlags),
|
|
|
|
Eval(EvalFlags),
|
|
|
|
Fmt(FmtFlags),
|
|
|
|
Info(InfoFlags),
|
|
|
|
Install(InstallFlags),
|
2021-09-30 15:38:07 +00:00
|
|
|
Uninstall(UninstallFlags),
|
2021-06-23 01:48:01 +00:00
|
|
|
Lsp,
|
2021-09-03 23:33:35 +00:00
|
|
|
Lint(LintFlags),
|
|
|
|
Repl(ReplFlags),
|
|
|
|
Run(RunFlags),
|
|
|
|
Test(TestFlags),
|
2019-11-26 16:06:32 +00:00
|
|
|
Types,
|
2021-09-03 23:33:35 +00:00
|
|
|
Upgrade(UpgradeFlags),
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for DenoSubcommand {
|
|
|
|
fn default() -> DenoSubcommand {
|
2021-09-03 23:33:35 +00:00
|
|
|
DenoSubcommand::Repl(ReplFlags { eval: None })
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
2018-08-17 20:34:30 +00:00
|
|
|
}
|
|
|
|
|
2021-11-29 22:23:30 +00:00
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
|
|
pub enum CheckFlag {
|
|
|
|
/// Type check all modules. The default value.
|
|
|
|
All,
|
|
|
|
/// Skip type checking of all modules. Represents `--no-check` on the command
|
|
|
|
/// line.
|
|
|
|
None,
|
|
|
|
/// Only type check local modules. Represents `--no-check=remote` on the
|
|
|
|
/// command line.
|
|
|
|
Local,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for CheckFlag {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::All
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-08 02:08:51 +00:00
|
|
|
#[derive(Clone, Debug, PartialEq, Default)]
|
2020-02-26 10:52:15 +00:00
|
|
|
pub struct Flags {
|
2019-12-03 22:23:10 +00:00
|
|
|
/// Vector of CLI arguments - these are user script arguments, all Deno
|
|
|
|
/// specific flags are removed.
|
2019-11-26 16:06:32 +00:00
|
|
|
pub argv: Vec<String>,
|
|
|
|
pub subcommand: DenoSubcommand,
|
|
|
|
|
2021-04-13 11:25:21 +00:00
|
|
|
pub allow_env: Option<Vec<String>>,
|
2019-05-23 16:28:29 +00:00
|
|
|
pub allow_hrtime: bool,
|
2020-12-29 18:34:35 +00:00
|
|
|
pub allow_net: Option<Vec<String>>,
|
2021-10-13 17:04:44 +00:00
|
|
|
pub allow_ffi: Option<Vec<PathBuf>>,
|
2020-12-29 18:34:35 +00:00
|
|
|
pub allow_read: Option<Vec<PathBuf>>,
|
2021-04-09 22:12:00 +00:00
|
|
|
pub allow_run: Option<Vec<String>>,
|
2020-12-29 18:34:35 +00:00
|
|
|
pub allow_write: Option<Vec<PathBuf>>,
|
2021-08-07 12:49:38 +00:00
|
|
|
pub ca_stores: Option<Vec<String>>,
|
2020-04-30 15:23:40 +00:00
|
|
|
pub ca_file: Option<String>,
|
2021-07-23 14:31:16 +00:00
|
|
|
pub cache_blocklist: Vec<String>,
|
2021-07-27 21:25:09 +00:00
|
|
|
/// This is not exposed as an option in the CLI, it is used internally when
|
|
|
|
/// the language server is configured with an explicit cache option.
|
|
|
|
pub cache_path: Option<PathBuf>,
|
2019-12-03 22:48:53 +00:00
|
|
|
pub cached_only: bool,
|
2021-11-29 22:23:30 +00:00
|
|
|
pub check: CheckFlag,
|
2020-04-30 15:23:40 +00:00
|
|
|
pub config_path: Option<String>,
|
2020-12-21 13:04:25 +00:00
|
|
|
pub coverage_dir: Option<String>,
|
2021-07-23 14:31:16 +00:00
|
|
|
pub enable_testing_features: bool,
|
2020-10-21 11:12:01 +00:00
|
|
|
pub ignore: Vec<PathBuf>,
|
2020-04-30 15:23:40 +00:00
|
|
|
pub import_map_path: Option<String>,
|
2020-04-03 17:40:11 +00:00
|
|
|
pub inspect_brk: Option<SocketAddr>,
|
2021-07-23 14:31:16 +00:00
|
|
|
pub inspect: Option<SocketAddr>,
|
|
|
|
pub location: Option<Url>,
|
2019-11-03 15:39:27 +00:00
|
|
|
pub lock_write: bool,
|
2021-07-23 14:31:16 +00:00
|
|
|
pub lock: Option<PathBuf>,
|
2020-04-30 15:23:40 +00:00
|
|
|
pub log_level: Option<Level>,
|
|
|
|
pub no_remote: bool,
|
2021-10-04 23:35:55 +00:00
|
|
|
/// If true, a list of Node built-in modules will be injected into
|
|
|
|
/// the import map.
|
|
|
|
pub compat: bool,
|
2021-07-23 14:31:16 +00:00
|
|
|
pub prompt: bool,
|
2020-04-30 15:23:40 +00:00
|
|
|
pub reload: bool,
|
2020-10-01 23:14:55 +00:00
|
|
|
pub repl: bool,
|
2020-04-30 15:23:40 +00:00
|
|
|
pub seed: Option<u64>,
|
|
|
|
pub unstable: bool,
|
2021-08-10 11:19:45 +00:00
|
|
|
pub unsafely_ignore_certificate_errors: Option<Vec<String>>,
|
2020-12-06 17:19:21 +00:00
|
|
|
pub v8_flags: Vec<String>,
|
2020-04-30 15:23:40 +00:00
|
|
|
pub version: bool,
|
2021-12-15 21:04:43 +00:00
|
|
|
pub watch: Option<Vec<PathBuf>>,
|
2018-11-15 17:56:17 +00:00
|
|
|
}
|
|
|
|
|
2020-06-13 17:09:39 +00:00
|
|
|
fn join_paths(allowlist: &[PathBuf], d: &str) -> String {
|
|
|
|
allowlist
|
2020-02-11 09:29:36 +00:00
|
|
|
.iter()
|
|
|
|
.map(|path| path.to_str().unwrap().to_string())
|
|
|
|
.collect::<Vec<String>>()
|
|
|
|
.join(d)
|
|
|
|
}
|
|
|
|
|
2020-02-26 10:52:15 +00:00
|
|
|
impl Flags {
|
2020-01-30 23:42:39 +00: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![];
|
|
|
|
|
2020-12-29 18:34:35 +00:00
|
|
|
match &self.allow_read {
|
|
|
|
Some(read_allowlist) if read_allowlist.is_empty() => {
|
|
|
|
args.push("--allow-read".to_string());
|
|
|
|
}
|
|
|
|
Some(read_allowlist) => {
|
|
|
|
let s = format!("--allow-read={}", join_paths(read_allowlist, ","));
|
|
|
|
args.push(s);
|
|
|
|
}
|
|
|
|
_ => {}
|
2020-01-30 23:42:39 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 18:34:35 +00:00
|
|
|
match &self.allow_write {
|
|
|
|
Some(write_allowlist) if write_allowlist.is_empty() => {
|
|
|
|
args.push("--allow-write".to_string());
|
|
|
|
}
|
|
|
|
Some(write_allowlist) => {
|
|
|
|
let s = format!("--allow-write={}", join_paths(write_allowlist, ","));
|
|
|
|
args.push(s);
|
|
|
|
}
|
|
|
|
_ => {}
|
2020-01-30 23:42:39 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 18:34:35 +00:00
|
|
|
match &self.allow_net {
|
|
|
|
Some(net_allowlist) if net_allowlist.is_empty() => {
|
|
|
|
args.push("--allow-net".to_string());
|
|
|
|
}
|
|
|
|
Some(net_allowlist) => {
|
|
|
|
let s = format!("--allow-net={}", net_allowlist.join(","));
|
|
|
|
args.push(s);
|
|
|
|
}
|
|
|
|
_ => {}
|
2020-01-30 23:42:39 +00:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:19:45 +00:00
|
|
|
match &self.unsafely_ignore_certificate_errors {
|
2021-08-09 14:53:21 +00:00
|
|
|
Some(ic_allowlist) if ic_allowlist.is_empty() => {
|
2021-08-10 12:19:42 +00:00
|
|
|
args.push("--unsafely-ignore-certificate-errors".to_string());
|
2021-08-09 14:53:21 +00:00
|
|
|
}
|
|
|
|
Some(ic_allowlist) => {
|
|
|
|
let s = format!(
|
2021-08-10 12:19:42 +00:00
|
|
|
"--unsafely-ignore-certificate-errors={}",
|
2021-08-09 14:53:21 +00:00
|
|
|
ic_allowlist.join(",")
|
|
|
|
);
|
|
|
|
args.push(s);
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
|
2021-04-13 11:25:21 +00:00
|
|
|
match &self.allow_env {
|
|
|
|
Some(env_allowlist) if env_allowlist.is_empty() => {
|
|
|
|
args.push("--allow-env".to_string());
|
|
|
|
}
|
|
|
|
Some(env_allowlist) => {
|
|
|
|
let s = format!("--allow-env={}", env_allowlist.join(","));
|
|
|
|
args.push(s);
|
|
|
|
}
|
|
|
|
_ => {}
|
2020-01-30 23:42:39 +00:00
|
|
|
}
|
|
|
|
|
2021-04-09 22:12:00 +00:00
|
|
|
match &self.allow_run {
|
|
|
|
Some(run_allowlist) if run_allowlist.is_empty() => {
|
|
|
|
args.push("--allow-run".to_string());
|
|
|
|
}
|
|
|
|
Some(run_allowlist) => {
|
|
|
|
let s = format!("--allow-run={}", run_allowlist.join(","));
|
|
|
|
args.push(s);
|
|
|
|
}
|
|
|
|
_ => {}
|
2020-01-30 23:42:39 +00:00
|
|
|
}
|
|
|
|
|
2021-08-06 21:28:10 +00:00
|
|
|
match &self.allow_ffi {
|
|
|
|
Some(ffi_allowlist) if ffi_allowlist.is_empty() => {
|
|
|
|
args.push("--allow-ffi".to_string());
|
|
|
|
}
|
|
|
|
Some(ffi_allowlist) => {
|
2021-10-13 17:04:44 +00:00
|
|
|
let s = format!("--allow-ffi={}", join_paths(ffi_allowlist, ","));
|
2021-08-06 21:28:10 +00:00
|
|
|
args.push(s);
|
|
|
|
}
|
|
|
|
_ => {}
|
2020-01-30 23:42:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if self.allow_hrtime {
|
|
|
|
args.push("--allow-hrtime".to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
args
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-29 18:34:35 +00:00
|
|
|
impl From<Flags> for PermissionsOptions {
|
|
|
|
fn from(flags: Flags) -> Self {
|
|
|
|
Self {
|
|
|
|
allow_env: flags.allow_env,
|
|
|
|
allow_hrtime: flags.allow_hrtime,
|
|
|
|
allow_net: flags.allow_net,
|
2021-08-06 21:28:10 +00:00
|
|
|
allow_ffi: flags.allow_ffi,
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_read: flags.allow_read,
|
|
|
|
allow_run: flags.allow_run,
|
|
|
|
allow_write: flags.allow_write,
|
2021-04-12 02:15:43 +00:00
|
|
|
prompt: flags.prompt,
|
2020-12-29 18:34:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-16 02:50:27 +00:00
|
|
|
static ENV_VARIABLES_HELP: &str = r#"ENVIRONMENT VARIABLES:
|
|
|
|
DENO_AUTH_TOKENS A semi-colon separated list of bearer tokens and
|
|
|
|
hostnames to use when fetching remote modules from
|
|
|
|
private repositories
|
|
|
|
(e.g. "abcde12345@deno.land;54321edcba@github.com")
|
2021-11-09 18:43:23 +00:00
|
|
|
DENO_TLS_CA_STORE Comma-separated list of order dependent certificate stores
|
2021-08-07 12:49:38 +00:00
|
|
|
(system, mozilla)
|
|
|
|
(defaults to mozilla)
|
2021-02-16 02:50:27 +00:00
|
|
|
DENO_CERT Load certificate authority from PEM encoded file
|
2020-06-15 16:29:39 +00:00
|
|
|
DENO_DIR Set the cache directory
|
2020-04-16 22:15:42 +00:00
|
|
|
DENO_INSTALL_ROOT Set deno install's output directory
|
|
|
|
(defaults to $HOME/.deno/bin)
|
2021-03-01 10:31:13 +00:00
|
|
|
DENO_WEBGPU_TRACE Directory to use for wgpu traces
|
2020-04-16 22:15:42 +00:00
|
|
|
HTTP_PROXY Proxy address for HTTP requests
|
|
|
|
(module downloads, fetch)
|
2020-06-08 16:06:06 +00:00
|
|
|
HTTPS_PROXY Proxy address for HTTPS requests
|
2020-08-15 13:48:29 +00:00
|
|
|
(module downloads, fetch)
|
2021-02-16 02:50:27 +00:00
|
|
|
NO_COLOR Set to disable color
|
2020-08-15 13:48:29 +00:00
|
|
|
NO_PROXY Comma-separated list of hosts which do not use a proxy
|
2021-02-16 02:50:27 +00:00
|
|
|
(module downloads, fetch)"#;
|
2019-06-05 17:44:46 +00:00
|
|
|
|
2021-09-16 06:25:06 +00:00
|
|
|
static DENO_HELP: &str = "A modern JavaScript and TypeScript runtime
|
2019-05-06 14:48:19 +00:00
|
|
|
|
2020-05-17 17:24:39 +00:00
|
|
|
Docs: https://deno.land/manual
|
2020-03-10 23:23:08 +00:00
|
|
|
Modules: https://deno.land/std/ https://deno.land/x/
|
2019-05-23 18:57:44 +00:00
|
|
|
Bugs: https://github.com/denoland/deno/issues
|
|
|
|
|
2020-05-04 11:03:30 +00:00
|
|
|
To start the REPL:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2019-05-23 18:57:44 +00:00
|
|
|
deno
|
|
|
|
|
2019-11-26 16:06:32 +00:00
|
|
|
To execute a script:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2020-03-10 23:23:08 +00:00
|
|
|
deno run https://deno.land/std/examples/welcome.ts
|
2019-05-23 18:57:44 +00:00
|
|
|
|
2020-03-10 23:23:08 +00:00
|
|
|
To evaluate code in the shell:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2020-03-10 23:23:08 +00:00
|
|
|
deno eval \"console.log(30933 + 404)\"
|
2020-05-04 11:03:30 +00:00
|
|
|
";
|
2019-05-23 18:57:44 +00:00
|
|
|
|
2019-11-26 16:06:32 +00:00
|
|
|
/// Main entry point for parsing deno's command line flags.
|
2021-01-07 18:06:08 +00:00
|
|
|
pub fn flags_from_vec(args: Vec<String>) -> clap::Result<Flags> {
|
2020-11-25 10:30:14 +00:00
|
|
|
let version = crate::version::deno();
|
|
|
|
let app = clap_root(&*version);
|
2021-01-07 18:06:08 +00:00
|
|
|
let matches = app.get_matches_from_safe(args).map_err(|e| clap::Error {
|
|
|
|
message: e.message.trim_start_matches("error: ").to_string(),
|
|
|
|
..e
|
|
|
|
})?;
|
2019-11-26 16:06:32 +00:00
|
|
|
|
2020-02-26 10:52:15 +00:00
|
|
|
let mut flags = Flags::default();
|
2019-11-26 16:06:32 +00:00
|
|
|
|
2020-09-20 11:45:00 +00:00
|
|
|
if matches.is_present("unstable") {
|
|
|
|
flags.unstable = true;
|
|
|
|
}
|
2019-11-26 16:06:32 +00: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 12:26:17 +00:00
|
|
|
if matches.is_present("quiet") {
|
|
|
|
flags.log_level = Some(Level::Error);
|
|
|
|
}
|
2019-11-26 16:06:32 +00: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 15:24:47 +00:00
|
|
|
} else if let Some(m) = matches.subcommand_matches("cache") {
|
|
|
|
cache_parse(&mut flags, m);
|
2021-02-24 14:27:51 +00:00
|
|
|
} else if let Some(m) = matches.subcommand_matches("coverage") {
|
|
|
|
coverage_parse(&mut flags, m);
|
2019-11-26 16:06:32 +00: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);
|
2021-09-30 15:38:07 +00:00
|
|
|
} else if let Some(m) = matches.subcommand_matches("uninstall") {
|
|
|
|
uninstall_parse(&mut flags, m);
|
2019-11-26 16:06:32 +00:00
|
|
|
} 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 15:37:24 +00:00
|
|
|
} else if let Some(m) = matches.subcommand_matches("upgrade") {
|
|
|
|
upgrade_parse(&mut flags, m);
|
2020-03-28 18:16:57 +00:00
|
|
|
} else if let Some(m) = matches.subcommand_matches("doc") {
|
|
|
|
doc_parse(&mut flags, m);
|
2020-06-08 12:06:20 +00:00
|
|
|
} else if let Some(m) = matches.subcommand_matches("lint") {
|
|
|
|
lint_parse(&mut flags, m);
|
2020-11-30 19:35:12 +00:00
|
|
|
} else if let Some(m) = matches.subcommand_matches("compile") {
|
|
|
|
compile_parse(&mut flags, m);
|
2020-12-07 10:46:39 +00:00
|
|
|
} else if let Some(m) = matches.subcommand_matches("lsp") {
|
2021-02-26 14:51:25 +00:00
|
|
|
lsp_parse(&mut flags, m);
|
2019-11-26 16:06:32 +00:00
|
|
|
} else {
|
2020-05-04 11:03:30 +00:00
|
|
|
repl_parse(&mut flags, &matches);
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(flags)
|
|
|
|
}
|
|
|
|
|
2020-11-25 10:30:14 +00:00
|
|
|
fn clap_root<'a, 'b>(version: &'b str) -> App<'a, 'b> {
|
2019-11-26 16:06:32 +00:00
|
|
|
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.
|
2020-11-25 10:30:14 +00:00
|
|
|
.version(version)
|
2019-12-15 13:38:34 +00:00
|
|
|
.long_version(LONG_VERSION.as_str())
|
2020-09-20 11:45:00 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("unstable")
|
|
|
|
.long("unstable")
|
|
|
|
.help("Enable unstable features and APIs")
|
|
|
|
.global(true),
|
|
|
|
)
|
2019-04-06 22:13:06 +00:00
|
|
|
.arg(
|
2019-06-22 16:02:51 +00: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 21:15:16 +00:00
|
|
|
.global(true),
|
2019-07-31 15:02:20 +00:00
|
|
|
)
|
2020-03-10 12:26:17 +00: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 16:06:32 +00:00
|
|
|
.subcommand(bundle_subcommand())
|
2020-06-08 12:06:20 +00:00
|
|
|
.subcommand(cache_subcommand())
|
2020-11-30 19:35:12 +00:00
|
|
|
.subcommand(compile_subcommand())
|
2019-11-26 16:06:32 +00:00
|
|
|
.subcommand(completions_subcommand())
|
2021-02-24 14:27:51 +00:00
|
|
|
.subcommand(coverage_subcommand())
|
2020-06-08 12:06:20 +00:00
|
|
|
.subcommand(doc_subcommand())
|
2019-11-26 16:06:32 +00:00
|
|
|
.subcommand(eval_subcommand())
|
|
|
|
.subcommand(fmt_subcommand())
|
|
|
|
.subcommand(info_subcommand())
|
|
|
|
.subcommand(install_subcommand())
|
2021-09-30 15:38:07 +00:00
|
|
|
.subcommand(uninstall_subcommand())
|
2021-02-26 14:51:25 +00:00
|
|
|
.subcommand(lsp_subcommand())
|
2020-06-08 12:06:20 +00:00
|
|
|
.subcommand(lint_subcommand())
|
2019-11-26 16:06:32 +00:00
|
|
|
.subcommand(repl_subcommand())
|
|
|
|
.subcommand(run_subcommand())
|
|
|
|
.subcommand(test_subcommand())
|
|
|
|
.subcommand(types_subcommand())
|
2020-03-23 15:37:24 +00:00
|
|
|
.subcommand(upgrade_subcommand())
|
2019-11-26 16:06:32 +00:00
|
|
|
.long_about(DENO_HELP)
|
|
|
|
.after_help(ENV_VARIABLES_HELP)
|
|
|
|
}
|
2019-11-13 15:35:56 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn bundle_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
compile_args(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))
|
2021-12-15 21:04:43 +00:00
|
|
|
.arg(watch_arg(false))
|
2021-04-16 13:28:41 +00:00
|
|
|
.about("Bundle module and dependencies into single file")
|
|
|
|
.long_about(
|
|
|
|
"Output a single JavaScript file with all dependencies.
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno bundle https://deno.land/std/examples/colors.ts colors.bundle.js
|
|
|
|
|
|
|
|
If no output file is given, the output is written to standard output:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno bundle https://deno.land/std/examples/colors.ts",
|
|
|
|
)
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
2019-06-11 18:38:19 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn cache_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
compile_args(SubCommand::with_name("cache"))
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("file")
|
|
|
|
.takes_value(true)
|
|
|
|
.required(true)
|
|
|
|
.min_values(1),
|
|
|
|
)
|
|
|
|
.about("Cache the dependencies")
|
|
|
|
.long_about(
|
|
|
|
"Cache and compile remote dependencies recursively.
|
2021-01-19 17:39:35 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
Download and compile a module with all of its static dependencies and save them
|
|
|
|
in the local cache, without running any code:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno cache https://deno.land/std/http/file_server.ts
|
|
|
|
|
|
|
|
Future runs of this module will trigger no downloads or compilation unless
|
|
|
|
--reload is specified.",
|
|
|
|
)
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
2019-05-01 23:15:37 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn compile_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
runtime_args(SubCommand::with_name("compile"), true, false)
|
|
|
|
.setting(AppSettings::TrailingVarArg)
|
|
|
|
.arg(
|
|
|
|
script_arg().required(true),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("output")
|
|
|
|
.long("output")
|
|
|
|
.short("o")
|
|
|
|
.help("Output file (defaults to $PWD/<inferred-name>)")
|
|
|
|
.takes_value(true)
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("target")
|
|
|
|
.long("target")
|
|
|
|
.help("Target OS architecture")
|
|
|
|
.takes_value(true)
|
|
|
|
.possible_values(&["x86_64-unknown-linux-gnu", "x86_64-pc-windows-msvc", "x86_64-apple-darwin", "aarch64-apple-darwin"])
|
|
|
|
)
|
2021-04-27 10:44:36 +00:00
|
|
|
.about("UNSTABLE: Compile the script into a self contained executable")
|
2021-04-16 13:28:41 +00:00
|
|
|
.long_about(
|
2021-04-27 10:44:36 +00:00
|
|
|
"UNSTABLE: Compiles the given script into a self contained executable.
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-27 10:44:36 +00:00
|
|
|
deno compile -A https://deno.land/std/http/file_server.ts
|
|
|
|
deno compile --output /usr/local/bin/color_util https://deno.land/std/examples/colors.ts
|
2019-11-26 16:06:32 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
Any flags passed which affect runtime behavior, such as '--unstable',
|
|
|
|
'--allow-*', '--v8-flags', etc. are encoded into the output executable and used
|
|
|
|
at runtime as if they were passed to a similar 'deno run' command.
|
2019-05-01 23:15:37 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
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.
|
|
|
|
- If the resulting name has an '@...' suffix, strip it.
|
2020-01-30 23:42:39 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
This commands supports cross-compiling to different target architectures using `--target` flag.
|
|
|
|
On the first invocation with deno will download proper binary and cache it in $DENO_DIR. The
|
|
|
|
aarch64-apple-darwin target is not supported in canary.
|
|
|
|
",
|
|
|
|
)
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
2019-05-01 23:15:37 +00:00
|
|
|
|
2021-04-16 13:28:41 +00: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.
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno completions bash > /usr/local/etc/bash_completion.d/deno.bash
|
|
|
|
source /usr/local/etc/bash_completion.d/deno.bash",
|
|
|
|
)
|
2020-11-30 19:35:12 +00:00
|
|
|
}
|
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn coverage_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
SubCommand::with_name("coverage")
|
|
|
|
.about("Print coverage reports")
|
|
|
|
.long_about(
|
|
|
|
"Print coverage reports from coverage profiles.
|
2020-02-17 16:59:51 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
Collect a coverage profile with deno test:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno test --coverage=cov_profile
|
2020-02-04 19:24:33 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
Print a report to stdout:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno coverage cov_profile
|
2020-02-04 19:24:33 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
Include urls that start with the file schema:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno coverage --include=\"^file:\" cov_profile
|
2020-11-22 20:45:44 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
Exclude urls ending with test.ts and test.js:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno coverage --exclude=\"test\\.(ts|js)\" cov_profile
|
2019-05-23 18:57:44 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
Include urls that start with the file schema and exclude files ending with test.ts and test.js, for
|
|
|
|
an url to match it must match the include pattern and not match the exclude pattern:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno coverage --include=\"^file:\" --exclude=\"test\\.(ts|js)\" cov_profile
|
2020-02-04 19:24:33 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
Write a report using the lcov format:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno coverage --lcov cov_profile > cov.lcov
|
|
|
|
|
|
|
|
Generate html reports from lcov:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
genhtml -o html_cov cov.lcov
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("ignore")
|
|
|
|
.long("ignore")
|
|
|
|
.takes_value(true)
|
|
|
|
.use_delimiter(true)
|
|
|
|
.require_equals(true)
|
|
|
|
.help("Ignore coverage files"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("include")
|
|
|
|
.long("include")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("regex")
|
|
|
|
.multiple(true)
|
|
|
|
.require_equals(true)
|
|
|
|
.default_value(r"^file:")
|
|
|
|
.help("Include source files in the report"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("exclude")
|
|
|
|
.long("exclude")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("regex")
|
|
|
|
.multiple(true)
|
|
|
|
.require_equals(true)
|
|
|
|
.default_value(r"test\.(js|mjs|ts|jsx|tsx)$")
|
|
|
|
.help("Exclude source files from the report"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("lcov")
|
|
|
|
.long("lcov")
|
|
|
|
.help("Output coverage report in lcov format")
|
|
|
|
.takes_value(false),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("files")
|
|
|
|
.takes_value(true)
|
|
|
|
.multiple(true)
|
|
|
|
.required(true),
|
|
|
|
)
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
2019-08-12 00:43:01 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn doc_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
SubCommand::with_name("doc")
|
|
|
|
.about("Show documentation for a module")
|
|
|
|
.long_about(
|
|
|
|
"Show documentation for a module.
|
2019-05-01 23:15:37 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
Output documentation to standard output:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno doc ./path/to/module.ts
|
2019-05-01 23:15:37 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
Output private documentation to standard output:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno doc --private ./path/to/module.ts
|
2019-05-01 23:15:37 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
Output documentation in JSON format:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno doc --json ./path/to/module.ts
|
2021-02-24 14:27:51 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
Target a specific symbol:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno doc ./path/to/module.ts MyClass.someField
|
2019-05-06 14:48:19 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
Show documentation for runtime built-ins:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno doc
|
|
|
|
deno doc --builtin Deno.Listener",
|
|
|
|
)
|
2020-10-20 12:30:59 +00:00
|
|
|
.arg(import_map_arg())
|
2020-09-18 17:09:11 +00:00
|
|
|
.arg(reload_arg())
|
2021-04-16 13:28:41 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("json")
|
|
|
|
.long("json")
|
|
|
|
.help("Output documentation in JSON format")
|
|
|
|
.takes_value(false),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("private")
|
|
|
|
.long("private")
|
|
|
|
.help("Output private documentation")
|
|
|
|
.takes_value(false),
|
|
|
|
)
|
|
|
|
// 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))
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("filter")
|
|
|
|
.help("Dot separated path to symbol")
|
|
|
|
.takes_value(true)
|
|
|
|
.required(false)
|
|
|
|
.conflicts_with("json")
|
|
|
|
.conflicts_with("pretty"),
|
|
|
|
)
|
2020-09-18 17:09:11 +00:00
|
|
|
}
|
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn eval_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
runtime_args(SubCommand::with_name("eval"), false, true)
|
|
|
|
.about("Eval script")
|
|
|
|
.long_about(
|
|
|
|
"Evaluate JavaScript from the command line.
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno eval \"console.log('hello world')\"
|
2019-11-26 16:06:32 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
To evaluate as TypeScript:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno eval --ext=ts \"const v: string = 'hello'; console.log(v)\"
|
2019-11-26 16:06:32 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
This command has implicit access to all permissions (--allow-all).",
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
// TODO(@satyarohith): remove this argument in 2.0.
|
|
|
|
Arg::with_name("ts")
|
|
|
|
.long("ts")
|
|
|
|
.short("T")
|
|
|
|
.help("Treat eval input as TypeScript")
|
|
|
|
.takes_value(false)
|
|
|
|
.multiple(false)
|
|
|
|
.hidden(true),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("ext")
|
|
|
|
.long("ext")
|
|
|
|
.help("Set standard input (stdin) content type")
|
|
|
|
.takes_value(true)
|
|
|
|
.default_value("js")
|
|
|
|
.possible_values(&["ts", "tsx", "js", "jsx"]),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("print")
|
|
|
|
.long("print")
|
|
|
|
.short("p")
|
|
|
|
.help("print result to stdout")
|
|
|
|
.takes_value(false)
|
|
|
|
.multiple(false),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("code_arg")
|
|
|
|
.multiple(true)
|
|
|
|
.help("Code arg")
|
|
|
|
.value_name("CODE_ARG")
|
|
|
|
.required(true),
|
|
|
|
)
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn fmt_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
SubCommand::with_name("fmt")
|
|
|
|
.about("Format source files")
|
|
|
|
.long_about(
|
|
|
|
"Auto-format JavaScript, TypeScript, Markdown, and JSON files.
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno fmt
|
|
|
|
deno fmt myfile1.ts myfile2.ts
|
|
|
|
deno fmt --check
|
2020-02-09 10:19:05 +00:00
|
|
|
|
2020-03-10 23:23:08 +00:00
|
|
|
Format stdin and write to stdout:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2020-05-04 19:17:15 +00:00
|
|
|
cat file.ts | deno fmt -
|
|
|
|
|
|
|
|
Ignore formatting code by preceding it with an ignore comment:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2020-05-04 19:17:15 +00:00
|
|
|
// deno-fmt-ignore
|
|
|
|
|
|
|
|
Ignore formatting a file by adding an ignore comment at the top of the file:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2020-05-04 19:17:15 +00:00
|
|
|
// deno-fmt-ignore-file",
|
2020-01-30 02:16:48 +00:00
|
|
|
)
|
2021-09-13 18:19:10 +00:00
|
|
|
.arg(config_arg())
|
2020-01-30 02:16:48 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("check")
|
|
|
|
.long("check")
|
2020-09-20 11:45:00 +00:00
|
|
|
.help("Check if the source files are formatted")
|
2020-01-30 02:16:48 +00:00
|
|
|
.takes_value(false),
|
|
|
|
)
|
2021-01-19 17:39:35 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("ext")
|
|
|
|
.long("ext")
|
|
|
|
.help("Set standard input (stdin) content type")
|
|
|
|
.takes_value(true)
|
|
|
|
.default_value("ts")
|
2021-02-18 16:31:32 +00:00
|
|
|
.possible_values(&["ts", "tsx", "js", "jsx", "md", "json", "jsonc"]),
|
2021-01-19 17:39:35 +00:00
|
|
|
)
|
2020-07-30 16:09:08 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("ignore")
|
|
|
|
.long("ignore")
|
|
|
|
.takes_value(true)
|
|
|
|
.use_delimiter(true)
|
|
|
|
.require_equals(true)
|
2021-04-27 10:44:36 +00:00
|
|
|
.help("Ignore formatting particular source files"),
|
2020-07-30 16:09:08 +00:00
|
|
|
)
|
2020-01-30 02:16:48 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("files")
|
|
|
|
.takes_value(true)
|
|
|
|
.multiple(true)
|
|
|
|
.required(false),
|
|
|
|
)
|
2021-12-15 21:04:43 +00:00
|
|
|
.arg(watch_arg(false))
|
2021-09-13 20:06:45 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("options-use-tabs")
|
|
|
|
.long("options-use-tabs")
|
|
|
|
.help("Use tabs instead of spaces for indentation. Defaults to false."),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("options-line-width")
|
|
|
|
.long("options-line-width")
|
|
|
|
.help("Define maximum line width. Defaults to 80.")
|
|
|
|
.takes_value(true)
|
|
|
|
.validator(|val: String| match val.parse::<NonZeroUsize>() {
|
|
|
|
Ok(_) => Ok(()),
|
|
|
|
Err(_) => {
|
|
|
|
Err("options-line-width should be a non zero integer".to_string())
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("options-indent-width")
|
|
|
|
.long("options-indent-width")
|
|
|
|
.help("Define indentation width. Defaults to 2.")
|
|
|
|
.takes_value(true)
|
|
|
|
.validator(|val: String| match val.parse::<NonZeroUsize>() {
|
|
|
|
Ok(_) => Ok(()),
|
|
|
|
Err(_) => {
|
|
|
|
Err("options-indent-width should be a non zero integer".to_string())
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("options-single-quote")
|
|
|
|
.long("options-single-quote")
|
|
|
|
.help("Use single quotes. Defaults to false."),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("options-prose-wrap")
|
|
|
|
.long("options-prose-wrap")
|
|
|
|
.takes_value(true)
|
|
|
|
.possible_values(&["always", "never", "preserve"])
|
|
|
|
.help("Define how prose should be wrapped. Defaults to always."),
|
|
|
|
)
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
2019-08-15 14:11:52 +00:00
|
|
|
|
2021-04-16 13:28:41 +00: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 a module or the cache directories.
|
|
|
|
|
|
|
|
Get information about a module:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno info https://deno.land/std/http/file_server.ts
|
|
|
|
|
|
|
|
The following information is shown:
|
|
|
|
|
|
|
|
local: Local path of the file.
|
|
|
|
type: JavaScript, TypeScript, or JSON.
|
2021-09-13 11:50:04 +00:00
|
|
|
emit: Local path of compiled source code. (TypeScript only.)
|
|
|
|
dependencies: Dependency tree of the source file.
|
2021-04-16 13:28:41 +00:00
|
|
|
|
|
|
|
Without any additional arguments, 'deno info' shows:
|
|
|
|
|
|
|
|
DENO_DIR: Directory containing Deno-managed files.
|
|
|
|
Remote modules cache: Subdirectory containing downloaded remote modules.
|
|
|
|
TypeScript compiler cache: Subdirectory containing TS compiler output.",
|
|
|
|
)
|
|
|
|
.arg(Arg::with_name("file").takes_value(true).required(false))
|
|
|
|
.arg(reload_arg().requires("file"))
|
|
|
|
.arg(ca_file_arg())
|
2021-05-27 05:23:12 +00:00
|
|
|
.arg(
|
|
|
|
location_arg()
|
|
|
|
.conflicts_with("file")
|
|
|
|
.help("Show files used for origin bound APIs like the Web Storage API when running a script with '--location=<HREF>'")
|
|
|
|
)
|
2021-04-16 13:28:41 +00:00
|
|
|
// TODO(lucacasonato): remove for 2.0
|
|
|
|
.arg(no_check_arg().hidden(true))
|
|
|
|
.arg(import_map_arg())
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("json")
|
|
|
|
.long("json")
|
2021-04-27 10:44:36 +00:00
|
|
|
.help("UNSTABLE: Outputs the information in JSON format")
|
2021-04-16 13:28:41 +00:00
|
|
|
.takes_value(false),
|
|
|
|
)
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
2019-08-15 14:11:52 +00:00
|
|
|
|
2019-11-26 16:06:32 +00:00
|
|
|
fn install_subcommand<'a, 'b>() -> App<'a, 'b> {
|
2021-01-04 23:15:52 +00:00
|
|
|
runtime_args(SubCommand::with_name("install"), true, true)
|
2021-04-16 13:28:41 +00:00
|
|
|
.setting(AppSettings::TrailingVarArg)
|
|
|
|
.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))
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("root")
|
|
|
|
.long("root")
|
|
|
|
.help("Installation root")
|
|
|
|
.takes_value(true)
|
|
|
|
.multiple(false))
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("force")
|
|
|
|
.long("force")
|
|
|
|
.short("f")
|
|
|
|
.help("Forcefully overwrite existing installation")
|
|
|
|
.takes_value(false))
|
|
|
|
.about("Install script as an executable")
|
|
|
|
.long_about(
|
|
|
|
"Installs a script as an executable in the installation root's bin directory.
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2020-05-01 19:33:11 +00: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:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2020-05-01 19:33:11 +00:00
|
|
|
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.
|
2020-08-27 20:55:58 +00:00
|
|
|
- If the resulting name has an '@...' suffix, strip it.
|
2019-05-03 21:15:16 +00:00
|
|
|
|
2020-04-16 22:15:42 +00:00
|
|
|
To change the installation root, use --root:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2020-05-01 19:33:11 +00:00
|
|
|
deno install --allow-net --allow-read --root /usr/local https://deno.land/std/http/file_server.ts
|
2020-04-16 22:15:42 +00: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 16:06:32 +00:00
|
|
|
}
|
2019-05-03 21:15:16 +00:00
|
|
|
|
2021-09-30 15:38:07 +00:00
|
|
|
fn uninstall_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
SubCommand::with_name("uninstall")
|
|
|
|
.setting(AppSettings::TrailingVarArg)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("name")
|
|
|
|
.required(true)
|
|
|
|
.multiple(false)
|
|
|
|
.allow_hyphen_values(true))
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("root")
|
|
|
|
.long("root")
|
|
|
|
.help("Installation root")
|
|
|
|
.takes_value(true)
|
|
|
|
.multiple(false))
|
|
|
|
.about("Uninstall a script previously installed with deno install")
|
|
|
|
.long_about(
|
|
|
|
"Uninstalls an executable script in the installation root's bin directory.
|
|
|
|
|
|
|
|
deno uninstall serve
|
|
|
|
|
|
|
|
To change the installation root, use --root:
|
|
|
|
|
|
|
|
deno uninstall --root /usr/local serve
|
|
|
|
|
|
|
|
The installation root is determined, in order of precedence:
|
|
|
|
- --root option
|
|
|
|
- DENO_INSTALL_ROOT environment variable
|
|
|
|
- $HOME/.deno")
|
|
|
|
}
|
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn lsp_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
SubCommand::with_name("lsp")
|
|
|
|
.about("Start the language server")
|
|
|
|
.long_about(
|
|
|
|
"The 'deno lsp' subcommand provides a way for code editors and IDEs to
|
|
|
|
interact with Deno using the Language Server Protocol. Usually humans do not
|
|
|
|
use this subcommand directly. For example, 'deno lsp' can provide IDEs with
|
|
|
|
go-to-definition support and automatic code formatting.
|
|
|
|
|
|
|
|
How to connect various editors and IDEs to 'deno lsp':
|
|
|
|
https://deno.land/manual/getting_started/setup_your_environment#editors-and-ides")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn lint_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
SubCommand::with_name("lint")
|
2021-06-05 13:57:31 +00:00
|
|
|
.about("Lint source files")
|
2021-04-16 13:28:41 +00:00
|
|
|
.long_about(
|
2021-06-05 13:57:31 +00:00
|
|
|
"Lint JavaScript/TypeScript source code.
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-27 10:44:36 +00:00
|
|
|
deno lint
|
|
|
|
deno lint myfile1.ts myfile2.js
|
2021-04-16 13:28:41 +00:00
|
|
|
|
|
|
|
Print result as JSON:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-27 10:44:36 +00:00
|
|
|
deno lint --json
|
2021-04-16 13:28:41 +00:00
|
|
|
|
|
|
|
Read from stdin:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-27 10:44:36 +00:00
|
|
|
cat file.ts | deno lint -
|
|
|
|
cat file.ts | deno lint --json -
|
2021-04-16 13:28:41 +00:00
|
|
|
|
|
|
|
List available rules:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-27 10:44:36 +00:00
|
|
|
deno lint --rules
|
2021-04-16 13:28:41 +00:00
|
|
|
|
|
|
|
Ignore diagnostics on the next line by preceding it with an ignore comment and
|
|
|
|
rule name:
|
|
|
|
|
2021-04-18 13:12:55 +00:00
|
|
|
// deno-lint-ignore no-explicit-any
|
2021-04-16 13:28:41 +00:00
|
|
|
// deno-lint-ignore require-await no-empty
|
|
|
|
|
|
|
|
Names of rules to ignore must be specified after ignore comment.
|
|
|
|
|
|
|
|
Ignore linting a file by adding an ignore comment at the top of the file:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
// deno-lint-ignore-file
|
|
|
|
",
|
2020-11-30 19:35:12 +00:00
|
|
|
)
|
2020-12-01 14:11:02 +00:00
|
|
|
.arg(
|
2021-04-16 13:28:41 +00:00
|
|
|
Arg::with_name("rules")
|
|
|
|
.long("rules")
|
|
|
|
.help("List available rules"),
|
2020-12-01 14:11:02 +00:00
|
|
|
)
|
2021-09-03 15:01:58 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("rules-tags")
|
|
|
|
.long("rules-tags")
|
|
|
|
.require_equals(true)
|
|
|
|
.takes_value(true)
|
|
|
|
.use_delimiter(true)
|
|
|
|
.empty_values(true)
|
|
|
|
.conflicts_with("rules")
|
|
|
|
.help("Use set of rules with a tag"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("rules-include")
|
|
|
|
.long("rules-include")
|
|
|
|
.require_equals(true)
|
|
|
|
.takes_value(true)
|
|
|
|
.use_delimiter(true)
|
|
|
|
.conflicts_with("rules")
|
|
|
|
.help("Include lint rules"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("rules-exclude")
|
|
|
|
.long("rules-exclude")
|
|
|
|
.require_equals(true)
|
|
|
|
.takes_value(true)
|
|
|
|
.use_delimiter(true)
|
|
|
|
.conflicts_with("rules")
|
|
|
|
.help("Exclude lint rules"),
|
|
|
|
)
|
|
|
|
.arg(config_arg())
|
2021-01-19 02:40:22 +00:00
|
|
|
.arg(
|
2021-04-16 13:28:41 +00:00
|
|
|
Arg::with_name("ignore")
|
|
|
|
.long("ignore")
|
2021-01-19 02:40:22 +00:00
|
|
|
.takes_value(true)
|
2021-04-16 13:28:41 +00:00
|
|
|
.use_delimiter(true)
|
|
|
|
.require_equals(true)
|
|
|
|
.help("Ignore linting particular source files"),
|
2021-01-19 02:40:22 +00:00
|
|
|
)
|
|
|
|
.arg(
|
2021-04-16 13:28:41 +00:00
|
|
|
Arg::with_name("json")
|
|
|
|
.long("json")
|
|
|
|
.help("Output lint result in JSON format")
|
|
|
|
.takes_value(false),
|
2021-01-19 02:40:22 +00:00
|
|
|
)
|
2019-11-26 16:06:32 +00:00
|
|
|
.arg(
|
2021-04-16 13:28:41 +00:00
|
|
|
Arg::with_name("files")
|
2019-11-26 16:06:32 +00:00
|
|
|
.takes_value(true)
|
2021-04-16 13:28:41 +00:00
|
|
|
.multiple(true)
|
|
|
|
.required(false),
|
2019-11-26 16:06:32 +00:00
|
|
|
)
|
2021-12-15 21:04:43 +00:00
|
|
|
.arg(watch_arg(false))
|
2021-04-16 13:28:41 +00:00
|
|
|
}
|
2019-05-16 14:39:19 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn repl_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
runtime_args(SubCommand::with_name("repl"), false, true)
|
|
|
|
.about("Read Eval Print Loop")
|
2021-08-06 21:30:28 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("eval")
|
|
|
|
.long("eval")
|
|
|
|
.help("Evaluates the provided code when the REPL starts.")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("code"),
|
|
|
|
)
|
2021-12-10 14:47:55 +00:00
|
|
|
.arg(unsafely_ignore_ceritifcate_errors_arg())
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn run_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
runtime_args(SubCommand::with_name("run"), true, true)
|
2019-11-26 16:06:32 +00:00
|
|
|
.arg(
|
2021-12-15 21:04:43 +00:00
|
|
|
watch_arg(true)
|
2021-04-16 13:28:41 +00:00
|
|
|
.conflicts_with("inspect")
|
2021-04-18 13:12:55 +00:00
|
|
|
.conflicts_with("inspect-brk"),
|
2019-11-26 16:06:32 +00:00
|
|
|
)
|
2021-04-16 13:28:41 +00:00
|
|
|
.setting(AppSettings::TrailingVarArg)
|
2021-04-18 13:12:55 +00:00
|
|
|
.arg(script_arg().required(true))
|
|
|
|
.about("Run a JavaScript or TypeScript program")
|
2019-11-26 16:06:32 +00:00
|
|
|
.long_about(
|
2021-04-18 13:12:55 +00:00
|
|
|
"Run a JavaScript or TypeScript program
|
2020-02-28 14:17:56 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
By default all programs are run in sandbox without access to disk, network or
|
|
|
|
ability to spawn subprocesses.
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno run https://deno.land/std/examples/welcome.ts
|
2020-03-10 23:23:08 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
Grant all permissions:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno run -A https://deno.land/std/http/file_server.ts
|
|
|
|
|
|
|
|
Grant permission to read from disk and listen to network:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno run --allow-read --allow-net https://deno.land/std/http/file_server.ts
|
|
|
|
|
|
|
|
Grant permission to read allow-listed files from disk:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno run --allow-read=/etc https://deno.land/std/http/file_server.ts
|
|
|
|
|
|
|
|
Deno allows specifying the filename '-' to read the file from stdin.
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-07-02 08:43:53 +00:00
|
|
|
curl https://deno.land/std/examples/welcome.ts | deno run -",
|
2020-02-28 14:17:56 +00:00
|
|
|
)
|
2021-04-16 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
runtime_args(SubCommand::with_name("test"), true, true)
|
|
|
|
.setting(AppSettings::TrailingVarArg)
|
2021-08-24 15:23:29 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("ignore")
|
|
|
|
.long("ignore")
|
|
|
|
.takes_value(true)
|
|
|
|
.use_delimiter(true)
|
|
|
|
.require_equals(true)
|
|
|
|
.help("Ignore files"),
|
|
|
|
)
|
2020-02-28 14:17:56 +00:00
|
|
|
.arg(
|
2021-04-16 13:28:41 +00:00
|
|
|
Arg::with_name("no-run")
|
|
|
|
.long("no-run")
|
|
|
|
.help("Cache test modules, but don't run tests")
|
2021-04-27 10:44:36 +00:00
|
|
|
.takes_value(false),
|
2021-02-21 16:58:32 +00:00
|
|
|
)
|
2021-05-10 23:54:39 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("doc")
|
|
|
|
.long("doc")
|
|
|
|
.help("UNSTABLE: type check code blocks")
|
|
|
|
.takes_value(false),
|
|
|
|
)
|
2021-02-21 16:58:32 +00:00
|
|
|
.arg(
|
2021-04-16 13:28:41 +00:00
|
|
|
Arg::with_name("fail-fast")
|
|
|
|
.long("fail-fast")
|
|
|
|
.alias("failfast")
|
2021-07-12 10:55:42 +00:00
|
|
|
.help("Stop after N errors. Defaults to stopping after first failure.")
|
|
|
|
.min_values(0)
|
|
|
|
.required(false)
|
|
|
|
.takes_value(true)
|
|
|
|
.require_equals(true)
|
|
|
|
.value_name("N")
|
2021-08-23 10:37:02 +00:00
|
|
|
.validator(|val: String| match val.parse::<NonZeroUsize>() {
|
|
|
|
Ok(_) => Ok(()),
|
|
|
|
Err(_) => Err("fail-fast should be a non zero integer".to_string()),
|
2021-07-12 10:55:42 +00:00
|
|
|
}),
|
2019-04-17 13:25:51 +00:00
|
|
|
)
|
2020-05-21 14:35:36 +00:00
|
|
|
.arg(
|
2021-04-16 13:28:41 +00:00
|
|
|
Arg::with_name("allow-none")
|
|
|
|
.long("allow-none")
|
|
|
|
.help("Don't return error code if no test files are found")
|
|
|
|
.takes_value(false),
|
2020-05-21 14:35:36 +00:00
|
|
|
)
|
2020-11-30 02:10:21 +00:00
|
|
|
.arg(
|
2021-04-16 13:28:41 +00:00
|
|
|
Arg::with_name("filter")
|
|
|
|
.set(ArgSettings::AllowLeadingHyphen)
|
|
|
|
.long("filter")
|
|
|
|
.takes_value(true)
|
|
|
|
.help("Run tests with this string or pattern in the test name"),
|
2019-11-26 16:06:32 +00:00
|
|
|
)
|
2021-07-06 01:20:33 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("shuffle")
|
|
|
|
.long("shuffle")
|
|
|
|
.value_name("NUMBER")
|
|
|
|
.help("(UNSTABLE): Shuffle the order in which the tests are run")
|
|
|
|
.min_values(0)
|
|
|
|
.max_values(1)
|
|
|
|
.require_equals(true)
|
|
|
|
.takes_value(true)
|
|
|
|
.validator(|val: String| match val.parse::<u64>() {
|
|
|
|
Ok(_) => Ok(()),
|
|
|
|
Err(_) => Err("Shuffle seed should be a number".to_string()),
|
|
|
|
}),
|
|
|
|
)
|
2020-07-08 14:50:12 +00:00
|
|
|
.arg(
|
2021-04-16 13:28:41 +00:00
|
|
|
Arg::with_name("coverage")
|
|
|
|
.long("coverage")
|
|
|
|
.require_equals(true)
|
|
|
|
.takes_value(true)
|
2021-08-12 08:21:38 +00:00
|
|
|
.value_name("DIR")
|
2021-04-16 13:28:41 +00:00
|
|
|
.conflicts_with("inspect")
|
|
|
|
.conflicts_with("inspect-brk")
|
2021-08-12 08:21:38 +00:00
|
|
|
.help("UNSTABLE: Collect coverage profile data into DIR"),
|
2020-07-08 14:50:12 +00:00
|
|
|
)
|
2021-04-28 18:17:04 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("jobs")
|
|
|
|
.short("j")
|
|
|
|
.long("jobs")
|
2021-07-17 22:27:37 +00:00
|
|
|
.help("Number of parallel workers, defaults to # of CPUs when no value is provided. Defaults to 1 when the option is not present.")
|
2021-04-28 18:17:04 +00:00
|
|
|
.min_values(0)
|
|
|
|
.max_values(1)
|
|
|
|
.takes_value(true)
|
2021-08-23 10:35:38 +00:00
|
|
|
.validator(|val: String| match val.parse::<NonZeroUsize>() {
|
2021-04-28 18:17:04 +00:00
|
|
|
Ok(_) => Ok(()),
|
2021-08-23 10:35:38 +00:00
|
|
|
Err(_) => Err("jobs should be a non zero unsigned integer".to_string()),
|
2021-04-28 18:17:04 +00:00
|
|
|
}),
|
|
|
|
)
|
2020-01-31 21:07:37 +00:00
|
|
|
.arg(
|
2021-04-16 13:28:41 +00:00
|
|
|
Arg::with_name("files")
|
|
|
|
.help("List of file names to run")
|
2020-01-31 21:07:37 +00:00
|
|
|
.takes_value(true)
|
2021-04-16 13:28:41 +00:00
|
|
|
.multiple(true),
|
2020-01-31 21:07:37 +00:00
|
|
|
)
|
2021-05-10 06:06:13 +00:00
|
|
|
.arg(
|
2021-12-15 21:04:43 +00:00
|
|
|
watch_arg(false)
|
2021-05-10 06:06:13 +00:00
|
|
|
.conflicts_with("no-run")
|
|
|
|
.conflicts_with("coverage"),
|
|
|
|
)
|
2021-04-16 13:28:41 +00:00
|
|
|
.arg(script_arg().last(true))
|
|
|
|
.about("Run tests")
|
2019-11-26 16:06:32 +00:00
|
|
|
.long_about(
|
2021-04-16 13:28:41 +00:00
|
|
|
"Run tests using Deno's built-in test runner.
|
2019-04-06 22:13:06 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
Evaluate the given modules, run all tests declared with 'Deno.test()' and
|
|
|
|
report results to standard output:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno test src/fetch_test.ts src/signal_test.ts
|
2019-04-06 22:13:06 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
Directory arguments are expanded to all contained files matching the glob
|
|
|
|
{*_,*.,}test.{js,mjs,ts,jsx,tsx}:
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno test src/",
|
2019-11-26 16:06:32 +00:00
|
|
|
)
|
2019-06-05 17:44:46 +00:00
|
|
|
}
|
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn types_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
SubCommand::with_name("types")
|
|
|
|
.about("Print runtime TypeScript declarations")
|
2021-02-24 14:27:51 +00:00
|
|
|
.long_about(
|
2021-04-16 13:28:41 +00:00
|
|
|
"Print runtime TypeScript declarations.
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno types > lib.deno.d.ts
|
2021-02-24 14:27:51 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
The declaration file could be saved and used for typing information.",
|
|
|
|
)
|
|
|
|
}
|
2021-02-24 14:27:51 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn upgrade_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
SubCommand::with_name("upgrade")
|
|
|
|
.about("Upgrade deno executable to given version")
|
|
|
|
.long_about(
|
|
|
|
"Upgrade deno executable to the given version.
|
|
|
|
Defaults to latest.
|
2021-02-24 14:27:51 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
The version is downloaded from
|
|
|
|
https://github.com/denoland/deno/releases
|
|
|
|
and is used to replace the current executable.
|
2021-02-24 14:27:51 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
If you want to not replace the current Deno executable but instead download an
|
|
|
|
update to a different location, use the --output flag
|
2021-04-18 13:12:55 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
deno upgrade --output $HOME/my_deno",
|
2020-03-23 15:37:24 +00:00
|
|
|
)
|
2020-05-09 10:31:15 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("version")
|
|
|
|
.long("version")
|
|
|
|
.help("The version to upgrade to")
|
|
|
|
.takes_value(true),
|
|
|
|
)
|
2020-07-06 22:21:26 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("output")
|
|
|
|
.long("output")
|
|
|
|
.help("The path to output the updated version to")
|
|
|
|
.takes_value(true),
|
|
|
|
)
|
2020-03-23 15:37:24 +00: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-11-29 19:00:35 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("canary")
|
|
|
|
.long("canary")
|
|
|
|
.help("Upgrade to canary builds"),
|
|
|
|
)
|
2020-07-06 03:58:23 +00:00
|
|
|
.arg(ca_file_arg())
|
2020-03-23 15:37:24 +00:00
|
|
|
}
|
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn compile_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
|
|
|
|
app
|
2020-10-20 12:30:59 +00:00
|
|
|
.arg(import_map_arg())
|
2021-04-16 13:28:41 +00:00
|
|
|
.arg(no_remote_arg())
|
|
|
|
.arg(config_arg())
|
|
|
|
.arg(no_check_arg())
|
2020-03-28 18:16:57 +00:00
|
|
|
.arg(reload_arg())
|
2021-04-16 13:28:41 +00:00
|
|
|
.arg(lock_arg())
|
|
|
|
.arg(lock_write_arg())
|
|
|
|
.arg(ca_file_arg())
|
2020-06-08 12:06:20 +00:00
|
|
|
}
|
|
|
|
|
2020-01-30 23:42:39 +00:00
|
|
|
fn permission_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
|
2019-11-26 16:06:32 +00: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)
|
2020-06-26 12:09:02 +00:00
|
|
|
.help("Allow network access")
|
|
|
|
.validator(crate::flags_allow_net::validator),
|
2019-11-26 16:06:32 +00:00
|
|
|
)
|
2021-12-10 14:47:55 +00:00
|
|
|
.arg(unsafely_ignore_ceritifcate_errors_arg())
|
2019-11-26 16:06:32 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("allow-env")
|
|
|
|
.long("allow-env")
|
2021-04-13 11:25:21 +00:00
|
|
|
.min_values(0)
|
|
|
|
.takes_value(true)
|
|
|
|
.use_delimiter(true)
|
|
|
|
.require_equals(true)
|
|
|
|
.help("Allow environment access")
|
|
|
|
.validator(|keys| {
|
|
|
|
for key in keys.split(',') {
|
|
|
|
if key.is_empty() || key.contains(&['=', '\0'] as &[char]) {
|
|
|
|
return Err(format!("invalid key \"{}\"", key));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}),
|
2019-11-26 16:06:32 +00:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("allow-run")
|
|
|
|
.long("allow-run")
|
2021-04-09 22:12:00 +00:00
|
|
|
.min_values(0)
|
|
|
|
.takes_value(true)
|
|
|
|
.use_delimiter(true)
|
|
|
|
.require_equals(true)
|
2019-11-26 16:06:32 +00:00
|
|
|
.help("Allow running subprocesses"),
|
|
|
|
)
|
2019-12-05 20:30:20 +00:00
|
|
|
.arg(
|
2021-08-06 21:28:10 +00:00
|
|
|
Arg::with_name("allow-ffi")
|
|
|
|
.long("allow-ffi")
|
|
|
|
.min_values(0)
|
|
|
|
.takes_value(true)
|
|
|
|
.use_delimiter(true)
|
|
|
|
.require_equals(true)
|
|
|
|
.help("Allow loading dynamic libraries"),
|
2019-12-05 20:30:20 +00:00
|
|
|
)
|
2019-11-26 16:06:32 +00: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"),
|
|
|
|
)
|
2021-04-12 02:15:43 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("prompt")
|
|
|
|
.long("prompt")
|
|
|
|
.help("Fallback to prompt if required permission wasn't passed"),
|
|
|
|
)
|
2020-01-30 23:42:39 +00:00
|
|
|
}
|
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn runtime_args<'a, 'b>(
|
|
|
|
app: App<'a, 'b>,
|
|
|
|
include_perms: bool,
|
|
|
|
include_inspector: bool,
|
|
|
|
) -> App<'a, 'b> {
|
|
|
|
let app = compile_args(app);
|
|
|
|
let app = if include_perms {
|
|
|
|
permission_args(app)
|
|
|
|
} else {
|
|
|
|
app
|
|
|
|
};
|
|
|
|
let app = if include_inspector {
|
|
|
|
inspect_args(app)
|
|
|
|
} else {
|
|
|
|
app
|
|
|
|
};
|
|
|
|
app
|
|
|
|
.arg(cached_only_arg())
|
|
|
|
.arg(location_arg())
|
|
|
|
.arg(v8_flags_arg())
|
|
|
|
.arg(seed_arg())
|
2021-07-23 14:31:16 +00:00
|
|
|
.arg(enable_testing_features_arg())
|
2021-10-04 23:35:55 +00:00
|
|
|
.arg(compat_arg())
|
2021-04-16 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn inspect_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
|
|
|
|
app
|
2020-12-11 12:18:30 +00:00
|
|
|
.arg(
|
2021-04-16 13:28:41 +00:00
|
|
|
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)
|
|
|
|
.takes_value(true)
|
|
|
|
.validator(inspect_arg_validate),
|
2020-12-11 12:18:30 +00:00
|
|
|
)
|
2020-10-26 00:25:43 +00:00
|
|
|
.arg(
|
2021-04-16 13:28:41 +00:00
|
|
|
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)
|
|
|
|
.takes_value(true)
|
|
|
|
.validator(inspect_arg_validate),
|
2019-11-26 16:06:32 +00:00
|
|
|
)
|
2019-04-29 23:43:06 +00:00
|
|
|
}
|
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn import_map_arg<'a, 'b>() -> Arg<'a, 'b> {
|
|
|
|
Arg::with_name("import-map")
|
|
|
|
.long("import-map")
|
|
|
|
.alias("importmap")
|
|
|
|
.value_name("FILE")
|
|
|
|
.help("Load import map file")
|
|
|
|
.long_help(
|
|
|
|
"Load import map file from local file or remote URL.
|
|
|
|
Docs: https://deno.land/manual/linking_to_external_code/import_maps
|
|
|
|
Specification: https://wicg.github.io/import-maps/
|
|
|
|
Examples: https://github.com/WICG/import-maps#the-import-map",
|
2020-04-02 13:26:40 +00:00
|
|
|
)
|
2021-04-16 13:28:41 +00:00
|
|
|
.takes_value(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
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_BLOCKLIST")
|
|
|
|
.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",
|
2020-09-13 13:01:30 +00:00
|
|
|
)
|
2021-04-16 13:28:41 +00: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)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn cached_only_arg<'a, 'b>() -> Arg<'a, 'b> {
|
|
|
|
Arg::with_name("cached-only")
|
|
|
|
.long("cached-only")
|
|
|
|
.help("Require that remote dependencies are already cached")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn location_arg<'a, 'b>() -> Arg<'a, 'b> {
|
|
|
|
Arg::with_name("location")
|
|
|
|
.long("location")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("HREF")
|
|
|
|
.validator(|href| {
|
|
|
|
let url = Url::parse(&href);
|
|
|
|
if url.is_err() {
|
|
|
|
return Err("Failed to parse URL".to_string());
|
|
|
|
}
|
|
|
|
let mut url = url.unwrap();
|
|
|
|
if !["http", "https"].contains(&url.scheme()) {
|
|
|
|
return Err("Expected protocol \"http\" or \"https\"".to_string());
|
|
|
|
}
|
|
|
|
url.set_username("").unwrap();
|
|
|
|
url.set_password(None).unwrap();
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
.help("Value of 'globalThis.location' used by some web APIs")
|
|
|
|
}
|
|
|
|
|
2021-07-23 14:31:16 +00:00
|
|
|
fn enable_testing_features_arg<'a, 'b>() -> Arg<'a, 'b> {
|
|
|
|
Arg::with_name("enable-testing-features-do-not-use")
|
|
|
|
.long("enable-testing-features-do-not-use")
|
|
|
|
.help("INTERNAL: Enable internal features used during integration testing")
|
|
|
|
.hidden(true)
|
|
|
|
}
|
|
|
|
|
2021-04-16 13:28:41 +00: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 seed_arg<'a, 'b>() -> Arg<'a, 'b> {
|
|
|
|
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()),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-10-04 23:35:55 +00:00
|
|
|
fn compat_arg<'a, 'b>() -> Arg<'a, 'b> {
|
|
|
|
Arg::with_name("compat")
|
|
|
|
.long("compat")
|
2021-10-06 17:07:04 +00:00
|
|
|
.requires("unstable")
|
|
|
|
.help("Node compatibility mode. Currently only enables built-in node modules like 'fs' and globals like 'process'.")
|
2021-10-04 23:35:55 +00:00
|
|
|
}
|
|
|
|
|
2021-12-15 21:04:43 +00:00
|
|
|
fn watch_arg<'a, 'b>(takes_files: bool) -> Arg<'a, 'b> {
|
|
|
|
let arg = Arg::with_name("watch")
|
2021-04-16 13:28:41 +00:00
|
|
|
.long("watch")
|
2021-12-15 21:04:43 +00:00
|
|
|
.help("UNSTABLE: Watch for file changes and restart process automatically");
|
|
|
|
|
|
|
|
if takes_files {
|
|
|
|
arg
|
|
|
|
.value_name("FILES")
|
|
|
|
.min_values(0)
|
|
|
|
.takes_value(true)
|
|
|
|
.use_delimiter(true)
|
|
|
|
.require_equals(true)
|
|
|
|
.long_help(
|
|
|
|
"UNSTABLE: Watch for file changes and restart process automatically.
|
|
|
|
Local files from entry point module graph are watched by default.
|
|
|
|
Additional paths might be watched by passing them as arguments to this flag.",
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
arg.long_help(
|
2021-04-27 10:44:36 +00:00
|
|
|
"UNSTABLE: Watch for file changes and restart process automatically.
|
2021-04-16 13:28:41 +00:00
|
|
|
Only local files from entry point module graph are watched.",
|
2019-11-26 16:06:32 +00:00
|
|
|
)
|
2021-12-15 21:04:43 +00:00
|
|
|
}
|
2021-04-16 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn no_check_arg<'a, 'b>() -> Arg<'a, 'b> {
|
|
|
|
Arg::with_name("no-check")
|
2021-11-29 22:23:30 +00:00
|
|
|
.takes_value(true)
|
|
|
|
.require_equals(true)
|
|
|
|
.min_values(0)
|
|
|
|
.value_name("NO_CHECK_TYPE")
|
2021-04-16 13:28:41 +00:00
|
|
|
.long("no-check")
|
|
|
|
.help("Skip type checking modules")
|
2021-11-29 22:23:30 +00:00
|
|
|
.long_help(
|
|
|
|
"Skip type checking of modules.
|
|
|
|
If the value of '--no-check=remote' is supplied, diagnostic errors from remote
|
|
|
|
modules will be ignored.",
|
|
|
|
)
|
2021-04-16 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn script_arg<'a, 'b>() -> Arg<'a, 'b> {
|
|
|
|
Arg::with_name("script_arg")
|
|
|
|
.multiple(true)
|
|
|
|
// NOTE: these defaults are provided
|
|
|
|
// so `deno run --v8-flags=--help` works
|
|
|
|
// without specifying file to run.
|
|
|
|
.default_value_ifs(&[
|
|
|
|
("v8-flags", Some("--help"), "_"),
|
|
|
|
("v8-flags", Some("-help"), "_"),
|
|
|
|
])
|
|
|
|
.help("Script arg")
|
|
|
|
.value_name("SCRIPT_ARG")
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn lock_write_arg<'a, 'b>() -> Arg<'a, 'b> {
|
|
|
|
Arg::with_name("lock-write")
|
|
|
|
.long("lock-write")
|
|
|
|
.requires("lock")
|
|
|
|
.help("Write lock file (use with --lock)")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn config_arg<'a, 'b>() -> Arg<'a, 'b> {
|
|
|
|
Arg::with_name("config")
|
|
|
|
.short("c")
|
|
|
|
.long("config")
|
|
|
|
.value_name("FILE")
|
2021-09-13 22:41:34 +00:00
|
|
|
.help("Load configuration file")
|
|
|
|
.long_help(
|
|
|
|
"Load configuration file.
|
|
|
|
Before 1.14 Deno only supported loading tsconfig.json that allowed
|
2021-10-13 17:04:44 +00:00
|
|
|
to customise TypeScript compiler settings.
|
2021-09-13 22:41:34 +00:00
|
|
|
|
2021-10-13 17:04:44 +00:00
|
|
|
Starting with 1.14 configuration file can be used to configure different
|
|
|
|
subcommands like `deno lint` or `deno fmt`.
|
2021-09-13 22:41:34 +00:00
|
|
|
|
|
|
|
It's recommended to use `deno.json` or `deno.jsonc` as a filename.",
|
|
|
|
)
|
2021-04-16 13:28:41 +00:00
|
|
|
.takes_value(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn no_remote_arg<'a, 'b>() -> Arg<'a, 'b> {
|
|
|
|
Arg::with_name("no-remote")
|
|
|
|
.long("no-remote")
|
|
|
|
.help("Do not resolve remote modules")
|
|
|
|
}
|
|
|
|
|
2021-12-10 14:47:55 +00:00
|
|
|
fn unsafely_ignore_ceritifcate_errors_arg<'a, 'b>() -> Arg<'a, 'b> {
|
|
|
|
Arg::with_name("unsafely-ignore-certificate-errors")
|
|
|
|
.long("unsafely-ignore-certificate-errors")
|
|
|
|
.min_values(0)
|
|
|
|
.takes_value(true)
|
|
|
|
.use_delimiter(true)
|
|
|
|
.require_equals(true)
|
|
|
|
.value_name("HOSTNAMES")
|
|
|
|
.help("DANGER: Disables verification of TLS certificates")
|
|
|
|
.validator(crate::flags_allow_net::validator)
|
|
|
|
}
|
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn bundle_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|
|
|
compile_args_parse(flags, matches);
|
|
|
|
|
|
|
|
let source_file = matches.value_of("source_file").unwrap().to_string();
|
|
|
|
|
|
|
|
let out_file = if let Some(out_file) = matches.value_of("out_file") {
|
|
|
|
flags.allow_write = Some(vec![]);
|
|
|
|
Some(PathBuf::from(out_file))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2021-12-15 21:04:43 +00:00
|
|
|
watch_arg_parse(flags, matches, false);
|
2021-04-16 13:28:41 +00:00
|
|
|
|
2021-09-03 23:33:35 +00:00
|
|
|
flags.subcommand = DenoSubcommand::Bundle(BundleFlags {
|
2021-04-16 13:28:41 +00:00
|
|
|
source_file,
|
|
|
|
out_file,
|
2021-09-03 23:33:35 +00:00
|
|
|
});
|
2021-04-16 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn cache_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|
|
|
compile_args_parse(flags, matches);
|
|
|
|
let files = matches
|
|
|
|
.values_of("file")
|
|
|
|
.unwrap()
|
|
|
|
.map(String::from)
|
|
|
|
.collect();
|
2021-09-03 23:33:35 +00:00
|
|
|
flags.subcommand = DenoSubcommand::Cache(CacheFlags { files });
|
2021-04-16 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn compile_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|
|
|
runtime_args_parse(flags, matches, true, false);
|
|
|
|
|
|
|
|
let mut script: Vec<String> = matches
|
|
|
|
.values_of("script_arg")
|
|
|
|
.unwrap()
|
|
|
|
.map(String::from)
|
|
|
|
.collect();
|
|
|
|
assert!(!script.is_empty());
|
|
|
|
let args = script.split_off(1);
|
|
|
|
let source_file = script[0].to_string();
|
|
|
|
let output = matches.value_of("output").map(PathBuf::from);
|
|
|
|
let target = matches.value_of("target").map(String::from);
|
|
|
|
|
2021-09-03 23:33:35 +00:00
|
|
|
flags.subcommand = DenoSubcommand::Compile(CompileFlags {
|
2021-04-16 13:28:41 +00:00
|
|
|
source_file,
|
|
|
|
output,
|
|
|
|
args,
|
|
|
|
target,
|
2021-09-03 23:33:35 +00:00
|
|
|
});
|
2021-04-16 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn completions_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|
|
|
let shell: &str = matches.value_of("shell").unwrap();
|
|
|
|
let mut buf: Vec<u8> = vec![];
|
|
|
|
clap_root(&*crate::version::deno()).gen_completions_to(
|
|
|
|
"deno",
|
|
|
|
clap::Shell::from_str(shell).unwrap(),
|
|
|
|
&mut buf,
|
|
|
|
);
|
|
|
|
|
2021-09-03 23:33:35 +00:00
|
|
|
flags.subcommand = DenoSubcommand::Completions(CompletionsFlags {
|
2021-04-16 13:28:41 +00:00
|
|
|
buf: buf.into_boxed_slice(),
|
2021-09-03 23:33:35 +00:00
|
|
|
});
|
2021-04-16 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn coverage_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|
|
|
let files = match matches.values_of("files") {
|
|
|
|
Some(f) => f.map(PathBuf::from).collect(),
|
|
|
|
None => vec![],
|
|
|
|
};
|
|
|
|
let ignore = match matches.values_of("ignore") {
|
|
|
|
Some(f) => f.map(PathBuf::from).collect(),
|
|
|
|
None => vec![],
|
|
|
|
};
|
|
|
|
let include = match matches.values_of("include") {
|
|
|
|
Some(f) => f.map(String::from).collect(),
|
|
|
|
None => vec![],
|
|
|
|
};
|
|
|
|
let exclude = match matches.values_of("exclude") {
|
|
|
|
Some(f) => f.map(String::from).collect(),
|
|
|
|
None => vec![],
|
|
|
|
};
|
|
|
|
let lcov = matches.is_present("lcov");
|
2021-09-03 23:33:35 +00:00
|
|
|
flags.subcommand = DenoSubcommand::Coverage(CoverageFlags {
|
2021-04-16 13:28:41 +00:00
|
|
|
files,
|
|
|
|
ignore,
|
|
|
|
include,
|
|
|
|
exclude,
|
|
|
|
lcov,
|
2021-09-03 23:33:35 +00:00
|
|
|
});
|
2021-04-16 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn doc_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|
|
|
import_map_arg_parse(flags, matches);
|
|
|
|
reload_arg_parse(flags, matches);
|
|
|
|
|
|
|
|
let source_file = matches.value_of("source_file").map(String::from);
|
|
|
|
let private = matches.is_present("private");
|
|
|
|
let json = matches.is_present("json");
|
|
|
|
let filter = matches.value_of("filter").map(String::from);
|
2021-09-03 23:33:35 +00:00
|
|
|
flags.subcommand = DenoSubcommand::Doc(DocFlags {
|
2021-04-16 13:28:41 +00:00
|
|
|
source_file,
|
|
|
|
json,
|
|
|
|
filter,
|
|
|
|
private,
|
2021-09-03 23:33:35 +00:00
|
|
|
});
|
2021-04-16 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn eval_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|
|
|
runtime_args_parse(flags, matches, false, true);
|
|
|
|
flags.allow_net = Some(vec![]);
|
|
|
|
flags.allow_env = Some(vec![]);
|
|
|
|
flags.allow_run = Some(vec![]);
|
|
|
|
flags.allow_read = Some(vec![]);
|
|
|
|
flags.allow_write = Some(vec![]);
|
2021-08-06 21:28:10 +00:00
|
|
|
flags.allow_ffi = Some(vec![]);
|
2021-04-16 13:28:41 +00:00
|
|
|
flags.allow_hrtime = true;
|
|
|
|
// TODO(@satyarohith): remove this flag in 2.0.
|
|
|
|
let as_typescript = matches.is_present("ts");
|
|
|
|
let ext = if as_typescript {
|
|
|
|
"ts".to_string()
|
|
|
|
} else {
|
|
|
|
matches.value_of("ext").unwrap().to_string()
|
|
|
|
};
|
|
|
|
|
|
|
|
let print = matches.is_present("print");
|
|
|
|
let mut code: Vec<String> = matches
|
|
|
|
.values_of("code_arg")
|
|
|
|
.unwrap()
|
|
|
|
.map(String::from)
|
|
|
|
.collect();
|
|
|
|
assert!(!code.is_empty());
|
|
|
|
let code_args = code.split_off(1);
|
|
|
|
let code = code[0].to_string();
|
|
|
|
for v in code_args {
|
|
|
|
flags.argv.push(v);
|
|
|
|
}
|
2021-09-03 23:33:35 +00:00
|
|
|
flags.subcommand = DenoSubcommand::Eval(EvalFlags { print, code, ext });
|
2021-04-16 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn fmt_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
2021-09-13 18:19:10 +00:00
|
|
|
config_arg_parse(flags, matches);
|
2021-12-15 21:04:43 +00:00
|
|
|
watch_arg_parse(flags, matches, false);
|
2021-04-16 13:28:41 +00:00
|
|
|
let files = match matches.values_of("files") {
|
|
|
|
Some(f) => f.map(PathBuf::from).collect(),
|
|
|
|
None => vec![],
|
|
|
|
};
|
|
|
|
let ignore = match matches.values_of("ignore") {
|
|
|
|
Some(f) => f.map(PathBuf::from).collect(),
|
|
|
|
None => vec![],
|
|
|
|
};
|
|
|
|
let ext = matches.value_of("ext").unwrap().to_string();
|
2019-04-29 23:43:06 +00:00
|
|
|
|
2021-09-13 20:06:45 +00:00
|
|
|
let use_tabs = if matches.is_present("options-use-tabs") {
|
|
|
|
Some(true)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
let line_width = if matches.is_present("options-line-width") {
|
|
|
|
Some(
|
|
|
|
matches
|
|
|
|
.value_of("options-line-width")
|
|
|
|
.unwrap()
|
|
|
|
.parse()
|
|
|
|
.unwrap(),
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
let indent_width = if matches.is_present("options-indent-width") {
|
|
|
|
Some(
|
|
|
|
matches
|
|
|
|
.value_of("options-indent-width")
|
|
|
|
.unwrap()
|
|
|
|
.parse()
|
|
|
|
.unwrap(),
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
let single_quote = if matches.is_present("options-single-quote") {
|
|
|
|
Some(true)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
let prose_wrap = if matches.is_present("options-prose-wrap") {
|
|
|
|
Some(matches.value_of("options-prose-wrap").unwrap().to_string())
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2021-09-03 23:33:35 +00:00
|
|
|
flags.subcommand = DenoSubcommand::Fmt(FmtFlags {
|
2021-04-16 13:28:41 +00:00
|
|
|
check: matches.is_present("check"),
|
|
|
|
ext,
|
|
|
|
files,
|
|
|
|
ignore,
|
2021-09-13 20:06:45 +00:00
|
|
|
use_tabs,
|
|
|
|
line_width,
|
|
|
|
indent_width,
|
|
|
|
single_quote,
|
|
|
|
prose_wrap,
|
2021-09-03 23:33:35 +00:00
|
|
|
});
|
2021-04-16 13:28:41 +00:00
|
|
|
}
|
2019-07-27 09:20:40 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn info_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|
|
|
reload_arg_parse(flags, matches);
|
|
|
|
import_map_arg_parse(flags, matches);
|
2021-05-27 05:23:12 +00:00
|
|
|
location_arg_parse(flags, matches);
|
2021-04-16 13:28:41 +00:00
|
|
|
ca_file_arg_parse(flags, matches);
|
|
|
|
let json = matches.is_present("json");
|
2021-09-03 23:33:35 +00:00
|
|
|
flags.subcommand = DenoSubcommand::Info(InfoFlags {
|
2021-04-16 13:28:41 +00:00
|
|
|
file: matches.value_of("file").map(|f| f.to_string()),
|
|
|
|
json,
|
2021-09-03 23:33:35 +00:00
|
|
|
});
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
2019-05-16 14:11:35 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn install_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|
|
|
runtime_args_parse(flags, matches, true, true);
|
|
|
|
|
|
|
|
let root = if matches.is_present("root") {
|
|
|
|
let install_root = matches.value_of("root").unwrap();
|
|
|
|
Some(PathBuf::from(install_root))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
|
|
|
let force = matches.is_present("force");
|
|
|
|
let name = matches.value_of("name").map(|s| s.to_string());
|
|
|
|
let cmd_values = matches.values_of("cmd").unwrap();
|
|
|
|
let mut cmd = vec![];
|
|
|
|
for value in cmd_values {
|
|
|
|
cmd.push(value.to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
let module_url = cmd[0].to_string();
|
|
|
|
let args = cmd[1..].to_vec();
|
|
|
|
|
2021-09-03 23:33:35 +00:00
|
|
|
flags.subcommand = DenoSubcommand::Install(InstallFlags {
|
2021-04-16 13:28:41 +00:00
|
|
|
name,
|
|
|
|
module_url,
|
|
|
|
args,
|
|
|
|
root,
|
|
|
|
force,
|
2021-09-03 23:33:35 +00:00
|
|
|
});
|
2020-01-08 19:59:53 +00:00
|
|
|
}
|
|
|
|
|
2021-09-30 15:38:07 +00:00
|
|
|
fn uninstall_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|
|
|
let root = if matches.is_present("root") {
|
|
|
|
let install_root = matches.value_of("root").unwrap();
|
|
|
|
Some(PathBuf::from(install_root))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
|
|
|
let name = matches.value_of("name").unwrap().to_string();
|
|
|
|
flags.subcommand = DenoSubcommand::Uninstall(UninstallFlags { name, root });
|
|
|
|
}
|
|
|
|
|
2021-06-23 01:48:01 +00:00
|
|
|
fn lsp_parse(flags: &mut Flags, _matches: &clap::ArgMatches) {
|
|
|
|
flags.subcommand = DenoSubcommand::Lsp;
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
2019-08-15 14:11:52 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn lint_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
2021-09-03 15:01:58 +00:00
|
|
|
config_arg_parse(flags, matches);
|
2021-12-15 21:04:43 +00:00
|
|
|
watch_arg_parse(flags, matches, false);
|
2021-04-16 13:28:41 +00:00
|
|
|
let files = match matches.values_of("files") {
|
|
|
|
Some(f) => f.map(PathBuf::from).collect(),
|
|
|
|
None => vec![],
|
|
|
|
};
|
|
|
|
let ignore = match matches.values_of("ignore") {
|
|
|
|
Some(f) => f.map(PathBuf::from).collect(),
|
|
|
|
None => vec![],
|
|
|
|
};
|
|
|
|
let rules = matches.is_present("rules");
|
2021-11-04 15:12:12 +00:00
|
|
|
let maybe_rules_tags = matches
|
|
|
|
.values_of("rules-tags")
|
|
|
|
.map(|f| f.map(String::from).collect());
|
|
|
|
|
|
|
|
let maybe_rules_include = matches
|
|
|
|
.values_of("rules-include")
|
|
|
|
.map(|f| f.map(String::from).collect());
|
|
|
|
|
|
|
|
let maybe_rules_exclude = matches
|
|
|
|
.values_of("rules-exclude")
|
|
|
|
.map(|f| f.map(String::from).collect());
|
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
let json = matches.is_present("json");
|
2021-09-03 23:33:35 +00:00
|
|
|
flags.subcommand = DenoSubcommand::Lint(LintFlags {
|
2021-04-16 13:28:41 +00:00
|
|
|
files,
|
|
|
|
rules,
|
2021-11-04 15:12:12 +00:00
|
|
|
maybe_rules_tags,
|
|
|
|
maybe_rules_include,
|
|
|
|
maybe_rules_exclude,
|
2021-04-16 13:28:41 +00:00
|
|
|
ignore,
|
|
|
|
json,
|
2021-09-03 23:33:35 +00:00
|
|
|
});
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
2019-08-15 14:11:52 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn repl_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|
|
|
runtime_args_parse(flags, matches, false, true);
|
2021-12-10 14:47:55 +00:00
|
|
|
unsafely_ignore_ceritifcate_errors_parse(flags, matches);
|
2021-04-16 13:28:41 +00:00
|
|
|
flags.repl = true;
|
2021-09-03 23:33:35 +00:00
|
|
|
flags.subcommand = DenoSubcommand::Repl(ReplFlags {
|
2021-08-06 21:30:28 +00:00
|
|
|
eval: matches.value_of("eval").map(ToOwned::to_owned),
|
2021-09-03 23:33:35 +00:00
|
|
|
});
|
2021-04-16 13:28:41 +00:00
|
|
|
flags.allow_net = Some(vec![]);
|
|
|
|
flags.allow_env = Some(vec![]);
|
|
|
|
flags.allow_run = Some(vec![]);
|
|
|
|
flags.allow_read = Some(vec![]);
|
|
|
|
flags.allow_write = Some(vec![]);
|
2021-08-06 21:28:10 +00:00
|
|
|
flags.allow_ffi = Some(vec![]);
|
2021-04-16 13:28:41 +00:00
|
|
|
flags.allow_hrtime = true;
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
2019-08-15 14:11:52 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn run_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|
|
|
runtime_args_parse(flags, matches, true, true);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-12-15 21:04:43 +00:00
|
|
|
watch_arg_parse(flags, matches, true);
|
2021-09-03 23:33:35 +00:00
|
|
|
flags.subcommand = DenoSubcommand::Run(RunFlags { script });
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
2019-08-15 14:11:52 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn test_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|
|
|
runtime_args_parse(flags, matches, true, true);
|
|
|
|
|
2021-08-24 15:23:29 +00:00
|
|
|
let ignore = match matches.values_of("ignore") {
|
|
|
|
Some(f) => f.map(PathBuf::from).collect(),
|
|
|
|
None => vec![],
|
|
|
|
};
|
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
let no_run = matches.is_present("no-run");
|
2021-05-10 23:54:39 +00:00
|
|
|
let doc = matches.is_present("doc");
|
2021-04-16 13:28:41 +00:00
|
|
|
let allow_none = matches.is_present("allow-none");
|
|
|
|
let filter = matches.value_of("filter").map(String::from);
|
|
|
|
|
2021-07-12 10:55:42 +00:00
|
|
|
let fail_fast = if matches.is_present("fail-fast") {
|
|
|
|
if let Some(value) = matches.value_of("fail-fast") {
|
|
|
|
Some(value.parse().unwrap())
|
|
|
|
} else {
|
2021-08-23 10:37:02 +00:00
|
|
|
Some(NonZeroUsize::new(1).unwrap())
|
2021-07-12 10:55:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2021-07-06 01:20:33 +00:00
|
|
|
let shuffle = if matches.is_present("shuffle") {
|
|
|
|
let value = if let Some(value) = matches.value_of("shuffle") {
|
|
|
|
value.parse::<u64>().unwrap()
|
|
|
|
} else {
|
|
|
|
rand::random::<u64>()
|
|
|
|
};
|
|
|
|
|
|
|
|
Some(value)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
2021-05-10 06:06:13 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
if matches.is_present("script_arg") {
|
|
|
|
let script_arg: Vec<String> = matches
|
|
|
|
.values_of("script_arg")
|
|
|
|
.unwrap()
|
|
|
|
.map(String::from)
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
for v in script_arg {
|
|
|
|
flags.argv.push(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-28 18:17:04 +00:00
|
|
|
let concurrent_jobs = if matches.is_present("jobs") {
|
|
|
|
if let Some(value) = matches.value_of("jobs") {
|
|
|
|
value.parse().unwrap()
|
|
|
|
} else {
|
2021-04-30 12:57:42 +00:00
|
|
|
// TODO(caspervonb) drop the dependency on num_cpus when https://doc.rust-lang.org/std/thread/fn.available_concurrency.html becomes stable.
|
2021-08-23 10:35:38 +00:00
|
|
|
NonZeroUsize::new(num_cpus::get()).unwrap()
|
2021-04-28 18:17:04 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-08-23 10:35:38 +00:00
|
|
|
NonZeroUsize::new(1).unwrap()
|
2021-04-28 18:17:04 +00:00
|
|
|
};
|
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
let include = if matches.is_present("files") {
|
|
|
|
let files: Vec<String> = matches
|
|
|
|
.values_of("files")
|
|
|
|
.unwrap()
|
|
|
|
.map(String::from)
|
|
|
|
.collect();
|
|
|
|
Some(files)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
|
|
|
flags.coverage_dir = matches.value_of("coverage").map(String::from);
|
2021-12-15 21:04:43 +00:00
|
|
|
watch_arg_parse(flags, matches, false);
|
2021-09-03 23:33:35 +00:00
|
|
|
flags.subcommand = DenoSubcommand::Test(TestFlags {
|
2021-04-16 13:28:41 +00:00
|
|
|
no_run,
|
2021-05-10 23:54:39 +00:00
|
|
|
doc,
|
2021-04-16 13:28:41 +00:00
|
|
|
fail_fast,
|
|
|
|
include,
|
2021-08-24 15:23:29 +00:00
|
|
|
ignore,
|
2021-04-16 13:28:41 +00:00
|
|
|
filter,
|
2021-07-06 01:20:33 +00:00
|
|
|
shuffle,
|
2021-04-16 13:28:41 +00:00
|
|
|
allow_none,
|
2021-04-28 18:17:04 +00:00
|
|
|
concurrent_jobs,
|
2021-09-03 23:33:35 +00:00
|
|
|
});
|
2020-02-17 16:59:51 +00:00
|
|
|
}
|
2020-04-03 17:40:11 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn types_parse(flags: &mut Flags, _matches: &clap::ArgMatches) {
|
|
|
|
flags.subcommand = DenoSubcommand::Types;
|
2020-02-17 16:59:51 +00:00
|
|
|
}
|
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn upgrade_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|
|
|
ca_file_arg_parse(flags, matches);
|
|
|
|
|
|
|
|
let dry_run = matches.is_present("dry-run");
|
|
|
|
let force = matches.is_present("force");
|
|
|
|
let canary = matches.is_present("canary");
|
|
|
|
let version = matches.value_of("version").map(|s| s.to_string());
|
|
|
|
let output = if matches.is_present("output") {
|
|
|
|
let install_root = matches.value_of("output").unwrap();
|
|
|
|
Some(PathBuf::from(install_root))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
let ca_file = matches.value_of("cert").map(|s| s.to_string());
|
2021-09-03 23:33:35 +00:00
|
|
|
flags.subcommand = DenoSubcommand::Upgrade(UpgradeFlags {
|
2021-04-16 13:28:41 +00:00
|
|
|
dry_run,
|
|
|
|
force,
|
|
|
|
canary,
|
|
|
|
version,
|
|
|
|
output,
|
|
|
|
ca_file,
|
2021-09-03 23:33:35 +00:00
|
|
|
});
|
2021-01-07 18:06:08 +00:00
|
|
|
}
|
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn compile_args_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|
|
|
import_map_arg_parse(flags, matches);
|
|
|
|
no_remote_arg_parse(flags, matches);
|
|
|
|
config_arg_parse(flags, matches);
|
|
|
|
no_check_arg_parse(flags, matches);
|
|
|
|
reload_arg_parse(flags, matches);
|
|
|
|
lock_args_parse(flags, matches);
|
|
|
|
ca_file_arg_parse(flags, matches);
|
2021-01-07 18:06:08 +00:00
|
|
|
}
|
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn permission_args_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
2021-12-10 14:47:55 +00:00
|
|
|
unsafely_ignore_ceritifcate_errors_parse(flags, matches);
|
2021-04-16 13:28:41 +00:00
|
|
|
if let Some(read_wl) = matches.values_of("allow-read") {
|
|
|
|
let read_allowlist: Vec<PathBuf> = read_wl.map(PathBuf::from).collect();
|
|
|
|
flags.allow_read = Some(read_allowlist);
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(write_wl) = matches.values_of("allow-write") {
|
|
|
|
let write_allowlist: Vec<PathBuf> = write_wl.map(PathBuf::from).collect();
|
|
|
|
flags.allow_write = Some(write_allowlist);
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(net_wl) = matches.values_of("allow-net") {
|
|
|
|
let net_allowlist: Vec<String> =
|
|
|
|
crate::flags_allow_net::parse(net_wl.map(ToString::to_string).collect())
|
|
|
|
.unwrap();
|
|
|
|
flags.allow_net = Some(net_allowlist);
|
2021-08-09 14:53:21 +00:00
|
|
|
}
|
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
if let Some(env_wl) = matches.values_of("allow-env") {
|
|
|
|
let env_allowlist: Vec<String> = env_wl
|
|
|
|
.map(|env: &str| {
|
|
|
|
if cfg!(windows) {
|
|
|
|
env.to_uppercase()
|
|
|
|
} else {
|
|
|
|
env.to_string()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
flags.allow_env = Some(env_allowlist);
|
|
|
|
debug!("env allowlist: {:#?}", &flags.allow_env);
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(run_wl) = matches.values_of("allow-run") {
|
|
|
|
let run_allowlist: Vec<String> = run_wl.map(ToString::to_string).collect();
|
|
|
|
flags.allow_run = Some(run_allowlist);
|
|
|
|
debug!("run allowlist: {:#?}", &flags.allow_run);
|
|
|
|
}
|
|
|
|
|
2021-08-06 21:28:10 +00:00
|
|
|
if let Some(ffi_wl) = matches.values_of("allow-ffi") {
|
2021-10-13 17:04:44 +00:00
|
|
|
let ffi_allowlist: Vec<PathBuf> = ffi_wl.map(PathBuf::from).collect();
|
2021-08-06 21:28:10 +00:00
|
|
|
flags.allow_ffi = Some(ffi_allowlist);
|
|
|
|
debug!("ffi allowlist: {:#?}", &flags.allow_ffi);
|
2021-04-16 13:28:41 +00:00
|
|
|
}
|
2021-08-06 21:28:10 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
if matches.is_present("allow-hrtime") {
|
|
|
|
flags.allow_hrtime = true;
|
|
|
|
}
|
|
|
|
if matches.is_present("allow-all") {
|
|
|
|
flags.allow_read = Some(vec![]);
|
|
|
|
flags.allow_env = Some(vec![]);
|
|
|
|
flags.allow_net = Some(vec![]);
|
|
|
|
flags.allow_run = Some(vec![]);
|
|
|
|
flags.allow_write = Some(vec![]);
|
2021-08-06 21:28:10 +00:00
|
|
|
flags.allow_ffi = Some(vec![]);
|
2021-04-16 13:28:41 +00:00
|
|
|
flags.allow_hrtime = true;
|
|
|
|
}
|
|
|
|
if matches.is_present("prompt") {
|
|
|
|
flags.prompt = true;
|
|
|
|
}
|
2020-03-27 20:09:51 +00:00
|
|
|
}
|
2021-12-10 14:47:55 +00:00
|
|
|
fn unsafely_ignore_ceritifcate_errors_parse(
|
|
|
|
flags: &mut Flags,
|
|
|
|
matches: &clap::ArgMatches,
|
|
|
|
) {
|
|
|
|
if let Some(ic_wl) = matches.values_of("unsafely-ignore-certificate-errors") {
|
|
|
|
let ic_allowlist: Vec<String> =
|
|
|
|
crate::flags_allow_net::parse(ic_wl.map(ToString::to_string).collect())
|
|
|
|
.unwrap();
|
|
|
|
flags.unsafely_ignore_certificate_errors = Some(ic_allowlist);
|
|
|
|
}
|
|
|
|
}
|
2021-04-16 13:28:41 +00:00
|
|
|
fn runtime_args_parse(
|
|
|
|
flags: &mut Flags,
|
|
|
|
matches: &clap::ArgMatches,
|
|
|
|
include_perms: bool,
|
|
|
|
include_inspector: bool,
|
|
|
|
) {
|
|
|
|
compile_args_parse(flags, matches);
|
|
|
|
cached_only_arg_parse(flags, matches);
|
|
|
|
if include_perms {
|
|
|
|
permission_args_parse(flags, matches);
|
|
|
|
}
|
|
|
|
if include_inspector {
|
|
|
|
inspect_arg_parse(flags, matches);
|
2020-04-03 17:40:11 +00:00
|
|
|
}
|
2021-04-16 13:28:41 +00:00
|
|
|
location_arg_parse(flags, matches);
|
|
|
|
v8_flags_arg_parse(flags, matches);
|
|
|
|
seed_arg_parse(flags, matches);
|
2021-10-04 23:35:55 +00:00
|
|
|
compat_arg_parse(flags, matches);
|
2021-04-16 13:28:41 +00:00
|
|
|
inspect_arg_parse(flags, matches);
|
2021-07-23 14:31:16 +00:00
|
|
|
enable_testing_features_arg_parse(flags, matches);
|
2020-04-03 17:40:11 +00:00
|
|
|
}
|
|
|
|
|
2020-03-27 20:09:51 +00:00
|
|
|
fn inspect_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
2020-04-03 17:40:11 +00:00
|
|
|
let default = || "127.0.0.1:9229".parse::<SocketAddr>().unwrap();
|
2020-03-27 20:09:51 +00:00
|
|
|
flags.inspect = if matches.is_present("inspect") {
|
|
|
|
if let Some(host) = matches.value_of("inspect") {
|
2020-04-03 17:40:11 +00:00
|
|
|
Some(host.parse().unwrap())
|
2020-03-27 20:09:51 +00:00
|
|
|
} else {
|
2020-04-03 17:40:11 +00:00
|
|
|
Some(default())
|
2020-03-27 20:09:51 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
flags.inspect_brk = if matches.is_present("inspect-brk") {
|
|
|
|
if let Some(host) = matches.value_of("inspect-brk") {
|
2020-04-03 17:40:11 +00:00
|
|
|
Some(host.parse().unwrap())
|
2020-03-27 20:09:51 +00:00
|
|
|
} else {
|
2020-04-03 17:40:11 +00:00
|
|
|
Some(default())
|
2020-03-27 20:09:51 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn import_map_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|
|
|
flags.import_map_path = matches.value_of("import-map").map(ToOwned::to_owned);
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
2019-08-15 14:11:52 +00:00
|
|
|
|
2020-02-26 10:52:15 +00:00
|
|
|
fn reload_arg_parse(flags: &mut Flags, matches: &ArgMatches) {
|
2020-05-16 13:41:32 +00:00
|
|
|
if let Some(cache_bl) = matches.values_of("reload") {
|
2020-06-13 17:09:39 +00:00
|
|
|
let raw_cache_blocklist: Vec<String> =
|
2020-11-12 22:17:31 +00:00
|
|
|
cache_bl.map(ToString::to_string).collect();
|
2020-06-13 17:09:39 +00:00
|
|
|
if raw_cache_blocklist.is_empty() {
|
2020-05-16 13:41:32 +00:00
|
|
|
flags.reload = true;
|
|
|
|
} else {
|
2020-06-13 17:09:39 +00:00
|
|
|
flags.cache_blocklist = resolve_urls(raw_cache_blocklist);
|
|
|
|
debug!("cache blocklist: {:#?}", &flags.cache_blocklist);
|
2019-11-26 16:06:32 +00:00
|
|
|
flags.reload = false;
|
2019-05-03 21:15:16 +00:00
|
|
|
}
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-04 13:02:36 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn ca_file_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|
|
|
flags.ca_file = matches.value_of("cert").map(ToOwned::to_owned);
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
2019-10-04 13:02:36 +00:00
|
|
|
|
2021-07-23 14:31:16 +00:00
|
|
|
fn enable_testing_features_arg_parse(
|
|
|
|
flags: &mut Flags,
|
|
|
|
matches: &clap::ArgMatches,
|
|
|
|
) {
|
|
|
|
if matches.is_present("enable-testing-features-do-not-use") {
|
|
|
|
flags.enable_testing_features = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn cached_only_arg_parse(flags: &mut Flags, matches: &ArgMatches) {
|
|
|
|
if matches.is_present("cached-only") {
|
|
|
|
flags.cached_only = true;
|
|
|
|
}
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
2019-10-04 13:02:36 +00:00
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn location_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|
|
|
flags.location = matches
|
|
|
|
.value_of("location")
|
|
|
|
.map(|href| Url::parse(href).unwrap());
|
2019-11-27 04:25:14 +00:00
|
|
|
}
|
|
|
|
|
2020-02-26 10:52:15 +00:00
|
|
|
fn v8_flags_arg_parse(flags: &mut Flags, matches: &ArgMatches) {
|
2019-11-27 04:25:14 +00:00
|
|
|
if let Some(v8_flags) = matches.values_of("v8-flags") {
|
2020-12-06 17:19:21 +00:00
|
|
|
flags.v8_flags = v8_flags.map(String::from).collect();
|
2019-11-27 04:25:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-18 17:09:11 +00:00
|
|
|
fn seed_arg_parse(flags: &mut Flags, matches: &ArgMatches) {
|
|
|
|
if matches.is_present("seed") {
|
|
|
|
let seed_string = matches.value_of("seed").unwrap();
|
|
|
|
let seed = seed_string.parse::<u64>().unwrap();
|
|
|
|
flags.seed = Some(seed);
|
|
|
|
|
2020-12-06 17:19:21 +00:00
|
|
|
flags.v8_flags.push(format!("--random-seed={}", seed));
|
2020-09-18 17:09:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-04 23:35:55 +00:00
|
|
|
fn compat_arg_parse(flags: &mut Flags, matches: &ArgMatches) {
|
|
|
|
if matches.is_present("compat") {
|
|
|
|
flags.compat = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-08 09:26:39 +00:00
|
|
|
fn no_check_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
2021-11-29 22:23:30 +00:00
|
|
|
if let Some(cache_type) = matches.value_of("no-check") {
|
|
|
|
match cache_type {
|
|
|
|
"remote" => flags.check = CheckFlag::Local,
|
|
|
|
_ => debug!(
|
|
|
|
"invalid value for 'no-check' of '{}' using default",
|
|
|
|
cache_type
|
|
|
|
),
|
|
|
|
}
|
|
|
|
} else if matches.is_present("no-check") {
|
|
|
|
flags.check = CheckFlag::None;
|
2020-07-08 09:26:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn lock_args_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|
|
|
if matches.is_present("lock") {
|
|
|
|
let lockfile = matches.value_of("lock").unwrap();
|
|
|
|
flags.lock = Some(PathBuf::from(lockfile));
|
|
|
|
}
|
|
|
|
if matches.is_present("lock-write") {
|
|
|
|
flags.lock_write = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn config_arg_parse(flags: &mut Flags, matches: &ArgMatches) {
|
|
|
|
flags.config_path = matches.value_of("config").map(ToOwned::to_owned);
|
2019-12-03 22:48:53 +00:00
|
|
|
}
|
|
|
|
|
2020-02-26 10:52:15 +00:00
|
|
|
fn no_remote_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
2019-12-03 22:48:53 +00:00
|
|
|
if matches.is_present("no-remote") {
|
|
|
|
flags.no_remote = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-16 13:28:41 +00:00
|
|
|
fn inspect_arg_validate(val: String) -> Result<(), String> {
|
|
|
|
match val.parse::<SocketAddr>() {
|
|
|
|
Ok(_) => Ok(()),
|
|
|
|
Err(e) => Err(e.to_string()),
|
2021-04-12 02:15:43 +00:00
|
|
|
}
|
2020-01-30 23:42:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-15 21:04:43 +00:00
|
|
|
fn watch_arg_parse(
|
|
|
|
flags: &mut Flags,
|
|
|
|
matches: &clap::ArgMatches,
|
|
|
|
allow_extra: bool,
|
|
|
|
) {
|
|
|
|
if allow_extra {
|
|
|
|
if let Some(f) = matches.values_of("watch") {
|
|
|
|
flags.watch = Some(f.map(PathBuf::from).collect());
|
|
|
|
}
|
|
|
|
} else if matches.is_present("watch") {
|
|
|
|
flags.watch = Some(vec![]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-26 16:06:32 +00: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> {
|
|
|
|
let mut out: Vec<String> = vec![];
|
|
|
|
for urlstr in urls.iter() {
|
2020-11-12 22:17:31 +00:00
|
|
|
if let Ok(mut url) = Url::from_str(urlstr) {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
out.push(full_url);
|
|
|
|
} else {
|
2019-11-26 16:06:32 +00:00
|
|
|
panic!("Bad Url: {}", urlstr);
|
2019-06-05 17:44:46 +00:00
|
|
|
}
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
|
|
|
out
|
2019-04-29 23:43:06 +00:00
|
|
|
}
|
|
|
|
|
2019-11-26 16:06:32 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
2020-12-06 17:19:21 +00:00
|
|
|
/// Creates vector of strings, Vec<String>
|
|
|
|
macro_rules! svec {
|
|
|
|
($($x:expr),*) => (vec![$($x.to_string()),*]);
|
|
|
|
}
|
|
|
|
|
2020-09-20 11:45:00 +00:00
|
|
|
#[test]
|
|
|
|
fn global_flags() {
|
|
|
|
#[rustfmt::skip]
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "--unstable", "--log-level", "debug", "--quiet", "run", "script.ts"]);
|
2020-09-20 11:45:00 +00:00
|
|
|
let flags = r.unwrap();
|
|
|
|
assert_eq!(
|
|
|
|
flags,
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-09-20 11:45:00 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-09-20 11:45:00 +00:00
|
|
|
unstable: true,
|
|
|
|
log_level: Some(Level::Error),
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
#[rustfmt::skip]
|
2021-01-07 18:06:08 +00:00
|
|
|
let r2 = flags_from_vec(svec!["deno", "run", "--unstable", "--log-level", "debug", "--quiet", "script.ts"]);
|
2020-09-20 11:45:00 +00:00
|
|
|
let flags2 = r2.unwrap();
|
|
|
|
assert_eq!(flags2, flags);
|
|
|
|
}
|
|
|
|
|
2020-03-23 15:37:24 +00:00
|
|
|
#[test]
|
|
|
|
fn upgrade() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "upgrade", "--dry-run", "--force"]);
|
2020-03-23 15:37:24 +00:00
|
|
|
let flags = r.unwrap();
|
|
|
|
assert_eq!(
|
|
|
|
flags,
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Upgrade(UpgradeFlags {
|
2020-03-23 15:37:24 +00:00
|
|
|
force: true,
|
|
|
|
dry_run: true,
|
2020-11-29 19:00:35 +00:00
|
|
|
canary: false,
|
2020-07-06 03:58:23 +00:00
|
|
|
version: None,
|
2020-07-06 22:21:26 +00:00
|
|
|
output: None,
|
|
|
|
ca_file: None,
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-03-23 15:37:24 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-11-26 16:06:32 +00:00
|
|
|
#[test]
|
|
|
|
fn version() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "--version"]);
|
2019-11-26 16:06:32 +00:00
|
|
|
assert_eq!(r.unwrap_err().kind, clap::ErrorKind::VersionDisplayed);
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "-V"]);
|
2019-11-26 16:06:32 +00:00
|
|
|
assert_eq!(r.unwrap_err().kind, clap::ErrorKind::VersionDisplayed);
|
2019-04-21 15:34:18 +00:00
|
|
|
}
|
2018-08-24 19:26:40 +00:00
|
|
|
|
2019-04-21 15:34:18 +00:00
|
|
|
#[test]
|
2019-11-26 16:06:32 +00:00
|
|
|
fn run_reload() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "run", "-r", "script.ts"]);
|
2019-11-26 16:06:32 +00:00
|
|
|
let flags = r.unwrap();
|
2019-04-21 15:34:18 +00:00
|
|
|
assert_eq!(
|
|
|
|
flags,
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-02-04 19:24:33 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2019-04-21 15:34:18 +00:00
|
|
|
reload: true,
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-04-21 15:34:18 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2018-10-11 21:23:22 +00:00
|
|
|
|
2020-09-11 16:19:49 +00:00
|
|
|
#[test]
|
|
|
|
fn run_watch() {
|
2021-04-27 10:44:36 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "run", "--watch", "script.ts"]);
|
2020-09-11 16:19:49 +00:00
|
|
|
let flags = r.unwrap();
|
|
|
|
assert_eq!(
|
|
|
|
flags,
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-09-11 16:19:49 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2021-12-15 21:04:43 +00:00
|
|
|
watch: Some(vec![]),
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn run_watch_with_external() {
|
|
|
|
let r =
|
|
|
|
flags_from_vec(svec!["deno", "run", "--watch=file1,file2", "script.ts"]);
|
|
|
|
let flags = r.unwrap();
|
|
|
|
assert_eq!(
|
|
|
|
flags,
|
|
|
|
Flags {
|
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
|
|
|
script: "script.ts".to_string(),
|
|
|
|
}),
|
|
|
|
watch: Some(vec![PathBuf::from("file1"), PathBuf::from("file2")]),
|
2020-09-11 16:19:49 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-04-21 15:34:18 +00:00
|
|
|
#[test]
|
2019-11-26 16:06:32 +00:00
|
|
|
fn run_reload_allow_write() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r =
|
|
|
|
flags_from_vec(svec!["deno", "run", "-r", "--allow-write", "script.ts"]);
|
2019-04-21 15:34:18 +00:00
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2019-04-21 15:34:18 +00:00
|
|
|
reload: true,
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-02-04 19:24:33 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_write: Some(vec![]),
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-04-21 15:34:18 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2018-10-15 18:26:22 +00:00
|
|
|
|
2019-04-21 15:34:18 +00:00
|
|
|
#[test]
|
2019-11-26 16:06:32 +00:00
|
|
|
fn run_v8_flags() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "run", "--v8-flags=--help"]);
|
2019-04-21 15:34:18 +00:00
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-11-21 22:33:42 +00:00
|
|
|
script: "_".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-12-06 17:19:21 +00:00
|
|
|
v8_flags: svec!["--help"],
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-04-21 15:34:18 +00:00
|
|
|
}
|
|
|
|
);
|
2019-01-09 16:59:54 +00:00
|
|
|
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2019-05-03 21:15:16 +00:00
|
|
|
"deno",
|
|
|
|
"run",
|
2019-11-26 16:06:32 +00:00
|
|
|
"--v8-flags=--expose-gc,--gc-stats=1",
|
2019-05-03 21:15:16 +00:00
|
|
|
"script.ts"
|
|
|
|
]);
|
2019-04-21 15:34:18 +00:00
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-02-04 19:24:33 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-12-06 17:19:21 +00:00
|
|
|
v8_flags: svec!["--expose-gc", "--gc-stats=1"],
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-04-21 15:34:18 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-11-26 16:06:32 +00:00
|
|
|
fn script_args() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2019-05-03 21:15:16 +00:00
|
|
|
"deno",
|
|
|
|
"run",
|
|
|
|
"--allow-net",
|
|
|
|
"gist.ts",
|
|
|
|
"--title",
|
|
|
|
"X"
|
|
|
|
]);
|
2019-04-21 15:34:18 +00:00
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-02-04 19:24:33 +00:00
|
|
|
script: "gist.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-02-04 19:24:33 +00:00
|
|
|
argv: svec!["--title", "X"],
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_net: Some(vec![]),
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-04-21 15:34:18 +00:00
|
|
|
}
|
2019-04-29 23:43:06 +00:00
|
|
|
);
|
2019-04-21 15:34:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-11-26 16:06:32 +00:00
|
|
|
fn allow_all() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "run", "--allow-all", "gist.ts"]);
|
2019-04-21 15:34:18 +00:00
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-02-04 19:24:33 +00:00
|
|
|
script: "gist.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_net: Some(vec![]),
|
2021-04-13 11:25:21 +00:00
|
|
|
allow_env: Some(vec![]),
|
2021-04-09 22:12:00 +00:00
|
|
|
allow_run: Some(vec![]),
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_read: Some(vec![]),
|
|
|
|
allow_write: Some(vec![]),
|
2021-08-06 21:28:10 +00:00
|
|
|
allow_ffi: Some(vec![]),
|
2019-05-23 16:28:29 +00:00
|
|
|
allow_hrtime: true,
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-04-21 15:34:18 +00:00
|
|
|
}
|
2019-04-29 23:43:06 +00:00
|
|
|
);
|
2019-04-21 15:34:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-11-26 16:06:32 +00:00
|
|
|
fn allow_read() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "run", "--allow-read", "gist.ts"]);
|
2019-04-21 15:34:18 +00:00
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-02-04 19:24:33 +00:00
|
|
|
script: "gist.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_read: Some(vec![]),
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-04-21 15:34:18 +00:00
|
|
|
}
|
2019-04-29 23:43:06 +00:00
|
|
|
);
|
2019-04-21 15:34:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-11-26 16:06:32 +00:00
|
|
|
fn allow_hrtime() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "run", "--allow-hrtime", "gist.ts"]);
|
2019-04-21 15:34:18 +00:00
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-02-04 19:24:33 +00:00
|
|
|
script: "gist.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2019-05-23 16:28:29 +00:00
|
|
|
allow_hrtime: true,
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-04-21 15:34:18 +00:00
|
|
|
}
|
2019-04-29 23:43:06 +00:00
|
|
|
);
|
2019-04-21 15:34:18 +00:00
|
|
|
}
|
2019-04-08 20:22:40 +00:00
|
|
|
|
2019-04-21 15:34:18 +00:00
|
|
|
#[test]
|
2019-11-26 16:06:32 +00:00
|
|
|
fn double_hyphen() {
|
2019-06-29 22:32:54 +00:00
|
|
|
// notice that flags passed after double dash will not
|
2020-02-26 10:52:15 +00:00
|
|
|
// be parsed to Flags but instead forwarded to
|
2019-04-21 15:34:18 +00:00
|
|
|
// script args as Deno.args
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2019-04-21 15:34:18 +00:00
|
|
|
"deno",
|
2019-05-03 21:15:16 +00:00
|
|
|
"run",
|
2019-04-21 15:34:18 +00:00
|
|
|
"--allow-write",
|
|
|
|
"script.ts",
|
2019-06-29 22:32:54 +00:00
|
|
|
"--",
|
2019-04-21 15:34:18 +00:00
|
|
|
"-D",
|
|
|
|
"--allow-net"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-02-04 19:24:33 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-02-04 19:24:33 +00:00
|
|
|
argv: svec!["--", "-D", "--allow-net"],
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_write: Some(vec![]),
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-04-21 15:34:18 +00:00
|
|
|
}
|
2019-04-29 23:43:06 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-11-26 16:06:32 +00:00
|
|
|
fn fmt() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "fmt", "script_1.ts", "script_2.ts"]);
|
2019-04-29 23:43:06 +00:00
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Fmt(FmtFlags {
|
2020-07-30 16:09:08 +00:00
|
|
|
ignore: vec![],
|
2020-01-30 02:16:48 +00:00
|
|
|
check: false,
|
2020-10-21 11:12:01 +00:00
|
|
|
files: vec![
|
|
|
|
PathBuf::from("script_1.ts"),
|
|
|
|
PathBuf::from("script_2.ts")
|
|
|
|
],
|
2021-09-13 20:06:45 +00:00
|
|
|
ext: "ts".to_string(),
|
|
|
|
use_tabs: None,
|
|
|
|
line_width: None,
|
|
|
|
indent_width: None,
|
|
|
|
single_quote: None,
|
|
|
|
prose_wrap: None,
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2020-01-30 02:16:48 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "fmt", "--check"]);
|
2020-01-30 02:16:48 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Fmt(FmtFlags {
|
2020-07-30 16:09:08 +00:00
|
|
|
ignore: vec![],
|
2020-01-30 02:16:48 +00:00
|
|
|
check: true,
|
2020-02-13 21:02:18 +00:00
|
|
|
files: vec![],
|
2021-01-19 17:39:35 +00:00
|
|
|
ext: "ts".to_string(),
|
2021-09-13 20:06:45 +00:00
|
|
|
use_tabs: None,
|
|
|
|
line_width: None,
|
|
|
|
indent_width: None,
|
|
|
|
single_quote: None,
|
|
|
|
prose_wrap: None,
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-04-29 23:43:06 +00:00
|
|
|
}
|
|
|
|
);
|
2020-02-09 10:19:05 +00:00
|
|
|
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "fmt"]);
|
2020-02-09 10:19:05 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Fmt(FmtFlags {
|
2020-07-30 16:09:08 +00:00
|
|
|
ignore: vec![],
|
2020-02-09 10:19:05 +00:00
|
|
|
check: false,
|
2020-02-13 21:02:18 +00:00
|
|
|
files: vec![],
|
2021-01-19 17:39:35 +00:00
|
|
|
ext: "ts".to_string(),
|
2021-09-13 20:06:45 +00:00
|
|
|
use_tabs: None,
|
|
|
|
line_width: None,
|
|
|
|
indent_width: None,
|
|
|
|
single_quote: None,
|
|
|
|
prose_wrap: None,
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2020-02-09 10:19:05 +00:00
|
|
|
}
|
|
|
|
);
|
2020-11-22 20:45:44 +00:00
|
|
|
|
2021-04-27 10:44:36 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "fmt", "--watch"]);
|
2020-11-22 20:45:44 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Fmt(FmtFlags {
|
2020-11-22 20:45:44 +00:00
|
|
|
ignore: vec![],
|
|
|
|
check: false,
|
|
|
|
files: vec![],
|
2021-01-19 17:39:35 +00:00
|
|
|
ext: "ts".to_string(),
|
2021-09-13 20:06:45 +00:00
|
|
|
use_tabs: None,
|
|
|
|
line_width: None,
|
|
|
|
indent_width: None,
|
|
|
|
single_quote: None,
|
|
|
|
prose_wrap: None,
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2021-12-15 21:04:43 +00:00
|
|
|
watch: Some(vec![]),
|
2020-11-22 20:45:44 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2020-11-22 20:45:44 +00:00
|
|
|
"deno",
|
|
|
|
"fmt",
|
|
|
|
"--check",
|
|
|
|
"--watch",
|
|
|
|
"foo.ts",
|
|
|
|
"--ignore=bar.js"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Fmt(FmtFlags {
|
2020-11-22 20:45:44 +00:00
|
|
|
ignore: vec![PathBuf::from("bar.js")],
|
|
|
|
check: true,
|
|
|
|
files: vec![PathBuf::from("foo.ts")],
|
2021-01-19 17:39:35 +00:00
|
|
|
ext: "ts".to_string(),
|
2021-09-13 20:06:45 +00:00
|
|
|
use_tabs: None,
|
|
|
|
line_width: None,
|
|
|
|
indent_width: None,
|
|
|
|
single_quote: None,
|
|
|
|
prose_wrap: None,
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2021-12-15 21:04:43 +00:00
|
|
|
watch: Some(vec![]),
|
2021-09-13 18:19:10 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
let r = flags_from_vec(svec!["deno", "fmt", "--config", "deno.jsonc"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
subcommand: DenoSubcommand::Fmt(FmtFlags {
|
|
|
|
ignore: vec![],
|
|
|
|
check: false,
|
|
|
|
files: vec![],
|
2021-09-13 20:06:45 +00:00
|
|
|
ext: "ts".to_string(),
|
|
|
|
use_tabs: None,
|
|
|
|
line_width: None,
|
|
|
|
indent_width: None,
|
|
|
|
single_quote: None,
|
|
|
|
prose_wrap: None,
|
2021-09-13 18:19:10 +00:00
|
|
|
}),
|
|
|
|
config_path: Some("deno.jsonc".to_string()),
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
let r = flags_from_vec(svec![
|
|
|
|
"deno",
|
|
|
|
"fmt",
|
|
|
|
"--config",
|
|
|
|
"deno.jsonc",
|
|
|
|
"--watch",
|
|
|
|
"foo.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
subcommand: DenoSubcommand::Fmt(FmtFlags {
|
|
|
|
ignore: vec![],
|
|
|
|
check: false,
|
|
|
|
files: vec![PathBuf::from("foo.ts")],
|
2021-09-13 20:06:45 +00:00
|
|
|
ext: "ts".to_string(),
|
|
|
|
use_tabs: None,
|
|
|
|
line_width: None,
|
|
|
|
indent_width: None,
|
|
|
|
single_quote: None,
|
|
|
|
prose_wrap: None,
|
2021-09-13 18:19:10 +00:00
|
|
|
}),
|
|
|
|
config_path: Some("deno.jsonc".to_string()),
|
2021-12-15 21:04:43 +00:00
|
|
|
watch: Some(vec![]),
|
2020-11-22 20:45:44 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
2021-09-13 20:06:45 +00:00
|
|
|
|
|
|
|
let r = flags_from_vec(svec![
|
|
|
|
"deno",
|
|
|
|
"fmt",
|
|
|
|
"--options-use-tabs",
|
|
|
|
"--options-line-width",
|
|
|
|
"60",
|
|
|
|
"--options-indent-width",
|
|
|
|
"4",
|
|
|
|
"--options-single-quote",
|
|
|
|
"--options-prose-wrap",
|
|
|
|
"never"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
subcommand: DenoSubcommand::Fmt(FmtFlags {
|
|
|
|
ignore: vec![],
|
|
|
|
check: false,
|
|
|
|
files: vec![],
|
|
|
|
ext: "ts".to_string(),
|
|
|
|
use_tabs: Some(true),
|
|
|
|
line_width: Some(NonZeroU32::new(60).unwrap()),
|
|
|
|
indent_width: Some(NonZeroU8::new(4).unwrap()),
|
|
|
|
single_quote: Some(true),
|
|
|
|
prose_wrap: Some("never".to_string()),
|
|
|
|
}),
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
2019-04-29 23:43:06 +00:00
|
|
|
}
|
|
|
|
|
2020-06-10 21:29:48 +00:00
|
|
|
#[test]
|
|
|
|
fn lint() {
|
2021-04-27 10:44:36 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "lint", "script_1.ts", "script_2.ts"]);
|
2020-06-10 21:29:48 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Lint(LintFlags {
|
2020-10-21 11:12:01 +00:00
|
|
|
files: vec![
|
|
|
|
PathBuf::from("script_1.ts"),
|
|
|
|
PathBuf::from("script_2.ts")
|
|
|
|
],
|
2020-06-12 14:42:12 +00:00
|
|
|
rules: false,
|
2021-11-04 15:12:12 +00:00
|
|
|
maybe_rules_tags: None,
|
|
|
|
maybe_rules_include: None,
|
|
|
|
maybe_rules_exclude: None,
|
2020-08-13 15:30:46 +00:00
|
|
|
json: false,
|
2020-08-12 13:47:44 +00:00
|
|
|
ignore: vec![],
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-06-10 21:29:48 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-04-27 10:44:36 +00:00
|
|
|
let r =
|
|
|
|
flags_from_vec(svec!["deno", "lint", "--ignore=script_1.ts,script_2.ts"]);
|
2020-06-10 21:29:48 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Lint(LintFlags {
|
2020-06-12 14:42:12 +00:00
|
|
|
files: vec![],
|
|
|
|
rules: false,
|
2021-11-04 15:12:12 +00:00
|
|
|
maybe_rules_tags: None,
|
|
|
|
maybe_rules_include: None,
|
|
|
|
maybe_rules_exclude: None,
|
2020-08-13 15:30:46 +00:00
|
|
|
json: false,
|
2020-10-21 11:12:01 +00:00
|
|
|
ignore: vec![
|
|
|
|
PathBuf::from("script_1.ts"),
|
|
|
|
PathBuf::from("script_2.ts")
|
|
|
|
],
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-06-12 14:42:12 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-04-27 10:44:36 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "lint", "--rules"]);
|
2020-06-12 14:42:12 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Lint(LintFlags {
|
2020-06-12 14:42:12 +00:00
|
|
|
files: vec![],
|
2020-08-12 13:47:44 +00:00
|
|
|
rules: true,
|
2021-11-04 15:12:12 +00:00
|
|
|
maybe_rules_tags: None,
|
|
|
|
maybe_rules_include: None,
|
|
|
|
maybe_rules_exclude: None,
|
2021-09-03 15:01:58 +00:00
|
|
|
json: false,
|
|
|
|
ignore: vec![],
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2021-09-03 15:01:58 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
let r = flags_from_vec(svec![
|
|
|
|
"deno",
|
|
|
|
"lint",
|
|
|
|
"--rules-tags=",
|
|
|
|
"--rules-include=ban-untagged-todo,no-undef",
|
|
|
|
"--rules-exclude=no-const-assign"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Lint(LintFlags {
|
2021-09-03 15:01:58 +00:00
|
|
|
files: vec![],
|
|
|
|
rules: false,
|
2021-11-04 15:12:12 +00:00
|
|
|
maybe_rules_tags: Some(svec![""]),
|
|
|
|
maybe_rules_include: Some(svec!["ban-untagged-todo", "no-undef"]),
|
|
|
|
maybe_rules_exclude: Some(svec!["no-const-assign"]),
|
2020-08-13 15:30:46 +00:00
|
|
|
json: false,
|
|
|
|
ignore: vec![],
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-08-13 15:30:46 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-04-27 10:44:36 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "lint", "--json", "script_1.ts"]);
|
2020-08-13 15:30:46 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Lint(LintFlags {
|
2020-10-21 11:12:01 +00:00
|
|
|
files: vec![PathBuf::from("script_1.ts")],
|
2020-08-13 15:30:46 +00:00
|
|
|
rules: false,
|
2021-11-04 15:12:12 +00:00
|
|
|
maybe_rules_tags: None,
|
|
|
|
maybe_rules_include: None,
|
|
|
|
maybe_rules_exclude: None,
|
2021-09-03 15:01:58 +00:00
|
|
|
json: true,
|
|
|
|
ignore: vec![],
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2021-09-03 15:01:58 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
let r = flags_from_vec(svec![
|
|
|
|
"deno",
|
|
|
|
"lint",
|
|
|
|
"--config",
|
|
|
|
"Deno.jsonc",
|
|
|
|
"--json",
|
|
|
|
"script_1.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Lint(LintFlags {
|
2021-09-03 15:01:58 +00:00
|
|
|
files: vec![PathBuf::from("script_1.ts")],
|
|
|
|
rules: false,
|
2021-11-04 15:12:12 +00:00
|
|
|
maybe_rules_tags: None,
|
|
|
|
maybe_rules_include: None,
|
|
|
|
maybe_rules_exclude: None,
|
2020-08-13 15:30:46 +00:00
|
|
|
json: true,
|
2020-08-12 13:47:44 +00:00
|
|
|
ignore: vec![],
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2021-09-03 15:01:58 +00:00
|
|
|
config_path: Some("Deno.jsonc".to_string()),
|
2020-06-10 21:29:48 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-04-29 23:43:06 +00:00
|
|
|
#[test]
|
2019-11-26 16:06:32 +00:00
|
|
|
fn types() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "types"]);
|
2019-11-26 16:06:32 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2019-11-26 16:06:32 +00:00
|
|
|
subcommand: DenoSubcommand::Types,
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
|
|
|
);
|
2019-04-29 23:43:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-04-07 15:24:47 +00:00
|
|
|
fn cache() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "cache", "script.ts"]);
|
2019-11-26 16:06:32 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Cache(CacheFlags {
|
2020-02-04 19:24:33 +00:00
|
|
|
files: svec!["script.ts"],
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
|
|
|
);
|
2019-04-29 23:43:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-11-26 16:06:32 +00:00
|
|
|
fn info() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "info", "script.ts"]);
|
2019-11-26 16:06:32 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Info(InfoFlags {
|
2020-07-08 14:50:12 +00:00
|
|
|
json: false,
|
|
|
|
file: Some("script.ts".to_string()),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-07-08 14:50:12 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "info", "--reload", "script.ts"]);
|
2020-08-12 10:58:50 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Info(InfoFlags {
|
2020-08-12 10:58:50 +00:00
|
|
|
json: false,
|
|
|
|
file: Some("script.ts".to_string()),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-08-12 10:58:50 +00:00
|
|
|
reload: true,
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "info", "--json", "script.ts"]);
|
2020-07-08 14:50:12 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Info(InfoFlags {
|
2020-07-08 14:50:12 +00:00
|
|
|
json: true,
|
2020-02-04 19:24:33 +00:00
|
|
|
file: Some("script.ts".to_string()),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
|
|
|
);
|
2019-08-12 00:43:01 +00:00
|
|
|
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "info"]);
|
2019-11-26 16:06:32 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Info(InfoFlags {
|
2020-07-08 14:50:12 +00:00
|
|
|
json: false,
|
|
|
|
file: None
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-07-08 14:50:12 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "info", "--json"]);
|
2020-07-08 14:50:12 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Info(InfoFlags {
|
2020-07-08 14:50:12 +00:00
|
|
|
json: true,
|
|
|
|
file: None
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
|
|
|
);
|
2019-04-21 15:34:18 +00:00
|
|
|
}
|
2019-04-29 14:58:31 +00:00
|
|
|
|
2019-05-03 20:24:09 +00:00
|
|
|
#[test]
|
2019-11-26 16:06:32 +00:00
|
|
|
fn tsconfig() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r =
|
|
|
|
flags_from_vec(svec!["deno", "run", "-c", "tsconfig.json", "script.ts"]);
|
2019-05-03 21:15:16 +00:00
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-02-04 19:24:33 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2019-05-03 21:15:16 +00:00
|
|
|
config_path: Some("tsconfig.json".to_owned()),
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-05-03 21:15:16 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-11-26 16:06:32 +00:00
|
|
|
fn eval() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "eval", "'console.log(\"hello\")'"]);
|
2019-05-03 21:15:16 +00:00
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Eval(EvalFlags {
|
2020-05-21 14:35:36 +00:00
|
|
|
print: false,
|
2020-02-04 19:24:33 +00:00
|
|
|
code: "'console.log(\"hello\")'".to_string(),
|
2021-02-21 16:58:32 +00:00
|
|
|
ext: "js".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_net: Some(vec![]),
|
2021-04-13 11:25:21 +00:00
|
|
|
allow_env: Some(vec![]),
|
2021-04-09 22:12:00 +00:00
|
|
|
allow_run: Some(vec![]),
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_read: Some(vec![]),
|
|
|
|
allow_write: Some(vec![]),
|
2021-08-06 21:28:10 +00:00
|
|
|
allow_ffi: Some(vec![]),
|
2020-02-28 14:17:56 +00:00
|
|
|
allow_hrtime: true,
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-05-21 14:35:36 +00:00
|
|
|
#[test]
|
|
|
|
fn eval_p() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "eval", "-p", "1+2"]);
|
2020-05-21 14:35:36 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Eval(EvalFlags {
|
2020-05-21 14:35:36 +00:00
|
|
|
print: true,
|
|
|
|
code: "1+2".to_string(),
|
2021-02-21 16:58:32 +00:00
|
|
|
ext: "js".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_net: Some(vec![]),
|
2021-04-13 11:25:21 +00:00
|
|
|
allow_env: Some(vec![]),
|
2021-04-09 22:12:00 +00:00
|
|
|
allow_run: Some(vec![]),
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_read: Some(vec![]),
|
|
|
|
allow_write: Some(vec![]),
|
2021-08-06 21:28:10 +00:00
|
|
|
allow_ffi: Some(vec![]),
|
2020-05-21 14:35:36 +00:00
|
|
|
allow_hrtime: true,
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-02-28 14:17:56 +00:00
|
|
|
#[test]
|
|
|
|
fn eval_typescript() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r =
|
|
|
|
flags_from_vec(svec!["deno", "eval", "-T", "'console.log(\"hello\")'"]);
|
2020-02-28 14:17:56 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Eval(EvalFlags {
|
2020-05-21 14:35:36 +00:00
|
|
|
print: false,
|
2020-02-28 14:17:56 +00:00
|
|
|
code: "'console.log(\"hello\")'".to_string(),
|
2021-02-21 16:58:32 +00:00
|
|
|
ext: "ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_net: Some(vec![]),
|
2021-04-13 11:25:21 +00:00
|
|
|
allow_env: Some(vec![]),
|
2021-04-09 22:12:00 +00:00
|
|
|
allow_run: Some(vec![]),
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_read: Some(vec![]),
|
|
|
|
allow_write: Some(vec![]),
|
2021-08-06 21:28:10 +00:00
|
|
|
allow_ffi: Some(vec![]),
|
2019-05-23 16:28:29 +00:00
|
|
|
allow_hrtime: true,
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-05-03 21:15:16 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-01-26 14:49:34 +00:00
|
|
|
#[test]
|
2020-09-18 17:09:11 +00:00
|
|
|
fn eval_with_flags() {
|
|
|
|
#[rustfmt::skip]
|
2021-03-01 11:41:22 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "eval", "--import-map", "import_map.json", "--no-remote", "--config", "tsconfig.json", "--no-check", "--reload", "--lock", "lock.json", "--lock-write", "--cert", "example.crt", "--cached-only", "--location", "https:foo", "--v8-flags=--help", "--seed", "1", "--inspect=127.0.0.1:9229", "42"]);
|
2020-01-26 14:49:34 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Eval(EvalFlags {
|
2020-05-21 14:35:36 +00:00
|
|
|
print: false,
|
2020-02-04 19:24:33 +00:00
|
|
|
code: "42".to_string(),
|
2021-02-21 16:58:32 +00:00
|
|
|
ext: "js".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-09-18 17:09:11 +00:00
|
|
|
import_map_path: Some("import_map.json".to_string()),
|
|
|
|
no_remote: true,
|
|
|
|
config_path: Some("tsconfig.json".to_string()),
|
2021-11-29 22:23:30 +00:00
|
|
|
check: CheckFlag::None,
|
2020-09-18 17:09:11 +00:00
|
|
|
reload: true,
|
2020-10-19 19:19:20 +00:00
|
|
|
lock: Some(PathBuf::from("lock.json")),
|
2020-09-18 17:09:11 +00:00
|
|
|
lock_write: true,
|
|
|
|
ca_file: Some("example.crt".to_string()),
|
|
|
|
cached_only: true,
|
2021-01-07 18:06:08 +00:00
|
|
|
location: Some(Url::parse("https://foo/").unwrap()),
|
2020-12-06 17:19:21 +00:00
|
|
|
v8_flags: svec!["--help", "--random-seed=1"],
|
2020-09-18 17:09:11 +00:00
|
|
|
seed: Some(1),
|
|
|
|
inspect: Some("127.0.0.1:9229".parse().unwrap()),
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_net: Some(vec![]),
|
2021-04-13 11:25:21 +00:00
|
|
|
allow_env: Some(vec![]),
|
2021-04-09 22:12:00 +00:00
|
|
|
allow_run: Some(vec![]),
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_read: Some(vec![]),
|
|
|
|
allow_write: Some(vec![]),
|
2021-08-06 21:28:10 +00:00
|
|
|
allow_ffi: Some(vec![]),
|
2020-01-26 14:49:34 +00:00
|
|
|
allow_hrtime: true,
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2020-01-26 14:49:34 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-11-30 02:10:21 +00:00
|
|
|
#[test]
|
|
|
|
fn eval_args() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2020-11-30 02:10:21 +00:00
|
|
|
"deno",
|
|
|
|
"eval",
|
|
|
|
"console.log(Deno.args)",
|
|
|
|
"arg1",
|
|
|
|
"arg2"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Eval(EvalFlags {
|
2020-11-30 02:10:21 +00:00
|
|
|
print: false,
|
|
|
|
code: "console.log(Deno.args)".to_string(),
|
2021-02-21 16:58:32 +00:00
|
|
|
ext: "js".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-11-30 02:10:21 +00:00
|
|
|
argv: svec!["arg1", "arg2"],
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_net: Some(vec![]),
|
2021-04-13 11:25:21 +00:00
|
|
|
allow_env: Some(vec![]),
|
2021-04-09 22:12:00 +00:00
|
|
|
allow_run: Some(vec![]),
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_read: Some(vec![]),
|
|
|
|
allow_write: Some(vec![]),
|
2021-08-06 21:28:10 +00:00
|
|
|
allow_ffi: Some(vec![]),
|
2020-11-30 02:10:21 +00:00
|
|
|
allow_hrtime: true,
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-05-03 21:15:16 +00:00
|
|
|
#[test]
|
2019-11-26 16:06:32 +00:00
|
|
|
fn repl() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno"]);
|
2019-05-03 21:15:16 +00:00
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2020-10-01 23:14:55 +00:00
|
|
|
repl: true,
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Repl(ReplFlags { eval: None }),
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_net: Some(vec![]),
|
2021-08-10 11:19:45 +00:00
|
|
|
unsafely_ignore_certificate_errors: None,
|
2021-04-13 11:25:21 +00:00
|
|
|
allow_env: Some(vec![]),
|
2021-04-09 22:12:00 +00:00
|
|
|
allow_run: Some(vec![]),
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_read: Some(vec![]),
|
|
|
|
allow_write: Some(vec![]),
|
2021-08-06 21:28:10 +00:00
|
|
|
allow_ffi: Some(vec![]),
|
2019-05-23 16:28:29 +00:00
|
|
|
allow_hrtime: true,
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-05-03 21:15:16 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-04-30 15:23:40 +00:00
|
|
|
#[test]
|
2020-09-18 17:09:11 +00:00
|
|
|
fn repl_with_flags() {
|
|
|
|
#[rustfmt::skip]
|
2021-12-10 14:47:55 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "repl", "--import-map", "import_map.json", "--no-remote", "--config", "tsconfig.json", "--no-check", "--reload", "--lock", "lock.json", "--lock-write", "--cert", "example.crt", "--cached-only", "--location", "https:foo", "--v8-flags=--help", "--seed", "1", "--inspect=127.0.0.1:9229", "--unsafely-ignore-certificate-errors"]);
|
2020-04-30 15:23:40 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2020-10-01 23:14:55 +00:00
|
|
|
repl: true,
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Repl(ReplFlags { eval: None }),
|
2020-09-18 17:09:11 +00:00
|
|
|
import_map_path: Some("import_map.json".to_string()),
|
|
|
|
no_remote: true,
|
|
|
|
config_path: Some("tsconfig.json".to_string()),
|
2021-11-29 22:23:30 +00:00
|
|
|
check: CheckFlag::None,
|
2020-09-18 17:09:11 +00:00
|
|
|
reload: true,
|
2020-10-19 19:19:20 +00:00
|
|
|
lock: Some(PathBuf::from("lock.json")),
|
2020-09-18 17:09:11 +00:00
|
|
|
lock_write: true,
|
|
|
|
ca_file: Some("example.crt".to_string()),
|
|
|
|
cached_only: true,
|
2021-01-07 18:06:08 +00:00
|
|
|
location: Some(Url::parse("https://foo/").unwrap()),
|
2020-12-06 17:19:21 +00:00
|
|
|
v8_flags: svec!["--help", "--random-seed=1"],
|
2020-09-18 17:09:11 +00:00
|
|
|
seed: Some(1),
|
|
|
|
inspect: Some("127.0.0.1:9229".parse().unwrap()),
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_net: Some(vec![]),
|
2021-04-13 11:25:21 +00:00
|
|
|
allow_env: Some(vec![]),
|
2021-04-09 22:12:00 +00:00
|
|
|
allow_run: Some(vec![]),
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_read: Some(vec![]),
|
|
|
|
allow_write: Some(vec![]),
|
2021-08-06 21:28:10 +00:00
|
|
|
allow_ffi: Some(vec![]),
|
2020-04-30 15:23:40 +00:00
|
|
|
allow_hrtime: true,
|
2021-12-10 14:47:55 +00:00
|
|
|
unsafely_ignore_certificate_errors: Some(vec![]),
|
2020-04-30 15:23:40 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-08-06 21:30:28 +00:00
|
|
|
#[test]
|
|
|
|
fn repl_with_eval_flag() {
|
|
|
|
#[rustfmt::skip]
|
|
|
|
let r = flags_from_vec(svec!["deno", "repl", "--eval", "console.log('hello');"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
repl: true,
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Repl(ReplFlags {
|
2021-08-06 21:30:28 +00:00
|
|
|
eval: Some("console.log('hello');".to_string()),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2021-08-06 21:30:28 +00:00
|
|
|
allow_net: Some(vec![]),
|
|
|
|
allow_env: Some(vec![]),
|
|
|
|
allow_run: Some(vec![]),
|
|
|
|
allow_read: Some(vec![]),
|
|
|
|
allow_write: Some(vec![]),
|
2021-08-06 22:09:19 +00:00
|
|
|
allow_ffi: Some(vec![]),
|
2021-08-06 21:30:28 +00:00
|
|
|
allow_hrtime: true,
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-05-08 23:20:30 +00:00
|
|
|
#[test]
|
2020-06-13 17:09:39 +00:00
|
|
|
fn allow_read_allowlist() {
|
2019-05-09 16:20:34 +00:00
|
|
|
use tempfile::TempDir;
|
2020-02-11 09:29:36 +00:00
|
|
|
let temp_dir = TempDir::new().expect("tempdir fail").path().to_path_buf();
|
2019-05-09 16:20:34 +00:00
|
|
|
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2019-05-08 23:20:30 +00:00
|
|
|
"deno",
|
|
|
|
"run",
|
2020-02-11 09:29:36 +00:00
|
|
|
format!("--allow-read=.,{}", temp_dir.to_str().unwrap()),
|
2019-05-08 23:20:30 +00:00
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_read: Some(vec![PathBuf::from("."), temp_dir]),
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-02-04 19:24:33 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-05-08 23:20:30 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2019-06-09 13:08:20 +00:00
|
|
|
|
2019-05-08 23:20:30 +00:00
|
|
|
#[test]
|
2020-06-13 17:09:39 +00:00
|
|
|
fn allow_write_allowlist() {
|
2019-05-09 16:20:34 +00:00
|
|
|
use tempfile::TempDir;
|
2020-02-11 09:29:36 +00:00
|
|
|
let temp_dir = TempDir::new().expect("tempdir fail").path().to_path_buf();
|
2019-05-09 16:20:34 +00:00
|
|
|
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2019-05-08 23:20:30 +00:00
|
|
|
"deno",
|
|
|
|
"run",
|
2020-02-11 09:29:36 +00:00
|
|
|
format!("--allow-write=.,{}", temp_dir.to_str().unwrap()),
|
2019-05-08 23:20:30 +00:00
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_write: Some(vec![PathBuf::from("."), temp_dir]),
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-02-04 19:24:33 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-05-08 23:20:30 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2019-06-09 13:08:20 +00:00
|
|
|
|
2019-05-08 23:20:30 +00:00
|
|
|
#[test]
|
2020-06-13 17:09:39 +00:00
|
|
|
fn allow_net_allowlist() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2019-05-08 23:20:30 +00:00
|
|
|
"deno",
|
|
|
|
"run",
|
|
|
|
"--allow-net=127.0.0.1",
|
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-02-04 19:24:33 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_net: Some(svec!["127.0.0.1"]),
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-05-08 23:20:30 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2019-06-01 12:54:32 +00:00
|
|
|
|
2021-04-13 11:25:21 +00:00
|
|
|
#[test]
|
|
|
|
fn allow_env_allowlist() {
|
|
|
|
let r =
|
|
|
|
flags_from_vec(svec!["deno", "run", "--allow-env=HOME", "script.ts"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2021-04-13 11:25:21 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2021-04-13 11:25:21 +00:00
|
|
|
allow_env: Some(svec!["HOME"]),
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn allow_env_allowlist_multiple() {
|
|
|
|
let r = flags_from_vec(svec![
|
|
|
|
"deno",
|
|
|
|
"run",
|
|
|
|
"--allow-env=HOME,PATH",
|
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2021-04-13 11:25:21 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2021-04-13 11:25:21 +00:00
|
|
|
allow_env: Some(svec!["HOME", "PATH"]),
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn allow_env_allowlist_validator() {
|
|
|
|
let r =
|
|
|
|
flags_from_vec(svec!["deno", "run", "--allow-env=HOME", "script.ts"]);
|
|
|
|
assert!(r.is_ok());
|
|
|
|
let r =
|
|
|
|
flags_from_vec(svec!["deno", "run", "--allow-env=H=ME", "script.ts"]);
|
|
|
|
assert!(r.is_err());
|
|
|
|
let r =
|
|
|
|
flags_from_vec(svec!["deno", "run", "--allow-env=H\0ME", "script.ts"]);
|
|
|
|
assert!(r.is_err());
|
|
|
|
}
|
|
|
|
|
2019-06-08 18:42:28 +00:00
|
|
|
#[test]
|
2019-11-26 16:06:32 +00:00
|
|
|
fn bundle() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "bundle", "source.ts"]);
|
2019-06-08 18:42:28 +00:00
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Bundle(BundleFlags {
|
2020-02-04 19:24:33 +00:00
|
|
|
source_file: "source.ts".to_string(),
|
|
|
|
out_file: None,
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-05-07 15:02:03 +00:00
|
|
|
#[test]
|
|
|
|
fn bundle_with_config() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2020-05-07 15:02:03 +00:00
|
|
|
"deno",
|
|
|
|
"bundle",
|
2020-09-18 17:09:11 +00:00
|
|
|
"--no-remote",
|
2020-05-07 15:02:03 +00:00
|
|
|
"--config",
|
|
|
|
"tsconfig.json",
|
|
|
|
"source.ts",
|
|
|
|
"bundle.js"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Bundle(BundleFlags {
|
2020-05-07 15:02:03 +00:00
|
|
|
source_file: "source.ts".to_string(),
|
|
|
|
out_file: Some(PathBuf::from("bundle.js")),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_write: Some(vec![]),
|
2020-09-18 17:09:11 +00:00
|
|
|
no_remote: true,
|
2020-05-07 15:02:03 +00:00
|
|
|
config_path: Some("tsconfig.json".to_owned()),
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-11-26 16:06:32 +00:00
|
|
|
#[test]
|
|
|
|
fn bundle_with_output() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "bundle", "source.ts", "bundle.js"]);
|
2019-11-26 16:06:32 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Bundle(BundleFlags {
|
2020-02-04 19:24:33 +00:00
|
|
|
source_file: "source.ts".to_string(),
|
2020-02-11 09:29:36 +00:00
|
|
|
out_file: Some(PathBuf::from("bundle.js")),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_write: Some(vec![]),
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2020-07-07 11:05:28 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn bundle_with_lock() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2020-07-07 11:05:28 +00:00
|
|
|
"deno",
|
|
|
|
"bundle",
|
|
|
|
"--lock-write",
|
|
|
|
"--lock=lock.json",
|
|
|
|
"source.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Bundle(BundleFlags {
|
2020-07-07 11:05:28 +00:00
|
|
|
source_file: "source.ts".to_string(),
|
|
|
|
out_file: None,
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-07-07 11:05:28 +00:00
|
|
|
lock_write: true,
|
2020-10-19 19:19:20 +00:00
|
|
|
lock: Some(PathBuf::from("lock.json")),
|
2020-07-07 11:05:28 +00:00
|
|
|
..Flags::default()
|
2019-06-08 18:42:28 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2019-06-09 13:08:20 +00:00
|
|
|
|
2020-08-12 15:32:03 +00:00
|
|
|
#[test]
|
|
|
|
fn bundle_with_reload() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "bundle", "--reload", "source.ts"]);
|
2020-08-12 15:32:03 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
reload: true,
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Bundle(BundleFlags {
|
2020-08-12 15:32:03 +00:00
|
|
|
source_file: "source.ts".to_string(),
|
|
|
|
out_file: None,
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-08-12 15:32:03 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-10-20 03:10:42 +00:00
|
|
|
#[test]
|
|
|
|
fn bundle_nocheck() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "bundle", "--no-check", "script.ts"])
|
|
|
|
.unwrap();
|
2020-10-20 03:10:42 +00:00
|
|
|
assert_eq!(
|
|
|
|
r,
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Bundle(BundleFlags {
|
2020-10-20 03:10:42 +00:00
|
|
|
source_file: "script.ts".to_string(),
|
|
|
|
out_file: None,
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2021-11-29 22:23:30 +00:00
|
|
|
check: CheckFlag::None,
|
2020-10-20 03:10:42 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-11-22 20:45:44 +00:00
|
|
|
#[test]
|
|
|
|
fn bundle_watch() {
|
2021-04-27 10:44:36 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "bundle", "--watch", "source.ts"]);
|
2020-11-22 20:45:44 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Bundle(BundleFlags {
|
2020-11-22 20:45:44 +00:00
|
|
|
source_file: "source.ts".to_string(),
|
|
|
|
out_file: None,
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2021-12-15 21:04:43 +00:00
|
|
|
watch: Some(vec![]),
|
2020-11-22 20:45:44 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-06-09 13:08:20 +00:00
|
|
|
#[test]
|
2020-10-20 12:30:59 +00:00
|
|
|
fn run_import_map() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2019-06-09 13:08:20 +00:00
|
|
|
"deno",
|
|
|
|
"run",
|
2020-10-20 12:30:59 +00:00
|
|
|
"--import-map=import_map.json",
|
2019-06-09 13:08:20 +00:00
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-02-04 19:24:33 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-10-20 12:30:59 +00:00
|
|
|
import_map_path: Some("import_map.json".to_owned()),
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-06-09 13:08:20 +00:00
|
|
|
}
|
|
|
|
);
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
2019-06-09 13:08:20 +00:00
|
|
|
|
2020-09-21 13:07:19 +00:00
|
|
|
#[test]
|
2020-10-20 12:30:59 +00:00
|
|
|
fn info_import_map() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2020-09-21 13:07:19 +00:00
|
|
|
"deno",
|
|
|
|
"info",
|
2020-10-20 12:30:59 +00:00
|
|
|
"--import-map=import_map.json",
|
2020-09-21 13:07:19 +00:00
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Info(InfoFlags {
|
2020-09-21 13:07:19 +00:00
|
|
|
file: Some("script.ts".to_string()),
|
|
|
|
json: false,
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-10-20 12:30:59 +00:00
|
|
|
import_map_path: Some("import_map.json".to_owned()),
|
2020-09-21 13:07:19 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-11-26 16:06:32 +00:00
|
|
|
#[test]
|
2020-10-20 12:30:59 +00:00
|
|
|
fn cache_import_map() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2019-07-27 14:37:03 +00:00
|
|
|
"deno",
|
2020-04-07 15:24:47 +00:00
|
|
|
"cache",
|
2020-10-20 12:30:59 +00:00
|
|
|
"--import-map=import_map.json",
|
2019-07-27 14:37:03 +00:00
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Cache(CacheFlags {
|
2020-02-04 19:24:33 +00:00
|
|
|
files: svec!["script.ts"],
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-10-20 12:30:59 +00:00
|
|
|
import_map_path: Some("import_map.json".to_owned()),
|
2020-10-11 23:05:46 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-10-20 12:30:59 +00:00
|
|
|
fn doc_import_map() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2020-10-11 23:05:46 +00:00
|
|
|
"deno",
|
|
|
|
"doc",
|
2020-10-20 12:30:59 +00:00
|
|
|
"--import-map=import_map.json",
|
2020-10-11 23:05:46 +00:00
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Doc(DocFlags {
|
2020-10-11 23:05:46 +00:00
|
|
|
source_file: Some("script.ts".to_owned()),
|
|
|
|
private: false,
|
|
|
|
json: false,
|
|
|
|
filter: None,
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-10-20 12:30:59 +00:00
|
|
|
import_map_path: Some("import_map.json".to_owned()),
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-07-27 14:37:03 +00:00
|
|
|
}
|
|
|
|
);
|
2019-06-09 13:08:20 +00:00
|
|
|
}
|
2019-06-11 14:34:39 +00:00
|
|
|
|
2020-01-31 21:07:37 +00:00
|
|
|
#[test]
|
2020-04-07 15:24:47 +00:00
|
|
|
fn cache_multiple() {
|
2020-01-31 21:07:37 +00:00
|
|
|
let r =
|
2021-01-07 18:06:08 +00:00
|
|
|
flags_from_vec(svec!["deno", "cache", "script.ts", "script_two.ts"]);
|
2020-01-31 21:07:37 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Cache(CacheFlags {
|
2020-02-04 19:24:33 +00:00
|
|
|
files: svec!["script.ts", "script_two.ts"],
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2020-01-31 21:07:37 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-11 14:34:39 +00:00
|
|
|
#[test]
|
2019-11-26 16:06:32 +00:00
|
|
|
fn run_seed() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "run", "--seed", "250", "script.ts"]);
|
2019-06-11 14:34:39 +00:00
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-02-04 19:24:33 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-11-27 19:47:35 +00:00
|
|
|
seed: Some(250_u64),
|
2020-12-06 17:19:21 +00:00
|
|
|
v8_flags: svec!["--random-seed=250"],
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-06-11 14:34:39 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-11-26 16:06:32 +00:00
|
|
|
fn run_seed_with_v8_flags() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2019-06-11 14:34:39 +00:00
|
|
|
"deno",
|
2019-11-26 16:06:32 +00:00
|
|
|
"run",
|
2019-06-11 14:34:39 +00:00
|
|
|
"--seed",
|
|
|
|
"250",
|
|
|
|
"--v8-flags=--expose-gc",
|
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-02-04 19:24:33 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-11-27 19:47:35 +00:00
|
|
|
seed: Some(250_u64),
|
2020-12-06 17:19:21 +00:00
|
|
|
v8_flags: svec!["--expose-gc", "--random-seed=250"],
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-06-11 14:34:39 +00:00
|
|
|
}
|
|
|
|
);
|
2019-06-15 14:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-11-26 16:06:32 +00:00
|
|
|
fn install() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2019-06-15 14:08:11 +00:00
|
|
|
"deno",
|
|
|
|
"install",
|
|
|
|
"https://deno.land/std/examples/colors.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Install(InstallFlags {
|
2020-05-01 19:33:11 +00:00
|
|
|
name: None,
|
2020-01-30 23:42:39 +00:00
|
|
|
module_url: "https://deno.land/std/examples/colors.ts".to_string(),
|
|
|
|
args: vec![],
|
2020-05-01 19:33:11 +00:00
|
|
|
root: None,
|
2020-02-08 08:49:55 +00:00
|
|
|
force: false,
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-06-15 14:08:11 +00:00
|
|
|
}
|
|
|
|
);
|
2019-11-26 16:06:32 +00:00
|
|
|
}
|
2019-06-15 14:08:11 +00:00
|
|
|
|
2019-11-26 16:06:32 +00:00
|
|
|
#[test]
|
2020-10-19 19:19:20 +00:00
|
|
|
fn install_with_flags() {
|
|
|
|
#[rustfmt::skip]
|
2021-08-10 11:19:45 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "install", "--import-map", "import_map.json", "--no-remote", "--config", "tsconfig.json", "--no-check", "--unsafely-ignore-certificate-errors", "--reload", "--lock", "lock.json", "--lock-write", "--cert", "example.crt", "--cached-only", "--allow-read", "--allow-net", "--v8-flags=--help", "--seed", "1", "--inspect=127.0.0.1:9229", "--name", "file_server", "--root", "/foo", "--force", "https://deno.land/std/http/file_server.ts", "foo", "bar"]);
|
2019-06-20 18:25:13 +00:00
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Install(InstallFlags {
|
2020-05-01 19:33:11 +00:00
|
|
|
name: Some("file_server".to_string()),
|
2020-01-30 23:42:39 +00:00
|
|
|
module_url: "https://deno.land/std/http/file_server.ts".to_string(),
|
2020-10-19 19:19:20 +00:00
|
|
|
args: svec!["foo", "bar"],
|
|
|
|
root: Some(PathBuf::from("/foo")),
|
2020-02-08 08:49:55 +00:00
|
|
|
force: true,
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-10-19 19:19:20 +00:00
|
|
|
import_map_path: Some("import_map.json".to_string()),
|
|
|
|
no_remote: true,
|
|
|
|
config_path: Some("tsconfig.json".to_string()),
|
2021-11-29 22:23:30 +00:00
|
|
|
check: CheckFlag::None,
|
2020-10-19 19:19:20 +00:00
|
|
|
reload: true,
|
|
|
|
lock: Some(PathBuf::from("lock.json")),
|
|
|
|
lock_write: true,
|
|
|
|
ca_file: Some("example.crt".to_string()),
|
|
|
|
cached_only: true,
|
2020-12-06 17:19:21 +00:00
|
|
|
v8_flags: svec!["--help", "--random-seed=1"],
|
2020-10-19 19:19:20 +00:00
|
|
|
seed: Some(1),
|
|
|
|
inspect: Some("127.0.0.1:9229".parse().unwrap()),
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_net: Some(vec![]),
|
2021-08-10 11:19:45 +00:00
|
|
|
unsafely_ignore_certificate_errors: Some(vec![]),
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_read: Some(vec![]),
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-06-20 18:25:13 +00:00
|
|
|
}
|
|
|
|
);
|
2019-06-11 14:34:39 +00:00
|
|
|
}
|
2019-06-22 16:02:51 +00:00
|
|
|
|
|
|
|
#[test]
|
2019-11-26 16:06:32 +00:00
|
|
|
fn log_level() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r =
|
|
|
|
flags_from_vec(svec!["deno", "run", "--log-level=debug", "script.ts"]);
|
2019-06-22 16:02:51 +00:00
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-02-04 19:24:33 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2019-06-22 16:02:51 +00:00
|
|
|
log_level: Some(Level::Debug),
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-06-22 16:02:51 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2019-06-26 10:02:13 +00:00
|
|
|
|
2020-03-10 12:26:17 +00:00
|
|
|
#[test]
|
|
|
|
fn quiet() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "run", "-q", "script.ts"]);
|
2020-03-10 12:26:17 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-03-10 12:26:17 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-03-10 12:26:17 +00:00
|
|
|
log_level: Some(Level::Error),
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-26 10:02:13 +00:00
|
|
|
#[test]
|
2019-11-26 16:06:32 +00:00
|
|
|
fn completions() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "completions", "zsh"]).unwrap();
|
2020-02-04 19:24:33 +00:00
|
|
|
|
|
|
|
match r.subcommand {
|
2021-09-03 23:33:35 +00:00
|
|
|
DenoSubcommand::Completions(CompletionsFlags { buf }) => {
|
|
|
|
assert!(!buf.is_empty())
|
|
|
|
}
|
2020-02-04 19:24:33 +00:00
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
2019-06-26 10:02:13 +00:00
|
|
|
}
|
2019-06-29 22:32:54 +00:00
|
|
|
|
|
|
|
#[test]
|
2020-08-28 23:20:57 +00:00
|
|
|
fn run_with_args() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2020-08-28 23:20:57 +00:00
|
|
|
"deno",
|
|
|
|
"run",
|
|
|
|
"script.ts",
|
|
|
|
"--allow-read",
|
|
|
|
"--allow-net"
|
|
|
|
]);
|
2019-06-29 22:32:54 +00:00
|
|
|
assert_eq!(
|
2020-08-28 23:20:57 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-08-28 23:20:57 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-08-28 23:20:57 +00:00
|
|
|
argv: svec!["--allow-read", "--allow-net"],
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-06-29 22:32:54 +00:00
|
|
|
}
|
|
|
|
);
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2019-06-29 22:32:54 +00:00
|
|
|
"deno",
|
|
|
|
"run",
|
2021-01-07 18:06:08 +00:00
|
|
|
"--location",
|
|
|
|
"https:foo",
|
2019-11-26 16:06:32 +00:00
|
|
|
"--allow-read",
|
2019-06-29 22:32:54 +00:00
|
|
|
"script.ts",
|
|
|
|
"--allow-net",
|
|
|
|
"-r",
|
|
|
|
"--help",
|
|
|
|
"--foo",
|
|
|
|
"bar"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2020-08-28 23:20:57 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-08-28 23:20:57 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2021-01-07 18:06:08 +00:00
|
|
|
location: Some(Url::parse("https://foo/").unwrap()),
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_read: Some(vec![]),
|
2020-08-28 23:20:57 +00:00
|
|
|
argv: svec!["--allow-net", "-r", "--help", "--foo", "bar"],
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-06-29 22:32:54 +00:00
|
|
|
}
|
|
|
|
);
|
2020-08-28 23:20:57 +00:00
|
|
|
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "run", "script.ts", "foo", "bar"]);
|
2020-08-28 23:20:57 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-08-28 23:20:57 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-08-28 23:20:57 +00:00
|
|
|
argv: svec!["foo", "bar"],
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "run", "script.ts", "-"]);
|
2020-08-28 23:20:57 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-08-28 23:20:57 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-08-28 23:20:57 +00:00
|
|
|
argv: svec!["-"],
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
let r =
|
2021-01-07 18:06:08 +00:00
|
|
|
flags_from_vec(svec!["deno", "run", "script.ts", "-", "foo", "bar"]);
|
2020-08-28 23:20:57 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-08-28 23:20:57 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-08-28 23:20:57 +00:00
|
|
|
argv: svec!["-", "foo", "bar"],
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2019-07-20 13:19:06 +00:00
|
|
|
|
2020-07-08 09:26:39 +00:00
|
|
|
#[test]
|
|
|
|
fn no_check() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "run", "--no-check", "script.ts"]);
|
2020-07-08 09:26:39 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-07-08 09:26:39 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2021-11-29 22:23:30 +00:00
|
|
|
check: CheckFlag::None,
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn no_check_remote() {
|
|
|
|
let r =
|
|
|
|
flags_from_vec(svec!["deno", "run", "--no-check=remote", "script.ts"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
|
|
|
script: "script.ts".to_string(),
|
|
|
|
}),
|
|
|
|
check: CheckFlag::Local,
|
2020-07-08 09:26:39 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-08-09 14:53:21 +00:00
|
|
|
#[test]
|
2021-12-10 14:47:55 +00:00
|
|
|
fn repl_with_unsafely_ignore_certificate_errors() {
|
|
|
|
let r = flags_from_vec(svec![
|
|
|
|
"deno",
|
|
|
|
"repl",
|
|
|
|
"--eval",
|
|
|
|
"console.log('hello');",
|
|
|
|
"--unsafely-ignore-certificate-errors"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
repl: true,
|
|
|
|
subcommand: DenoSubcommand::Repl(ReplFlags {
|
|
|
|
eval: Some("console.log('hello');".to_string()),
|
|
|
|
}),
|
|
|
|
unsafely_ignore_certificate_errors: Some(vec![]),
|
|
|
|
allow_net: Some(vec![]),
|
|
|
|
allow_env: Some(vec![]),
|
|
|
|
allow_run: Some(vec![]),
|
|
|
|
allow_read: Some(vec![]),
|
|
|
|
allow_write: Some(vec![]),
|
|
|
|
allow_ffi: Some(vec![]),
|
|
|
|
allow_hrtime: true,
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn run_with_unsafely_ignore_certificate_errors() {
|
2021-08-09 14:53:21 +00:00
|
|
|
let r = flags_from_vec(svec![
|
|
|
|
"deno",
|
|
|
|
"run",
|
2021-08-10 11:19:45 +00:00
|
|
|
"--unsafely-ignore-certificate-errors",
|
2021-08-09 14:53:21 +00:00
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2021-08-09 14:53:21 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2021-08-10 11:19:45 +00:00
|
|
|
unsafely_ignore_certificate_errors: Some(vec![]),
|
2021-08-09 14:53:21 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-12-10 14:47:55 +00:00
|
|
|
fn run_with_unsafely_treat_insecure_origin_as_secure_with_ipv6_address() {
|
2021-08-09 14:53:21 +00:00
|
|
|
let r = flags_from_vec(svec![
|
|
|
|
"deno",
|
|
|
|
"run",
|
2021-08-10 11:19:45 +00:00
|
|
|
"--unsafely-ignore-certificate-errors=deno.land,localhost,::,127.0.0.1,[::1],1.2.3.4",
|
2021-08-09 14:53:21 +00:00
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2021-08-09 14:53:21 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2021-08-10 11:19:45 +00:00
|
|
|
unsafely_ignore_certificate_errors: Some(svec![
|
2021-08-09 14:53:21 +00:00
|
|
|
"deno.land",
|
|
|
|
"localhost",
|
|
|
|
"::",
|
|
|
|
"127.0.0.1",
|
|
|
|
"[::1]",
|
|
|
|
"1.2.3.4"
|
|
|
|
]),
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-12-10 14:47:55 +00:00
|
|
|
#[test]
|
|
|
|
fn repl_with_unsafely_treat_insecure_origin_as_secure_with_ipv6_address() {
|
|
|
|
let r = flags_from_vec(svec![
|
|
|
|
"deno",
|
|
|
|
"repl",
|
|
|
|
"--unsafely-ignore-certificate-errors=deno.land,localhost,::,127.0.0.1,[::1],1.2.3.4"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
repl: true,
|
|
|
|
subcommand: DenoSubcommand::Repl(ReplFlags { eval: None }),
|
|
|
|
unsafely_ignore_certificate_errors: Some(svec![
|
|
|
|
"deno.land",
|
|
|
|
"localhost",
|
|
|
|
"::",
|
|
|
|
"127.0.0.1",
|
|
|
|
"[::1]",
|
|
|
|
"1.2.3.4"
|
|
|
|
]),
|
|
|
|
allow_net: Some(vec![]),
|
|
|
|
allow_env: Some(vec![]),
|
|
|
|
allow_run: Some(vec![]),
|
|
|
|
allow_read: Some(vec![]),
|
|
|
|
allow_write: Some(vec![]),
|
|
|
|
allow_ffi: Some(vec![]),
|
|
|
|
allow_hrtime: true,
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-07-20 13:19:06 +00:00
|
|
|
#[test]
|
2019-12-03 22:48:53 +00:00
|
|
|
fn no_remote() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "run", "--no-remote", "script.ts"]);
|
2019-12-03 22:48:53 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-02-04 19:24:33 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2019-12-03 22:48:53 +00:00
|
|
|
no_remote: true,
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-12-03 22:48:53 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn cached_only() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "run", "--cached-only", "script.ts"]);
|
2019-07-20 13:19:06 +00:00
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-02-04 19:24:33 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2019-12-03 22:48:53 +00:00
|
|
|
cached_only: true,
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-07-20 13:19:06 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2019-07-31 15:02:20 +00:00
|
|
|
|
2019-10-12 21:13:52 +00:00
|
|
|
#[test]
|
2020-06-13 17:09:39 +00:00
|
|
|
fn allow_net_allowlist_with_ports() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2019-10-12 21:13:52 +00:00
|
|
|
"deno",
|
2020-05-04 11:03:30 +00:00
|
|
|
"run",
|
2019-10-12 21:13:52 +00:00
|
|
|
"--allow-net=deno.land,:8000,:4545",
|
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-02-04 19:24:33 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_net: Some(svec![
|
2019-10-12 21:13:52 +00:00
|
|
|
"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-12-29 18:34:35 +00:00
|
|
|
]),
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-10-12 21:13:52 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2019-11-03 15:39:27 +00:00
|
|
|
|
2020-06-26 12:09:02 +00:00
|
|
|
#[test]
|
|
|
|
fn allow_net_allowlist_with_ipv6_address() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2020-06-26 12:09:02 +00:00
|
|
|
"deno",
|
|
|
|
"run",
|
|
|
|
"--allow-net=deno.land,deno.land:80,::,127.0.0.1,[::1],1.2.3.4:5678,:5678,[::1]:8080",
|
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-06-26 12:09:02 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_net: Some(svec![
|
2020-06-26 12:09:02 +00:00
|
|
|
"deno.land",
|
|
|
|
"deno.land:80",
|
|
|
|
"::",
|
|
|
|
"127.0.0.1",
|
|
|
|
"[::1]",
|
|
|
|
"1.2.3.4:5678",
|
|
|
|
"0.0.0.0:5678",
|
|
|
|
"127.0.0.1:5678",
|
|
|
|
"localhost:5678",
|
|
|
|
"[::1]:8080"
|
2020-12-29 18:34:35 +00:00
|
|
|
]),
|
2020-06-26 12:09:02 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-11-03 15:39:27 +00:00
|
|
|
#[test]
|
2019-11-26 16:06:32 +00:00
|
|
|
fn lock_write() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2019-11-03 15:39:27 +00:00
|
|
|
"deno",
|
2020-05-04 11:03:30 +00:00
|
|
|
"run",
|
2019-11-03 15:39:27 +00:00
|
|
|
"--lock-write",
|
|
|
|
"--lock=lock.json",
|
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-02-04 19:24:33 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2019-11-03 15:39:27 +00:00
|
|
|
lock_write: true,
|
2020-10-19 19:19:20 +00:00
|
|
|
lock: Some(PathBuf::from("lock.json")),
|
2020-02-26 10:52:15 +00:00
|
|
|
..Flags::default()
|
2019-11-03 15:39:27 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2019-11-13 16:21:17 +00:00
|
|
|
|
2019-11-26 16:06:32 +00:00
|
|
|
#[test]
|
2020-11-22 13:06:51 +00:00
|
|
|
fn test_with_flags() {
|
|
|
|
#[rustfmt::skip]
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "test", "--unstable", "--no-run", "--filter", "- foo", "--coverage=cov", "--location", "https:foo", "--allow-net", "--allow-none", "dir1/", "dir2/", "--", "arg1", "arg2"]);
|
2019-11-13 16:21:17 +00:00
|
|
|
assert_eq!(
|
2019-11-26 16:06:32 +00:00
|
|
|
r.unwrap(),
|
2020-02-26 10:52:15 +00:00
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Test(TestFlags {
|
2020-11-22 13:06:51 +00:00
|
|
|
no_run: true,
|
2021-05-10 23:54:39 +00:00
|
|
|
doc: false,
|
2021-07-12 10:55:42 +00:00
|
|
|
fail_fast: None,
|
2020-11-22 13:06:51 +00:00
|
|
|
filter: Some("- foo".to_string()),
|
2020-02-11 11:01:56 +00:00
|
|
|
allow_none: true,
|
|
|
|
include: Some(svec!["dir1/", "dir2/"]),
|
2021-08-24 15:23:29 +00:00
|
|
|
ignore: vec![],
|
2021-07-06 01:20:33 +00:00
|
|
|
shuffle: None,
|
2021-08-23 10:35:38 +00:00
|
|
|
concurrent_jobs: NonZeroUsize::new(1).unwrap(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-09-13 13:01:30 +00:00
|
|
|
unstable: true,
|
2020-12-21 13:04:25 +00:00
|
|
|
coverage_dir: Some("cov".to_string()),
|
2021-01-07 18:06:08 +00:00
|
|
|
location: Some(Url::parse("https://foo/").unwrap()),
|
2020-12-29 18:34:35 +00:00
|
|
|
allow_net: Some(vec![]),
|
2020-10-26 00:25:43 +00:00
|
|
|
argv: svec!["arg1", "arg2"],
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-04-02 13:26:40 +00:00
|
|
|
#[test]
|
|
|
|
fn run_with_cafile() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2020-04-02 13:26:40 +00:00
|
|
|
"deno",
|
|
|
|
"run",
|
|
|
|
"--cert",
|
|
|
|
"example.crt",
|
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-04-02 13:26:40 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-04-02 13:26:40 +00:00
|
|
|
ca_file: Some("example.crt".to_owned()),
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-02-17 16:59:51 +00:00
|
|
|
|
2021-07-23 14:31:16 +00:00
|
|
|
#[test]
|
|
|
|
fn run_with_enable_testing_features() {
|
|
|
|
let r = flags_from_vec(svec![
|
|
|
|
"deno",
|
|
|
|
"run",
|
|
|
|
"--enable-testing-features-do-not-use",
|
|
|
|
"script.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2021-07-23 14:31:16 +00:00
|
|
|
script: "script.ts".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2021-07-23 14:31:16 +00:00
|
|
|
enable_testing_features: true,
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-08-23 10:35:38 +00:00
|
|
|
#[test]
|
|
|
|
fn test_with_concurrent_jobs() {
|
|
|
|
let r = flags_from_vec(svec!["deno", "test", "--jobs=4"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Test(TestFlags {
|
2021-08-23 10:35:38 +00:00
|
|
|
no_run: false,
|
|
|
|
doc: false,
|
|
|
|
fail_fast: None,
|
|
|
|
filter: None,
|
|
|
|
allow_none: false,
|
|
|
|
shuffle: None,
|
|
|
|
include: None,
|
2021-08-24 15:23:29 +00:00
|
|
|
ignore: vec![],
|
2021-08-23 10:35:38 +00:00
|
|
|
concurrent_jobs: NonZeroUsize::new(4).unwrap(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2021-08-23 10:35:38 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
let r = flags_from_vec(svec!["deno", "test", "--jobs=0"]);
|
|
|
|
assert!(r.is_err());
|
|
|
|
}
|
|
|
|
|
2021-07-12 10:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn test_with_fail_fast() {
|
|
|
|
let r = flags_from_vec(svec!["deno", "test", "--fail-fast=3"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Test(TestFlags {
|
2021-07-12 10:55:42 +00:00
|
|
|
no_run: false,
|
|
|
|
doc: false,
|
2021-08-23 10:37:02 +00:00
|
|
|
fail_fast: Some(NonZeroUsize::new(3).unwrap()),
|
2021-07-12 10:55:42 +00:00
|
|
|
filter: None,
|
|
|
|
allow_none: false,
|
|
|
|
shuffle: None,
|
|
|
|
include: None,
|
2021-08-24 15:23:29 +00:00
|
|
|
ignore: vec![],
|
2021-08-23 10:35:38 +00:00
|
|
|
concurrent_jobs: NonZeroUsize::new(1).unwrap(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2021-07-12 10:55:42 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
2021-08-23 10:37:02 +00:00
|
|
|
|
|
|
|
let r = flags_from_vec(svec!["deno", "test", "--fail-fast=0"]);
|
|
|
|
assert!(r.is_err());
|
2021-07-12 10:55:42 +00:00
|
|
|
}
|
|
|
|
|
2021-07-23 14:31:16 +00:00
|
|
|
#[test]
|
|
|
|
fn test_with_enable_testing_features() {
|
|
|
|
let r = flags_from_vec(svec![
|
|
|
|
"deno",
|
|
|
|
"test",
|
|
|
|
"--enable-testing-features-do-not-use"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Test(TestFlags {
|
2021-07-23 14:31:16 +00:00
|
|
|
no_run: false,
|
|
|
|
doc: false,
|
|
|
|
fail_fast: None,
|
|
|
|
filter: None,
|
|
|
|
allow_none: false,
|
|
|
|
shuffle: None,
|
|
|
|
include: None,
|
2021-08-24 15:23:29 +00:00
|
|
|
ignore: vec![],
|
2021-08-23 10:35:38 +00:00
|
|
|
concurrent_jobs: NonZeroUsize::new(1).unwrap(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2021-07-23 14:31:16 +00:00
|
|
|
enable_testing_features: true,
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2021-07-27 18:18:16 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_shuffle() {
|
|
|
|
let r = flags_from_vec(svec!["deno", "test", "--shuffle=1"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Test(TestFlags {
|
2021-07-27 18:18:16 +00:00
|
|
|
no_run: false,
|
|
|
|
doc: false,
|
|
|
|
fail_fast: None,
|
|
|
|
filter: None,
|
|
|
|
allow_none: false,
|
|
|
|
shuffle: Some(1),
|
|
|
|
include: None,
|
2021-08-24 15:23:29 +00:00
|
|
|
ignore: vec![],
|
2021-08-23 10:35:38 +00:00
|
|
|
concurrent_jobs: NonZeroUsize::new(1).unwrap(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2021-12-15 21:04:43 +00:00
|
|
|
watch: None,
|
2021-07-27 18:18:16 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-20 09:29:17 +00:00
|
|
|
#[test]
|
|
|
|
fn test_watch() {
|
|
|
|
let r = flags_from_vec(svec!["deno", "test", "--watch"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Test(TestFlags {
|
2021-07-20 09:29:17 +00:00
|
|
|
no_run: false,
|
|
|
|
doc: false,
|
|
|
|
fail_fast: None,
|
|
|
|
filter: None,
|
|
|
|
allow_none: false,
|
|
|
|
shuffle: None,
|
|
|
|
include: None,
|
2021-08-24 15:23:29 +00:00
|
|
|
ignore: vec![],
|
2021-08-23 10:35:38 +00:00
|
|
|
concurrent_jobs: NonZeroUsize::new(1).unwrap(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2021-12-15 21:04:43 +00:00
|
|
|
watch: Some(vec![]),
|
2021-07-20 09:29:17 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-04-02 13:26:40 +00:00
|
|
|
#[test]
|
|
|
|
fn bundle_with_cafile() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2020-04-02 13:26:40 +00:00
|
|
|
"deno",
|
|
|
|
"bundle",
|
|
|
|
"--cert",
|
|
|
|
"example.crt",
|
|
|
|
"source.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Bundle(BundleFlags {
|
2020-04-02 13:26:40 +00:00
|
|
|
source_file: "source.ts".to_string(),
|
|
|
|
out_file: None,
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-04-02 13:26:40 +00:00
|
|
|
ca_file: Some("example.crt".to_owned()),
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-02-17 16:59:51 +00:00
|
|
|
|
2020-07-06 03:58:23 +00:00
|
|
|
#[test]
|
|
|
|
fn upgrade_with_ca_file() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "upgrade", "--cert", "example.crt"]);
|
2020-07-06 03:58:23 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Upgrade(UpgradeFlags {
|
2020-07-06 03:58:23 +00:00
|
|
|
force: false,
|
|
|
|
dry_run: false,
|
2020-11-29 19:00:35 +00:00
|
|
|
canary: false,
|
2020-07-06 03:58:23 +00:00
|
|
|
version: None,
|
2020-07-06 22:21:26 +00:00
|
|
|
output: None,
|
2020-07-06 03:58:23 +00:00
|
|
|
ca_file: Some("example.crt".to_owned()),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-07-06 03:58:23 +00:00
|
|
|
ca_file: Some("example.crt".to_owned()),
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-04-02 13:26:40 +00:00
|
|
|
#[test]
|
2020-04-07 15:24:47 +00:00
|
|
|
fn cache_with_cafile() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2020-04-02 13:26:40 +00:00
|
|
|
"deno",
|
2020-04-07 15:24:47 +00:00
|
|
|
"cache",
|
2020-04-02 13:26:40 +00:00
|
|
|
"--cert",
|
|
|
|
"example.crt",
|
|
|
|
"script.ts",
|
|
|
|
"script_two.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Cache(CacheFlags {
|
2020-04-02 13:26:40 +00:00
|
|
|
files: svec!["script.ts", "script_two.ts"],
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-04-02 13:26:40 +00:00
|
|
|
ca_file: Some("example.crt".to_owned()),
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-02-17 16:59:51 +00:00
|
|
|
|
2020-04-02 13:26:40 +00:00
|
|
|
#[test]
|
|
|
|
fn info_with_cafile() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2020-04-02 13:26:40 +00:00
|
|
|
"deno",
|
|
|
|
"info",
|
|
|
|
"--cert",
|
|
|
|
"example.crt",
|
|
|
|
"https://example.com"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Info(InfoFlags {
|
2020-07-08 14:50:12 +00:00
|
|
|
json: false,
|
2020-04-02 13:26:40 +00:00
|
|
|
file: Some("https://example.com".to_string()),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-04-02 13:26:40 +00:00
|
|
|
ca_file: Some("example.crt".to_owned()),
|
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-02-17 16:59:51 +00:00
|
|
|
|
2020-04-02 13:26:40 +00:00
|
|
|
#[test]
|
|
|
|
fn doc() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "doc", "--json", "path/to/module.ts"]);
|
2020-04-02 13:26:40 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Doc(DocFlags {
|
2020-07-12 12:16:33 +00:00
|
|
|
private: false,
|
2020-04-02 13:26:40 +00:00
|
|
|
json: true,
|
2020-04-09 12:34:24 +00:00
|
|
|
source_file: Some("path/to/module.ts".to_string()),
|
2020-04-02 13:26:40 +00:00
|
|
|
filter: None,
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-04-02 13:26:40 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
2020-03-28 18:16:57 +00:00
|
|
|
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2020-04-02 13:26:40 +00:00
|
|
|
"deno",
|
|
|
|
"doc",
|
|
|
|
"path/to/module.ts",
|
|
|
|
"SomeClass.someField"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Doc(DocFlags {
|
2020-07-12 12:16:33 +00:00
|
|
|
private: false,
|
2020-04-02 13:26:40 +00:00
|
|
|
json: false,
|
2020-04-09 12:34:24 +00:00
|
|
|
source_file: Some("path/to/module.ts".to_string()),
|
2020-04-02 13:26:40 +00:00
|
|
|
filter: Some("SomeClass.someField".to_string()),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-04-02 13:26:40 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
2020-04-09 12:34:24 +00:00
|
|
|
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "doc"]);
|
2020-04-09 12:34:24 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Doc(DocFlags {
|
2020-07-12 12:16:33 +00:00
|
|
|
private: false,
|
2020-04-09 12:34:24 +00:00
|
|
|
json: false,
|
|
|
|
source_file: None,
|
|
|
|
filter: None,
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-04-09 12:34:24 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "doc", "--builtin", "Deno.Listener"]);
|
2020-04-09 12:34:24 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Doc(DocFlags {
|
2020-07-12 12:16:33 +00:00
|
|
|
private: false,
|
2020-04-09 12:34:24 +00:00
|
|
|
json: false,
|
|
|
|
source_file: Some("--builtin".to_string()),
|
|
|
|
filter: Some("Deno.Listener".to_string()),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-04-09 12:34:24 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
2020-07-12 12:16:33 +00:00
|
|
|
|
2021-01-07 18:06:08 +00:00
|
|
|
let r =
|
|
|
|
flags_from_vec(svec!["deno", "doc", "--private", "path/to/module.js"]);
|
2020-07-12 12:16:33 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Doc(DocFlags {
|
2020-07-12 12:16:33 +00:00
|
|
|
private: true,
|
|
|
|
json: false,
|
|
|
|
source_file: Some("path/to/module.js".to_string()),
|
|
|
|
filter: None,
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-07-12 12:16:33 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
2020-04-02 13:26:40 +00:00
|
|
|
}
|
2020-03-27 20:09:51 +00:00
|
|
|
|
2020-04-02 13:26:40 +00:00
|
|
|
#[test]
|
|
|
|
fn inspect_default_host() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "run", "--inspect", "foo.js"]);
|
2020-04-02 13:26:40 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
2020-04-02 13:26:40 +00:00
|
|
|
script: "foo.js".to_string(),
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-04-03 17:40:11 +00:00
|
|
|
inspect: Some("127.0.0.1:9229".parse().unwrap()),
|
2020-04-02 13:26:40 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-11-30 19:35:12 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compile() {
|
2021-01-07 18:06:08 +00:00
|
|
|
let r = flags_from_vec(svec![
|
2020-11-30 19:35:12 +00:00
|
|
|
"deno",
|
|
|
|
"compile",
|
|
|
|
"https://deno.land/std/examples/colors.ts"
|
|
|
|
]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Compile(CompileFlags {
|
2020-11-30 19:35:12 +00:00
|
|
|
source_file: "https://deno.land/std/examples/colors.ts".to_string(),
|
2021-01-04 23:15:52 +00:00
|
|
|
output: None,
|
|
|
|
args: vec![],
|
2021-01-19 02:40:22 +00:00
|
|
|
target: None,
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-11-30 19:35:12 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compile_with_flags() {
|
|
|
|
#[rustfmt::skip]
|
2021-08-10 11:19:45 +00:00
|
|
|
let r = flags_from_vec(svec!["deno", "compile", "--import-map", "import_map.json", "--no-remote", "--config", "tsconfig.json", "--no-check", "--unsafely-ignore-certificate-errors", "--reload", "--lock", "lock.json", "--lock-write", "--cert", "example.crt", "--cached-only", "--location", "https:foo", "--allow-read", "--allow-net", "--v8-flags=--help", "--seed", "1", "--output", "colors", "https://deno.land/std/examples/colors.ts", "foo", "bar"]);
|
2020-11-30 19:35:12 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Compile(CompileFlags {
|
2020-11-30 19:35:12 +00:00
|
|
|
source_file: "https://deno.land/std/examples/colors.ts".to_string(),
|
2021-01-04 23:15:52 +00:00
|
|
|
output: Some(PathBuf::from("colors")),
|
|
|
|
args: svec!["foo", "bar"],
|
2021-01-19 02:40:22 +00:00
|
|
|
target: None,
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2020-11-30 19:35:12 +00:00
|
|
|
import_map_path: Some("import_map.json".to_string()),
|
|
|
|
no_remote: true,
|
|
|
|
config_path: Some("tsconfig.json".to_string()),
|
2021-11-29 22:23:30 +00:00
|
|
|
check: CheckFlag::None,
|
2020-11-30 19:35:12 +00:00
|
|
|
reload: true,
|
|
|
|
lock: Some(PathBuf::from("lock.json")),
|
|
|
|
lock_write: true,
|
|
|
|
ca_file: Some("example.crt".to_string()),
|
2021-01-04 23:15:52 +00:00
|
|
|
cached_only: true,
|
2021-01-07 18:06:08 +00:00
|
|
|
location: Some(Url::parse("https://foo/").unwrap()),
|
2021-01-04 23:15:52 +00:00
|
|
|
allow_read: Some(vec![]),
|
2021-08-10 11:19:45 +00:00
|
|
|
unsafely_ignore_certificate_errors: Some(vec![]),
|
2021-01-04 23:15:52 +00:00
|
|
|
allow_net: Some(vec![]),
|
|
|
|
v8_flags: svec!["--help", "--random-seed=1"],
|
|
|
|
seed: Some(1),
|
2020-11-30 19:35:12 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2021-01-24 01:18:19 +00:00
|
|
|
|
2021-02-24 14:27:51 +00:00
|
|
|
#[test]
|
|
|
|
fn coverage() {
|
|
|
|
let r = flags_from_vec(svec!["deno", "coverage", "foo.json"]);
|
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
2021-09-03 23:33:35 +00:00
|
|
|
subcommand: DenoSubcommand::Coverage(CoverageFlags {
|
2021-02-24 14:27:51 +00:00
|
|
|
files: vec![PathBuf::from("foo.json")],
|
|
|
|
ignore: vec![],
|
|
|
|
include: vec![r"^file:".to_string()],
|
|
|
|
exclude: vec![r"test\.(js|mjs|ts|jsx|tsx)$".to_string()],
|
|
|
|
lcov: false,
|
2021-09-03 23:33:35 +00:00
|
|
|
}),
|
2021-02-24 14:27:51 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-24 01:18:19 +00:00
|
|
|
#[test]
|
|
|
|
fn location_with_bad_scheme() {
|
|
|
|
#[rustfmt::skip]
|
|
|
|
let r = flags_from_vec(svec!["deno", "run", "--location", "foo:", "mod.ts"]);
|
|
|
|
assert!(r.is_err());
|
|
|
|
assert!(r
|
|
|
|
.unwrap_err()
|
|
|
|
.to_string()
|
|
|
|
.contains("Expected protocol \"http\" or \"https\""));
|
|
|
|
}
|
2021-10-04 23:35:55 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compat() {
|
2021-10-06 17:07:04 +00:00
|
|
|
let r =
|
|
|
|
flags_from_vec(svec!["deno", "run", "--compat", "--unstable", "foo.js"]);
|
2021-10-04 23:35:55 +00:00
|
|
|
assert_eq!(
|
|
|
|
r.unwrap(),
|
|
|
|
Flags {
|
|
|
|
subcommand: DenoSubcommand::Run(RunFlags {
|
|
|
|
script: "foo.js".to_string(),
|
|
|
|
}),
|
|
|
|
compat: true,
|
2021-10-06 17:07:04 +00:00
|
|
|
unstable: true,
|
2021-10-04 23:35:55 +00:00
|
|
|
..Flags::default()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-03-27 20:09:51 +00:00
|
|
|
}
|