summaryrefslogtreecommitdiff
path: root/cli/flags.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/flags.rs')
-rw-r--r--cli/flags.rs118
1 files changed, 104 insertions, 14 deletions
diff --git a/cli/flags.rs b/cli/flags.rs
index e68b831d5..d90a025a2 100644
--- a/cli/flags.rs
+++ b/cli/flags.rs
@@ -16,8 +16,11 @@ pub struct DenoFlags {
/// the path passed on the command line, otherwise `None`.
pub config_path: Option<String>,
pub allow_read: bool,
+ pub read_whitelist: Vec<String>,
pub allow_write: bool,
+ pub write_whitelist: Vec<String>,
pub allow_net: bool,
+ pub net_whitelist: Vec<String>,
pub allow_env: bool,
pub allow_run: bool,
pub allow_high_precision: bool,
@@ -193,17 +196,29 @@ ability to spawn subprocesses.
",
).arg(
Arg::with_name("allow-read")
- .long("allow-read")
- .help("Allow file system read access"),
- ).arg(
- Arg::with_name("allow-write")
- .long("allow-write")
- .help("Allow file system write access"),
- ).arg(
- Arg::with_name("allow-net")
- .long("allow-net")
- .help("Allow network access"),
- ).arg(
+ .long("allow-read")
+ .min_values(0)
+ .takes_value(true)
+ .use_delimiter(true)
+ .require_equals(true)
+ .help("Allow file system read access"),
+ ).arg(
+ Arg::with_name("allow-write")
+ .long("allow-write")
+ .min_values(0)
+ .takes_value(true)
+ .use_delimiter(true)
+ .require_equals(true)
+ .help("Allow file system write access"),
+ ).arg(
+ Arg::with_name("allow-net")
+ .long("allow-net")
+ .min_values(0)
+ .takes_value(true)
+ .use_delimiter(true)
+ .require_equals(true)
+ .help("Allow network access"),
+ ).arg(
Arg::with_name("allow-env")
.long("allow-env")
.help("Allow environment access"),
@@ -301,13 +316,31 @@ pub fn parse_flags(matches: ArgMatches) -> DenoFlags {
// flags specific to "run" subcommand
if let Some(run_matches) = matches.subcommand_matches("run") {
if run_matches.is_present("allow-read") {
- flags.allow_read = true;
+ if run_matches.value_of("allow-read").is_some() {
+ let read_wl = run_matches.values_of("allow-read").unwrap();
+ flags.read_whitelist =
+ read_wl.map(std::string::ToString::to_string).collect();
+ } else {
+ flags.allow_read = true;
+ }
}
if run_matches.is_present("allow-write") {
- flags.allow_write = true;
+ if run_matches.value_of("allow-write").is_some() {
+ let write_wl = run_matches.values_of("allow-write").unwrap();
+ flags.write_whitelist =
+ write_wl.map(std::string::ToString::to_string).collect();
+ } else {
+ flags.allow_write = true;
+ }
}
if run_matches.is_present("allow-net") {
- flags.allow_net = true;
+ if run_matches.value_of("allow-net").is_some() {
+ let net_wl = run_matches.values_of("allow-net").unwrap();
+ flags.net_whitelist =
+ net_wl.map(std::string::ToString::to_string).collect();
+ } else {
+ flags.allow_net = true;
+ }
}
if run_matches.is_present("allow-env") {
flags.allow_env = true;
@@ -779,4 +812,61 @@ mod tests {
assert_eq!(subcommand, DenoSubcommand::Xeval);
assert_eq!(argv, svec!["deno", "console.log(val)"]);
}
+ #[test]
+ fn test_flags_from_vec_19() {
+ let (flags, subcommand, argv) = flags_from_vec(svec![
+ "deno",
+ "run",
+ "--allow-read=/some/test/dir",
+ "script.ts"
+ ]);
+ assert_eq!(
+ flags,
+ DenoFlags {
+ allow_read: false,
+ read_whitelist: svec!["/some/test/dir"],
+ ..DenoFlags::default()
+ }
+ );
+ assert_eq!(subcommand, DenoSubcommand::Run);
+ assert_eq!(argv, svec!["deno", "script.ts"]);
+ }
+ #[test]
+ fn test_flags_from_vec_20() {
+ let (flags, subcommand, argv) = flags_from_vec(svec![
+ "deno",
+ "run",
+ "--allow-write=/some/test/dir",
+ "script.ts"
+ ]);
+ assert_eq!(
+ flags,
+ DenoFlags {
+ allow_write: false,
+ write_whitelist: svec!["/some/test/dir"],
+ ..DenoFlags::default()
+ }
+ );
+ assert_eq!(subcommand, DenoSubcommand::Run);
+ assert_eq!(argv, svec!["deno", "script.ts"]);
+ }
+ #[test]
+ fn test_flags_from_vec_21() {
+ let (flags, subcommand, argv) = flags_from_vec(svec![
+ "deno",
+ "run",
+ "--allow-net=127.0.0.1",
+ "script.ts"
+ ]);
+ assert_eq!(
+ flags,
+ DenoFlags {
+ allow_net: false,
+ net_whitelist: svec!["127.0.0.1"],
+ ..DenoFlags::default()
+ }
+ );
+ assert_eq!(subcommand, DenoSubcommand::Run);
+ assert_eq!(argv, svec!["deno", "script.ts"]);
+ }
}