1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 23:59:59 -05:00

DenoFlags -> Flags (#4136)

This commit is contained in:
Ryan Dahl 2020-02-26 05:52:15 -05:00 committed by GitHub
parent 3eebef39c5
commit 9a8d6fbd98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 186 additions and 189 deletions

View file

@ -72,7 +72,7 @@ impl Default for DenoSubcommand {
}
#[derive(Clone, Debug, PartialEq, Default)]
pub struct DenoFlags {
pub struct Flags {
/// Vector of CLI arguments - these are user script arguments, all Deno
/// specific flags are removed.
pub argv: Vec<String>,
@ -113,7 +113,7 @@ fn join_paths(whitelist: &[PathBuf], d: &str) -> String {
.join(d)
}
impl DenoFlags {
impl Flags {
/// Return list of permission arguments that are equivalent
/// to the ones used to create `self`.
pub fn to_permission_args(&self) -> Vec<String> {
@ -208,7 +208,7 @@ lazy_static! {
/// Main entry point for parsing deno's command line flags.
/// Exits the process on error.
pub fn flags_from_vec(args: Vec<String>) -> DenoFlags {
pub fn flags_from_vec(args: Vec<String>) -> Flags {
match flags_from_vec_safe(args) {
Ok(flags) => flags,
Err(err) => err.exit(),
@ -216,12 +216,12 @@ pub fn flags_from_vec(args: Vec<String>) -> DenoFlags {
}
/// Same as flags_from_vec but does not exit on error.
pub fn flags_from_vec_safe(args: Vec<String>) -> clap::Result<DenoFlags> {
pub fn flags_from_vec_safe(args: Vec<String>) -> clap::Result<Flags> {
let args = arg_hacks(args);
let app = clap_root();
let matches = app.get_matches_from_safe(args)?;
let mut flags = DenoFlags::default();
let mut flags = Flags::default();
if matches.is_present("log-level") {
flags.log_level = match matches.value_of("log-level").unwrap() {
@ -297,11 +297,11 @@ fn clap_root<'a, 'b>() -> App<'a, 'b> {
.after_help(ENV_VARIABLES_HELP)
}
fn types_parse(flags: &mut DenoFlags, _matches: &clap::ArgMatches) {
fn types_parse(flags: &mut Flags, _matches: &clap::ArgMatches) {
flags.subcommand = DenoSubcommand::Types;
}
fn fmt_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
fn fmt_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
let files = match matches.values_of("files") {
Some(f) => f.map(String::from).collect(),
None => vec![],
@ -312,7 +312,7 @@ fn fmt_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
}
}
fn install_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
fn install_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
permission_args_parse(flags, matches);
ca_file_arg_parse(flags, matches);
@ -344,7 +344,7 @@ fn install_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
};
}
fn bundle_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
fn bundle_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
ca_file_arg_parse(flags, matches);
let source_file = matches.value_of("source_file").unwrap().to_string();
@ -362,7 +362,7 @@ fn bundle_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
};
}
fn completions_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
fn completions_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
let shell: &str = matches.value_of("shell").unwrap();
let mut buf: Vec<u8> = vec![];
use std::str::FromStr;
@ -377,7 +377,7 @@ fn completions_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
};
}
fn repl_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
fn repl_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
v8_flags_arg_parse(flags, matches);
ca_file_arg_parse(flags, matches);
flags.subcommand = DenoSubcommand::Repl;
@ -390,7 +390,7 @@ fn repl_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
flags.allow_hrtime = true;
}
fn eval_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
fn eval_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
v8_flags_arg_parse(flags, matches);
ca_file_arg_parse(flags, matches);
flags.allow_net = true;
@ -404,7 +404,7 @@ fn eval_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
flags.subcommand = DenoSubcommand::Eval { code }
}
fn info_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
fn info_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
ca_file_arg_parse(flags, matches);
flags.subcommand = DenoSubcommand::Info {
@ -412,7 +412,7 @@ fn info_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
};
}
fn fetch_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
fn fetch_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
reload_arg_parse(flags, matches);
lock_args_parse(flags, matches);
importmap_arg_parse(flags, matches);
@ -427,7 +427,7 @@ fn fetch_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
flags.subcommand = DenoSubcommand::Fetch { files };
}
fn lock_args_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
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(lockfile.to_string());
@ -445,7 +445,7 @@ fn resolve_fs_whitelist(whitelist: &[PathBuf]) -> Vec<PathBuf> {
}
// Shared between the run and test subcommands. They both take similar options.
fn run_test_args_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
fn run_test_args_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
reload_arg_parse(flags, matches);
lock_args_parse(flags, matches);
importmap_arg_parse(flags, matches);
@ -477,7 +477,7 @@ fn run_test_args_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
}
}
fn run_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
fn run_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
run_test_args_parse(flags, matches);
let mut script: Vec<String> = matches
@ -495,7 +495,7 @@ fn run_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
flags.subcommand = DenoSubcommand::Run { script };
}
fn test_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
fn test_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
flags.allow_read = true;
run_test_args_parse(flags, matches);
@ -909,7 +909,7 @@ fn config_arg<'a, 'b>() -> Arg<'a, 'b> {
.takes_value(true)
}
fn config_arg_parse(flags: &mut DenoFlags, matches: &ArgMatches) {
fn config_arg_parse(flags: &mut Flags, matches: &ArgMatches) {
flags.config_path = matches.value_of("config").map(ToOwned::to_owned);
}
@ -920,7 +920,7 @@ fn ca_file_arg<'a, 'b>() -> Arg<'a, 'b> {
.help("Load certificate authority from PEM encoded file")
.takes_value(true)
}
fn ca_file_arg_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
fn ca_file_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
flags.ca_file = matches.value_of("cert").map(ToOwned::to_owned);
}
@ -945,7 +945,7 @@ fn reload_arg<'a, 'b>() -> Arg<'a, 'b> {
)
}
fn reload_arg_parse(flags: &mut DenoFlags, matches: &ArgMatches) {
fn reload_arg_parse(flags: &mut Flags, matches: &ArgMatches) {
if matches.is_present("reload") {
if matches.value_of("reload").is_some() {
let cache_bl = matches.values_of("reload").unwrap();
@ -974,7 +974,7 @@ Examples: https://github.com/WICG/import-maps#the-import-map",
.takes_value(true)
}
fn importmap_arg_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
fn importmap_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
flags.import_map_path = matches.value_of("importmap").map(ToOwned::to_owned);
}
@ -987,7 +987,7 @@ fn v8_flags_arg<'a, 'b>() -> Arg<'a, 'b> {
.help("Set V8 command line options. For help: --v8-flags=--help")
}
fn v8_flags_arg_parse(flags: &mut DenoFlags, matches: &ArgMatches) {
fn v8_flags_arg_parse(flags: &mut Flags, matches: &ArgMatches) {
if let Some(v8_flags) = matches.values_of("v8-flags") {
let s: Vec<String> = v8_flags.map(String::from).collect();
flags.v8_flags = Some(s);
@ -1000,13 +1000,13 @@ fn no_remote_arg<'a, 'b>() -> Arg<'a, 'b> {
.help("Do not resolve remote modules")
}
fn no_remote_arg_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
fn no_remote_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
if matches.is_present("no-remote") {
flags.no_remote = true;
}
}
fn permission_args_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
fn permission_args_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
if matches.is_present("allow-read") {
if matches.value_of("allow-read").is_some() {
let read_wl = matches.values_of("allow-read").unwrap();
@ -1206,12 +1206,12 @@ mod tests {
let flags = r.unwrap();
assert_eq!(
flags,
DenoFlags {
Flags {
subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(),
},
reload: true,
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1227,13 +1227,13 @@ mod tests {
]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
reload: true,
subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(),
},
allow_write: true,
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1248,12 +1248,12 @@ mod tests {
]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(),
},
v8_flags: Some(svec!["--help"]),
..DenoFlags::default()
..Flags::default()
}
);
@ -1265,12 +1265,12 @@ mod tests {
]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(),
},
v8_flags: Some(svec!["--expose-gc", "--gc-stats=1"]),
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1287,13 +1287,13 @@ mod tests {
]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Run {
script: "gist.ts".to_string(),
},
argv: svec!["--title", "X"],
allow_net: true,
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1303,7 +1303,7 @@ mod tests {
let r = flags_from_vec_safe(svec!["deno", "run", "--allow-all", "gist.ts"]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Run {
script: "gist.ts".to_string(),
},
@ -1314,7 +1314,7 @@ mod tests {
allow_write: true,
allow_plugin: true,
allow_hrtime: true,
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1325,12 +1325,12 @@ mod tests {
flags_from_vec_safe(svec!["deno", "run", "--allow-read", "gist.ts"]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Run {
script: "gist.ts".to_string(),
},
allow_read: true,
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1341,12 +1341,12 @@ mod tests {
flags_from_vec_safe(svec!["deno", "run", "--allow-hrtime", "gist.ts"]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Run {
script: "gist.ts".to_string(),
},
allow_hrtime: true,
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1354,7 +1354,7 @@ mod tests {
#[test]
fn double_hyphen() {
// notice that flags passed after double dash will not
// be parsed to DenoFlags but instead forwarded to
// be parsed to Flags but instead forwarded to
// script args as Deno.args
let r = flags_from_vec_safe(svec![
"deno",
@ -1367,13 +1367,13 @@ mod tests {
]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(),
},
argv: svec!["--", "-D", "--allow-net"],
allow_write: true,
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1384,36 +1384,36 @@ mod tests {
flags_from_vec_safe(svec!["deno", "fmt", "script_1.ts", "script_2.ts"]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Fmt {
check: false,
files: vec!["script_1.ts".to_string(), "script_2.ts".to_string()]
},
..DenoFlags::default()
..Flags::default()
}
);
let r = flags_from_vec_safe(svec!["deno", "fmt", "--check"]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Fmt {
check: true,
files: vec![],
},
..DenoFlags::default()
..Flags::default()
}
);
let r = flags_from_vec_safe(svec!["deno", "fmt"]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Fmt {
check: false,
files: vec![],
},
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1423,9 +1423,9 @@ mod tests {
let r = flags_from_vec_safe(svec!["deno", "types"]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Types,
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1435,11 +1435,11 @@ mod tests {
let r = flags_from_vec_safe(svec!["deno", "fetch", "script.ts"]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Fetch {
files: svec!["script.ts"],
},
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1449,20 +1449,20 @@ mod tests {
let r = flags_from_vec_safe(svec!["deno", "info", "script.ts"]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Info {
file: Some("script.ts".to_string()),
},
..DenoFlags::default()
..Flags::default()
}
);
let r = flags_from_vec_safe(svec!["deno", "info"]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Info { file: None },
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1478,12 +1478,12 @@ mod tests {
]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(),
},
config_path: Some("tsconfig.json".to_owned()),
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1494,7 +1494,7 @@ mod tests {
flags_from_vec_safe(svec!["deno", "eval", "'console.log(\"hello\")'"]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Eval {
code: "'console.log(\"hello\")'".to_string(),
},
@ -1505,7 +1505,7 @@ mod tests {
allow_write: true,
allow_plugin: true,
allow_hrtime: true,
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1516,7 +1516,7 @@ mod tests {
flags_from_vec_safe(svec!["deno", "eval", "--v8-flags=--help", "42"]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Eval {
code: "42".to_string(),
},
@ -1528,7 +1528,7 @@ mod tests {
allow_write: true,
allow_plugin: true,
allow_hrtime: true,
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1538,7 +1538,7 @@ mod tests {
let r = flags_from_vec_safe(svec!["deno"]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Repl,
allow_net: true,
allow_env: true,
@ -1547,7 +1547,7 @@ mod tests {
allow_write: true,
allow_plugin: true,
allow_hrtime: true,
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1565,13 +1565,13 @@ mod tests {
]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
allow_read: false,
read_whitelist: vec![current_dir().unwrap(), temp_dir],
subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(),
},
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1589,13 +1589,13 @@ mod tests {
]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
allow_write: false,
write_whitelist: vec![current_dir().unwrap(), temp_dir],
subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(),
},
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1610,13 +1610,13 @@ mod tests {
]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(),
},
allow_net: false,
net_whitelist: svec!["127.0.0.1"],
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1626,11 +1626,11 @@ mod tests {
let r = flags_from_vec_safe(svec!["deno", "script.ts"]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(),
},
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1645,13 +1645,13 @@ mod tests {
]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(),
},
allow_net: true,
allow_read: true,
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1661,12 +1661,12 @@ mod tests {
let r = flags_from_vec_safe(svec!["deno", "bundle", "source.ts"]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Bundle {
source_file: "source.ts".to_string(),
out_file: None,
},
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1677,13 +1677,13 @@ mod tests {
flags_from_vec_safe(svec!["deno", "bundle", "source.ts", "bundle.js"]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Bundle {
source_file: "source.ts".to_string(),
out_file: Some(PathBuf::from("bundle.js")),
},
allow_write: true,
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1698,12 +1698,12 @@ mod tests {
]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(),
},
import_map_path: Some("importmap.json".to_owned()),
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1717,12 +1717,12 @@ mod tests {
]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(),
},
import_map_path: Some("importmap.json".to_owned()),
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1737,12 +1737,12 @@ mod tests {
]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Fetch {
files: svec!["script.ts"],
},
import_map_path: Some("importmap.json".to_owned()),
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1753,11 +1753,11 @@ mod tests {
flags_from_vec_safe(svec!["deno", "fetch", "script.ts", "script_two.ts"]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Fetch {
files: svec!["script.ts", "script_two.ts"],
},
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1768,13 +1768,13 @@ mod tests {
flags_from_vec_safe(svec!["deno", "run", "--seed", "250", "script.ts"]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(),
},
seed: Some(250 as u64),
v8_flags: Some(svec!["--random-seed=250"]),
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1791,13 +1791,13 @@ mod tests {
]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(),
},
seed: Some(250 as u64),
v8_flags: Some(svec!["--expose-gc", "--random-seed=250"]),
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1812,7 +1812,7 @@ mod tests {
]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Install {
dir: None,
exe_name: "deno_colors".to_string(),
@ -1820,7 +1820,7 @@ mod tests {
args: vec![],
force: false,
},
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1837,7 +1837,7 @@ mod tests {
]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Install {
dir: None,
exe_name: "file_server".to_string(),
@ -1847,7 +1847,7 @@ mod tests {
},
allow_net: true,
allow_read: true,
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1869,7 +1869,7 @@ mod tests {
]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Install {
dir: Some(PathBuf::from("/usr/local/bin")),
exe_name: "file_server".to_string(),
@ -1879,7 +1879,7 @@ mod tests {
},
allow_net: true,
allow_read: true,
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1890,12 +1890,12 @@ mod tests {
flags_from_vec_safe(svec!["deno", "--log-level=debug", "script.ts"]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(),
},
log_level: Some(Level::Debug),
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1917,10 +1917,10 @@ mod tests {
flags_from_vec_safe(svec!["deno", "script.ts", "--allow-read", "--allow-net"]);
assert_eq!(
flags,
DenoFlags {
Flags {
allow_net: true,
allow_read: true,
..DenoFlags::default()
..Flags::default()
}
);
assert_eq!(subcommand, DenoSubcommand::Run);
@ -1939,11 +1939,11 @@ mod tests {
]);
assert_eq!(
flags,
DenoFlags {
Flags {
allow_net: true,
allow_read: true,
reload: true,
..DenoFlags::default()
..Flags::default()
}
);
assert_eq!(subcommand, DenoSubcommand::Run);
@ -1951,19 +1951,19 @@ mod tests {
let (flags, subcommand, argv) =
flags_from_vec_safe(svec!["deno""script.ts", "foo", "bar"]);
assert_eq!(flags, DenoFlags::default());
assert_eq!(flags, Flags::default());
assert_eq!(subcommand, DenoSubcommand::Run);
assert_eq!(argv, svec!["script.ts", "foo", "bar"]);
let (flags, subcommand, argv) =
flags_from_vec_safe(svec!["deno""script.ts", "-"]);
assert_eq!(flags, DenoFlags::default());
assert_eq!(flags, Flags::default());
assert_eq!(subcommand, DenoSubcommand::Run);
assert_eq!(argv, svec!["script.ts", "-"]);
let (flags, subcommand, argv) =
flags_from_vec_safe(svec!["deno""script.ts", "-", "foo", "bar"]);
assert_eq!(flags, DenoFlags::default());
assert_eq!(flags, Flags::default());
assert_eq!(subcommand, DenoSubcommand::Run);
assert_eq!(argv, svec!["script.ts", "-", "foo", "bar"]);
}
@ -1974,12 +1974,12 @@ mod tests {
let r = flags_from_vec_safe(svec!["deno", "--no-remote", "script.ts"]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(),
},
no_remote: true,
..DenoFlags::default()
..Flags::default()
}
);
}
@ -1989,12 +1989,12 @@ mod tests {
let r = flags_from_vec_safe(svec!["deno", "--cached-only", "script.ts"]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(),
},
cached_only: true,
..DenoFlags::default()
..Flags::default()
}
);
}
@ -2008,7 +2008,7 @@ mod tests {
]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(),
},
@ -2021,7 +2021,7 @@ mod tests {
"127.0.0.1:4545",
"localhost:4545"
],
..DenoFlags::default()
..Flags::default()
}
);
}
@ -2036,13 +2036,13 @@ mod tests {
]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(),
},
lock_write: true,
lock: Some("lock.json".to_string()),
..DenoFlags::default()
..Flags::default()
}
);
}
@ -2059,7 +2059,7 @@ mod tests {
]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Test {
fail_fast: false,
quiet: false,
@ -2068,7 +2068,7 @@ mod tests {
},
allow_read: true,
allow_net: true,
..DenoFlags::default()
..Flags::default()
}
);
}
@ -2085,12 +2085,12 @@ fn run_with_cafile() {
]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(),
},
ca_file: Some("example.crt".to_owned()),
..DenoFlags::default()
..Flags::default()
}
);
}
@ -2106,13 +2106,13 @@ fn bundle_with_cafile() {
]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Bundle {
source_file: "source.ts".to_string(),
out_file: None,
},
ca_file: Some("example.crt".to_owned()),
..DenoFlags::default()
..Flags::default()
}
);
}
@ -2128,7 +2128,7 @@ fn eval_with_cafile() {
]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Eval {
code: "console.log('hello world')".to_string(),
},
@ -2140,7 +2140,7 @@ fn eval_with_cafile() {
allow_write: true,
allow_plugin: true,
allow_hrtime: true,
..DenoFlags::default()
..Flags::default()
}
);
}
@ -2157,12 +2157,12 @@ fn fetch_with_cafile() {
]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Fetch {
files: svec!["script.ts", "script_two.ts"],
},
ca_file: Some("example.crt".to_owned()),
..DenoFlags::default()
..Flags::default()
}
);
}
@ -2178,12 +2178,12 @@ fn info_with_cafile() {
]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Info {
file: Some("https://example.com".to_string()),
},
ca_file: Some("example.crt".to_owned()),
..DenoFlags::default()
..Flags::default()
}
);
}
@ -2200,7 +2200,7 @@ fn install_with_cafile() {
]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Install {
dir: None,
exe_name: "deno_colors".to_string(),
@ -2209,7 +2209,7 @@ fn install_with_cafile() {
force: false,
},
ca_file: Some("example.crt".to_owned()),
..DenoFlags::default()
..Flags::default()
}
);
}
@ -2219,7 +2219,7 @@ fn repl_with_cafile() {
let r = flags_from_vec_safe(svec!["deno", "repl", "--cert", "example.crt"]);
assert_eq!(
r.unwrap(),
DenoFlags {
Flags {
subcommand: DenoSubcommand::Repl {},
ca_file: Some("example.crt".to_owned()),
allow_read: true,
@ -2229,7 +2229,7 @@ fn repl_with_cafile() {
allow_run: true,
allow_plugin: true,
allow_hrtime: true,
..DenoFlags::default()
..Flags::default()
}
);
}

View file

@ -31,7 +31,7 @@ pub struct GlobalState(Arc<GlobalStateInner>);
/// It is shared by all created workers (thus V8 isolates).
pub struct GlobalStateInner {
/// Flags parsed from `argv` contents.
pub flags: flags::DenoFlags,
pub flags: flags::Flags,
/// Permissions parsed from `flags`.
pub permissions: DenoPermissions,
pub dir: deno_dir::DenoDir,
@ -53,7 +53,7 @@ impl Deref for GlobalState {
}
impl GlobalState {
pub fn new(flags: flags::DenoFlags) -> Result<Self, ErrBox> {
pub fn new(flags: flags::Flags) -> Result<Self, ErrBox> {
let custom_root = env::var("DENO_DIR").map(String::into).ok();
let dir = deno_dir::DenoDir::new(custom_root)?;
let deps_cache_location = dir.root.join("deps");
@ -168,9 +168,9 @@ impl GlobalState {
#[cfg(test)]
pub fn mock(argv: Vec<String>) -> GlobalState {
GlobalState::new(flags::DenoFlags {
GlobalState::new(flags::Flags {
argv,
..flags::DenoFlags::default()
..flags::Flags::default()
})
.unwrap()
}
@ -184,8 +184,8 @@ fn thread_safe() {
#[test]
fn import_map_given_for_repl() {
let _result = GlobalState::new(flags::DenoFlags {
let _result = GlobalState::new(flags::Flags {
import_map_path: Some("import_map.json".to_string()),
..flags::DenoFlags::default()
..flags::Flags::default()
});
}

View file

@ -1,5 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
use crate::flags::DenoFlags;
use crate::flags::Flags;
use regex::{Regex, RegexBuilder};
use std::env;
use std::fs;
@ -100,7 +100,7 @@ fn get_installer_dir() -> Result<PathBuf, Error> {
}
pub fn install(
flags: DenoFlags,
flags: Flags,
installation_dir: Option<PathBuf>,
exec_name: &str,
module_url: &str,
@ -218,7 +218,7 @@ mod tests {
env::set_var("USERPROFILE", &temp_dir_str);
install(
DenoFlags::default(),
Flags::default(),
None,
"echo_test",
"http://localhost:4545/cli/tests/echo_server.ts",
@ -252,7 +252,7 @@ mod tests {
fn install_custom_dir() {
let temp_dir = TempDir::new().expect("tempdir fail");
install(
DenoFlags::default(),
Flags::default(),
Some(temp_dir.path().to_path_buf()),
"echo_test",
"http://localhost:4545/cli/tests/echo_server.ts",
@ -277,10 +277,10 @@ mod tests {
let temp_dir = TempDir::new().expect("tempdir fail");
install(
DenoFlags {
Flags {
allow_net: true,
allow_read: true,
..DenoFlags::default()
..Flags::default()
},
Some(temp_dir.path().to_path_buf()),
"echo_test",
@ -308,7 +308,7 @@ mod tests {
let local_module_str = local_module.to_string_lossy();
install(
DenoFlags::default(),
Flags::default(),
Some(temp_dir.path().to_path_buf()),
"echo_test",
&local_module_str,
@ -332,7 +332,7 @@ mod tests {
let temp_dir = TempDir::new().expect("tempdir fail");
install(
DenoFlags::default(),
Flags::default(),
Some(temp_dir.path().to_path_buf()),
"echo_test",
"http://localhost:4545/cli/tests/echo_server.ts",
@ -349,7 +349,7 @@ mod tests {
// No force. Install failed.
let no_force_result = install(
DenoFlags::default(),
Flags::default(),
Some(temp_dir.path().to_path_buf()),
"echo_test",
"http://localhost:4545/cli/tests/cat.ts", // using a different URL
@ -367,7 +367,7 @@ mod tests {
// Force. Install success.
let force_result = install(
DenoFlags::default(),
Flags::default(),
Some(temp_dir.path().to_path_buf()),
"echo_test",
"http://localhost:4545/cli/tests/cat.ts", // using a different URL

View file

@ -65,8 +65,8 @@ use crate::worker::MainWorker;
use deno_core::v8_set_flags;
use deno_core::ErrBox;
use deno_core::ModuleSpecifier;
use flags::DenoFlags;
use flags::DenoSubcommand;
use flags::Flags;
use futures::future::FutureExt;
use log::Level;
use log::Metadata;
@ -219,7 +219,7 @@ async fn print_file_info(
}
async fn info_command(
flags: DenoFlags,
flags: Flags,
file: Option<String>,
) -> Result<(), ErrBox> {
let global_state = GlobalState::new(flags)?;
@ -236,7 +236,7 @@ async fn info_command(
}
async fn install_command(
flags: DenoFlags,
flags: Flags,
dir: Option<PathBuf>,
exe_name: String,
module_url: String,
@ -254,10 +254,7 @@ async fn install_command(
.map_err(ErrBox::from)
}
async fn fetch_command(
flags: DenoFlags,
files: Vec<String>,
) -> Result<(), ErrBox> {
async fn fetch_command(flags: Flags, files: Vec<String>) -> Result<(), ErrBox> {
let main_module =
ModuleSpecifier::resolve_url_or_path("./__$deno$fetch.ts").unwrap();
let global_state = GlobalState::new(flags)?;
@ -282,7 +279,7 @@ async fn fetch_command(
Ok(())
}
async fn eval_command(flags: DenoFlags, code: String) -> Result<(), ErrBox> {
async fn eval_command(flags: Flags, code: String) -> Result<(), ErrBox> {
// Force TypeScript compile.
let main_module =
ModuleSpecifier::resolve_url_or_path("./__$deno$eval.ts").unwrap();
@ -297,7 +294,7 @@ async fn eval_command(flags: DenoFlags, code: String) -> Result<(), ErrBox> {
}
async fn bundle_command(
flags: DenoFlags,
flags: Flags,
source_file: String,
out_file: Option<PathBuf>,
) -> Result<(), ErrBox> {
@ -312,7 +309,7 @@ async fn bundle_command(
bundle_result
}
async fn run_repl(flags: DenoFlags) -> Result<(), ErrBox> {
async fn run_repl(flags: Flags) -> Result<(), ErrBox> {
let main_module =
ModuleSpecifier::resolve_url_or_path("./__$deno$repl.ts").unwrap();
let global_state = GlobalState::new(flags)?;
@ -322,7 +319,7 @@ async fn run_repl(flags: DenoFlags) -> Result<(), ErrBox> {
}
}
async fn run_command(flags: DenoFlags, script: String) -> Result<(), ErrBox> {
async fn run_command(flags: Flags, script: String) -> Result<(), ErrBox> {
let global_state = GlobalState::new(flags.clone())?;
let main_module = ModuleSpecifier::resolve_url_or_path(&script).unwrap();
let mut worker =
@ -345,7 +342,7 @@ async fn run_command(flags: DenoFlags, script: String) -> Result<(), ErrBox> {
}
async fn test_command(
flags: DenoFlags,
flags: Flags,
include: Option<Vec<String>>,
fail_fast: bool,
_quiet: bool,

View file

@ -1,6 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
use crate::colors;
use crate::flags::DenoFlags;
use crate::flags::Flags;
use crate::op_error::OpError;
#[cfg(not(test))]
use atty;
@ -115,7 +115,7 @@ pub struct DenoPermissions {
}
impl DenoPermissions {
pub fn from_flags(flags: &DenoFlags) -> Self {
pub fn from_flags(flags: &Flags) -> Self {
Self {
allow_read: PermissionState::from(flags.allow_read),
read_whitelist: flags.read_whitelist.iter().cloned().collect(),
@ -397,7 +397,7 @@ mod tests {
PathBuf::from("/b/c"),
];
let perms = DenoPermissions::from_flags(&DenoFlags {
let perms = DenoPermissions::from_flags(&Flags {
read_whitelist: whitelist.clone(),
write_whitelist: whitelist,
..Default::default()
@ -444,7 +444,7 @@ mod tests {
#[test]
fn test_check_net() {
let perms = DenoPermissions::from_flags(&DenoFlags {
let perms = DenoPermissions::from_flags(&Flags {
net_whitelist: svec![
"localhost",
"deno.land",
@ -528,13 +528,13 @@ mod tests {
#[test]
fn test_permissions_request_run() {
let guard = PERMISSION_PROMPT_GUARD.lock().unwrap();
let mut perms0 = DenoPermissions::from_flags(&DenoFlags {
let mut perms0 = DenoPermissions::from_flags(&Flags {
..Default::default()
});
set_prompt_result(true);
assert_eq!(perms0.request_run(), PermissionState::Allow);
let mut perms1 = DenoPermissions::from_flags(&DenoFlags {
let mut perms1 = DenoPermissions::from_flags(&Flags {
..Default::default()
});
set_prompt_result(false);
@ -546,7 +546,7 @@ mod tests {
fn test_permissions_request_read() {
let guard = PERMISSION_PROMPT_GUARD.lock().unwrap();
let whitelist = vec![PathBuf::from("/foo/bar")];
let mut perms0 = DenoPermissions::from_flags(&DenoFlags {
let mut perms0 = DenoPermissions::from_flags(&Flags {
read_whitelist: whitelist.clone(),
..Default::default()
});
@ -558,7 +558,7 @@ mod tests {
PermissionState::Allow
);
let mut perms1 = DenoPermissions::from_flags(&DenoFlags {
let mut perms1 = DenoPermissions::from_flags(&Flags {
read_whitelist: whitelist.clone(),
..Default::default()
});
@ -568,7 +568,7 @@ mod tests {
PermissionState::Allow
);
let mut perms2 = DenoPermissions::from_flags(&DenoFlags {
let mut perms2 = DenoPermissions::from_flags(&Flags {
read_whitelist: whitelist,
..Default::default()
});
@ -584,7 +584,7 @@ mod tests {
fn test_permissions_request_write() {
let guard = PERMISSION_PROMPT_GUARD.lock().unwrap();
let whitelist = vec![PathBuf::from("/foo/bar")];
let mut perms0 = DenoPermissions::from_flags(&DenoFlags {
let mut perms0 = DenoPermissions::from_flags(&Flags {
write_whitelist: whitelist.clone(),
..Default::default()
});
@ -596,7 +596,7 @@ mod tests {
PermissionState::Allow
);
let mut perms1 = DenoPermissions::from_flags(&DenoFlags {
let mut perms1 = DenoPermissions::from_flags(&Flags {
write_whitelist: whitelist.clone(),
..Default::default()
});
@ -606,7 +606,7 @@ mod tests {
PermissionState::Allow
);
let mut perms2 = DenoPermissions::from_flags(&DenoFlags {
let mut perms2 = DenoPermissions::from_flags(&Flags {
write_whitelist: whitelist,
..Default::default()
});
@ -623,7 +623,7 @@ mod tests {
let guard = PERMISSION_PROMPT_GUARD.lock().unwrap();
let whitelist = svec!["localhost:8080"];
let mut perms0 = DenoPermissions::from_flags(&DenoFlags {
let mut perms0 = DenoPermissions::from_flags(&Flags {
net_whitelist: whitelist.clone(),
..Default::default()
});
@ -637,7 +637,7 @@ mod tests {
PermissionState::Allow
);
let mut perms1 = DenoPermissions::from_flags(&DenoFlags {
let mut perms1 = DenoPermissions::from_flags(&Flags {
net_whitelist: whitelist.clone(),
..Default::default()
});
@ -649,7 +649,7 @@ mod tests {
PermissionState::Allow
);
let mut perms2 = DenoPermissions::from_flags(&DenoFlags {
let mut perms2 = DenoPermissions::from_flags(&Flags {
net_whitelist: whitelist.clone(),
..Default::default()
});
@ -661,7 +661,7 @@ mod tests {
PermissionState::Deny
);
let mut perms3 = DenoPermissions::from_flags(&DenoFlags {
let mut perms3 = DenoPermissions::from_flags(&Flags {
net_whitelist: whitelist,
..Default::default()
});
@ -673,13 +673,13 @@ mod tests {
#[test]
fn test_permissions_request_env() {
let guard = PERMISSION_PROMPT_GUARD.lock().unwrap();
let mut perms0 = DenoPermissions::from_flags(&DenoFlags {
let mut perms0 = DenoPermissions::from_flags(&Flags {
..Default::default()
});
set_prompt_result(true);
assert_eq!(perms0.request_env(), PermissionState::Allow);
let mut perms1 = DenoPermissions::from_flags(&DenoFlags {
let mut perms1 = DenoPermissions::from_flags(&Flags {
..Default::default()
});
set_prompt_result(false);
@ -690,13 +690,13 @@ mod tests {
#[test]
fn test_permissions_request_plugin() {
let guard = PERMISSION_PROMPT_GUARD.lock().unwrap();
let mut perms0 = DenoPermissions::from_flags(&DenoFlags {
let mut perms0 = DenoPermissions::from_flags(&Flags {
..Default::default()
});
set_prompt_result(true);
assert_eq!(perms0.request_plugin(), PermissionState::Allow);
let mut perms1 = DenoPermissions::from_flags(&DenoFlags {
let mut perms1 = DenoPermissions::from_flags(&Flags {
..Default::default()
});
set_prompt_result(false);
@ -707,13 +707,13 @@ mod tests {
#[test]
fn test_permissions_request_hrtime() {
let guard = PERMISSION_PROMPT_GUARD.lock().unwrap();
let mut perms0 = DenoPermissions::from_flags(&DenoFlags {
let mut perms0 = DenoPermissions::from_flags(&Flags {
..Default::default()
});
set_prompt_result(true);
assert_eq!(perms0.request_hrtime(), PermissionState::Allow);
let mut perms1 = DenoPermissions::from_flags(&DenoFlags {
let mut perms1 = DenoPermissions::from_flags(&Flags {
..Default::default()
});
set_prompt_result(false);

View file

@ -153,7 +153,7 @@ fn fmt_test() {
#[test]
fn installer_test_local_module_run() {
use deno::flags::DenoFlags;
use deno::flags::Flags;
use deno::installer;
use std::env;
use std::path::PathBuf;
@ -164,7 +164,7 @@ fn installer_test_local_module_run() {
let local_module = env::current_dir().unwrap().join("tests/echo.ts");
let local_module_str = local_module.to_string_lossy();
installer::install(
DenoFlags::default(),
Flags::default(),
Some(temp_dir.path().to_path_buf()),
"echo_test",
&local_module_str,
@ -202,7 +202,7 @@ fn installer_test_local_module_run() {
#[test]
fn installer_test_remote_module_run() {
use deno::flags::DenoFlags;
use deno::flags::Flags;
use deno::installer;
use std::env;
use std::path::PathBuf;
@ -212,7 +212,7 @@ fn installer_test_remote_module_run() {
let g = util::http_server();
let temp_dir = TempDir::new().expect("tempdir fail");
installer::install(
DenoFlags::default(),
Flags::default(),
Some(temp_dir.path().to_path_buf()),
"echo_test",
"http://localhost:4545/cli/tests/echo.ts",

View file

@ -267,7 +267,7 @@ mod tests {
.join("cli/tests/esm_imports_a.js");
let module_specifier =
ModuleSpecifier::resolve_url_or_path(&p.to_string_lossy()).unwrap();
let global_state = GlobalState::new(flags::DenoFlags::default()).unwrap();
let global_state = GlobalState::new(flags::Flags::default()).unwrap();
let state =
State::new(global_state, None, module_specifier.clone()).unwrap();
let state_ = state.clone();
@ -296,7 +296,7 @@ mod tests {
.join("tests/circular1.ts");
let module_specifier =
ModuleSpecifier::resolve_url_or_path(&p.to_string_lossy()).unwrap();
let global_state = GlobalState::new(flags::DenoFlags::default()).unwrap();
let global_state = GlobalState::new(flags::Flags::default()).unwrap();
let state =
State::new(global_state, None, module_specifier.clone()).unwrap();
let state_ = state.clone();
@ -327,12 +327,12 @@ mod tests {
.join("cli/tests/006_url_imports.ts");
let module_specifier =
ModuleSpecifier::resolve_url_or_path(&p.to_string_lossy()).unwrap();
let flags = flags::DenoFlags {
let flags = flags::Flags {
subcommand: flags::DenoSubcommand::Run {
script: module_specifier.to_string(),
},
reload: true,
..flags::DenoFlags::default()
..flags::Flags::default()
};
let global_state = GlobalState::new(flags).unwrap();
let state =