summaryrefslogtreecommitdiff
path: root/cli/args
diff options
context:
space:
mode:
Diffstat (limited to 'cli/args')
-rw-r--r--cli/args/flags.rs189
-rw-r--r--cli/args/mod.rs60
2 files changed, 142 insertions, 107 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs
index 3065e130b..07b60331e 100644
--- a/cli/args/flags.rs
+++ b/cli/args/flags.rs
@@ -69,7 +69,7 @@ pub struct CheckFlags {
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct CompileFlags {
pub source_file: String,
- pub output: Option<PathBuf>,
+ pub output: Option<String>,
pub args: Vec<String>,
pub target: Option<String>,
pub no_terminal: bool,
@@ -102,7 +102,7 @@ pub enum CoverageType {
#[derive(Clone, Debug, Eq, PartialEq, Default)]
pub struct CoverageFlags {
pub files: FileFlags,
- pub output: Option<PathBuf>,
+ pub output: Option<String>,
pub include: Vec<String>,
pub exclude: Vec<String>,
pub r#type: CoverageType,
@@ -123,7 +123,7 @@ impl Default for DocSourceFileFlag {
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct DocHtmlFlag {
pub name: String,
- pub output: PathBuf,
+ pub output: String,
}
#[derive(Clone, Debug, Eq, PartialEq)]
@@ -186,7 +186,7 @@ pub struct InstallFlags {
pub struct JupyterFlags {
pub install: bool,
pub kernel: bool,
- pub conn_file: Option<PathBuf>,
+ pub conn_file: Option<String>,
}
#[derive(Clone, Debug, Eq, PartialEq)]
@@ -250,7 +250,7 @@ pub struct WatchFlags {
#[derive(Clone, Default, Debug, Eq, PartialEq)]
pub struct WatchFlagsWithPaths {
pub hmr: bool,
- pub paths: Vec<PathBuf>,
+ pub paths: Vec<String>,
pub no_clear_screen: bool,
}
@@ -292,13 +292,13 @@ pub struct UpgradeFlags {
pub force: bool,
pub canary: bool,
pub version: Option<String>,
- pub output: Option<PathBuf>,
+ pub output: Option<String>,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct VendorFlags {
pub specifiers: Vec<String>,
- pub output_path: Option<PathBuf>,
+ pub output_path: Option<String>,
pub force: bool,
}
@@ -440,16 +440,16 @@ pub struct Flags {
pub deny_hrtime: bool,
pub allow_net: Option<Vec<String>>,
pub deny_net: Option<Vec<String>>,
- pub allow_ffi: Option<Vec<PathBuf>>,
- pub deny_ffi: Option<Vec<PathBuf>>,
- pub allow_read: Option<Vec<PathBuf>>,
- pub deny_read: Option<Vec<PathBuf>>,
+ pub allow_ffi: Option<Vec<String>>,
+ pub deny_ffi: Option<Vec<String>>,
+ pub allow_read: Option<Vec<String>>,
+ pub deny_read: Option<Vec<String>>,
pub allow_run: Option<Vec<String>>,
pub deny_run: Option<Vec<String>>,
pub allow_sys: Option<Vec<String>>,
pub deny_sys: Option<Vec<String>>,
- pub allow_write: Option<Vec<PathBuf>>,
- pub deny_write: Option<Vec<PathBuf>>,
+ pub allow_write: Option<Vec<String>>,
+ pub deny_write: Option<Vec<String>>,
pub ca_stores: Option<Vec<String>>,
pub ca_data: Option<CaData>,
pub cache_blocklist: Vec<String>,
@@ -464,7 +464,7 @@ pub struct Flags {
pub enable_op_summary_metrics: bool,
pub enable_testing_features: bool,
pub ext: Option<String>,
- pub ignore: Vec<PathBuf>,
+ pub ignore: Vec<String>,
pub import_map_path: Option<String>,
pub env_file: Option<String>,
pub inspect_brk: Option<SocketAddr>,
@@ -472,7 +472,7 @@ pub struct Flags {
pub inspect: Option<SocketAddr>,
pub location: Option<Url>,
pub lock_write: bool,
- pub lock: Option<PathBuf>,
+ pub lock: Option<String>,
pub log_level: Option<Level>,
pub no_remote: bool,
pub no_lock: bool,
@@ -486,10 +486,10 @@ pub struct Flags {
pub v8_flags: Vec<String>,
}
-fn join_paths(allowlist: &[PathBuf], d: &str) -> String {
+fn join_paths(allowlist: &[String], d: &str) -> String {
allowlist
.iter()
- .map(|path| path.to_str().unwrap().to_string())
+ .map(|path| path.to_string())
.collect::<Vec<String>>()
.join(d)
}
@@ -1348,8 +1348,7 @@ supported in canary.
Arg::new("output")
.long("output")
.short('o')
- // todo(dsherret): remove value_parser!(PathBuf) and instead parse as string
- .value_parser(value_parser!(PathBuf))
+ .value_parser(value_parser!(String))
.help("Output file (defaults to $PWD/<inferred-name>)")
.value_hint(ValueHint::FilePath),
)
@@ -1473,8 +1472,7 @@ Generate html reports from lcov:
Arg::new("output")
.requires("lcov")
.long("output")
- // todo(dsherret): remove value_parser!(PathBuf) and instead parse as string
- .value_parser(value_parser!(PathBuf))
+ .value_parser(value_parser!(String))
.help("Output file (defaults to stdout) for lcov")
.long_help(
"Exports the coverage report in lcov format to the given file.
@@ -1580,8 +1578,7 @@ Show documentation for runtime built-ins:
.action(ArgAction::Set)
.require_equals(true)
.value_hint(ValueHint::DirPath)
- // todo(dsherret): remove value_parser!(PathBuf) and instead parse as string
- .value_parser(value_parser!(PathBuf))
+ .value_parser(value_parser!(String))
)
.arg(
Arg::new("private")
@@ -1922,8 +1919,7 @@ fn jupyter_subcommand() -> Command {
Arg::new("conn")
.long("conn")
.help("Path to JSON file describing connection parameters, provided by Jupyter")
- // todo(dsherret): remove value_parser!(PathBuf) and instead parse as string
- .value_parser(value_parser!(PathBuf))
+ .value_parser(value_parser!(String))
.value_hint(ValueHint::FilePath)
.conflicts_with("install"))
.about("Deno kernel for Jupyter notebooks")
@@ -2346,8 +2342,7 @@ update to a different location, use the --output flag
Arg::new("output")
.long("output")
.help("The path to output the updated version to")
- // todo(dsherret): remove value_parser!(PathBuf) and instead parse as string
- .value_parser(value_parser!(PathBuf))
+ .value_parser(value_parser!(String))
.value_hint(ValueHint::FilePath),
)
.arg(
@@ -2401,8 +2396,7 @@ Remote modules and multiple modules may also be specified:
Arg::new("output")
.long("output")
.help("The directory to output the vendored modules to")
- // todo(dsherret): remove value_parser!(PathBuf) and instead parse as string
- .value_parser(value_parser!(PathBuf))
+ .value_parser(value_parser!(String))
.value_hint(ValueHint::DirPath),
)
.arg(
@@ -2656,8 +2650,7 @@ fn permission_args(app: Command) -> Command {
.require_equals(true)
.value_name("PATH")
.help(ALLOW_READ_HELP)
- // todo(dsherret): remove value_parser!(PathBuf) and instead parse as string
- .value_parser(value_parser!(PathBuf))
+ .value_parser(value_parser!(String))
.value_hint(ValueHint::AnyPath),
)
.arg(
@@ -2668,8 +2661,7 @@ fn permission_args(app: Command) -> Command {
.require_equals(true)
.value_name("PATH")
.help(DENY_READ_HELP)
- // todo(dsherret): remove value_parser!(PathBuf) and instead parse as string
- .value_parser(value_parser!(PathBuf))
+ .value_parser(value_parser!(String))
.value_hint(ValueHint::AnyPath),
)
.arg(
@@ -2680,8 +2672,7 @@ fn permission_args(app: Command) -> Command {
.require_equals(true)
.value_name("PATH")
.help(ALLOW_WRITE_HELP)
- // todo(dsherret): remove value_parser!(PathBuf) and instead parse as string
- .value_parser(value_parser!(PathBuf))
+ .value_parser(value_parser!(String))
.value_hint(ValueHint::AnyPath),
)
.arg(
@@ -2692,8 +2683,7 @@ fn permission_args(app: Command) -> Command {
.require_equals(true)
.value_name("PATH")
.help(DENY_WRITE_HELP)
- // todo(dsherret): remove value_parser!(PathBuf) and instead parse as string
- .value_parser(value_parser!(PathBuf))
+ .value_parser(value_parser!(String))
.value_hint(ValueHint::AnyPath),
)
.arg(
@@ -2803,8 +2793,7 @@ fn permission_args(app: Command) -> Command {
.require_equals(true)
.value_name("PATH")
.help(ALLOW_FFI_HELP)
- // todo(dsherret): remove value_parser!(PathBuf) and instead parse as string
- .value_parser(value_parser!(PathBuf))
+ .value_parser(value_parser!(String))
.value_hint(ValueHint::AnyPath),
)
.arg(
@@ -2815,8 +2804,7 @@ fn permission_args(app: Command) -> Command {
.require_equals(true)
.value_name("PATH")
.help(DENY_FFI_HELP)
- // todo(dsherret): remove value_parser!(PathBuf) and instead parse as string
- .value_parser(value_parser!(PathBuf))
+ .value_parser(value_parser!(String))
.value_hint(ValueHint::AnyPath),
)
.arg(
@@ -3056,8 +3044,7 @@ fn hmr_arg(takes_files: bool) -> Arg {
arg
.value_name("FILES")
.num_args(0..)
- // todo(dsherret): remove value_parser!(PathBuf) and instead parse as string
- .value_parser(value_parser!(PathBuf))
+ .value_parser(value_parser!(String))
.use_value_delimiter(true)
.require_equals(true)
.long_help(
@@ -3083,8 +3070,7 @@ fn watch_arg(takes_files: bool) -> Arg {
arg
.value_name("FILES")
.num_args(0..)
- // todo(dsherret): remove value_parser!(PathBuf) and instead parse as string
- .value_parser(value_parser!(PathBuf))
+ .value_parser(value_parser!(String))
.use_value_delimiter(true)
.require_equals(true)
.long_help(
@@ -3175,8 +3161,7 @@ fn lock_arg() -> Arg {
If value is not provided, defaults to \"deno.lock\" in the current working directory.")
.num_args(0..=1)
- // todo(dsherret): remove value_parser!(PathBuf) and instead parse as string
- .value_parser(value_parser!(PathBuf))
+ .value_parser(value_parser!(String))
.value_hint(ValueHint::FilePath)
}
@@ -3362,7 +3347,7 @@ fn compile_parse(flags: &mut Flags, matches: &mut ArgMatches) {
let mut script = matches.remove_many::<String>("script_arg").unwrap();
let source_file = script.next().unwrap();
let args = script.collect();
- let output = matches.remove_one::<PathBuf>("output");
+ let output = matches.remove_one::<String>("output");
let target = matches.remove_one::<String>("target");
let no_terminal = matches.get_flag("no-terminal");
let include = match matches.remove_many::<String>("include") {
@@ -3436,7 +3421,7 @@ fn coverage_parse(flags: &mut Flags, matches: &mut ArgMatches) {
} else {
CoverageType::Summary
};
- let output = matches.remove_one::<PathBuf>("output");
+ let output = matches.remove_one::<String>("output");
flags.subcommand = DenoSubcommand::Coverage(CoverageFlags {
files: FileFlags {
include: files,
@@ -3482,8 +3467,8 @@ fn doc_parse(flags: &mut Flags, matches: &mut ArgMatches) {
let html = if matches.get_flag("html") {
let name = matches.remove_one::<String>("name").unwrap();
let output = matches
- .remove_one::<PathBuf>("output")
- .unwrap_or(PathBuf::from("./docs/"));
+ .remove_one::<String>("output")
+ .unwrap_or(String::from("./docs/"));
Some(DocHtmlFlag { name, output })
} else {
None
@@ -3605,7 +3590,7 @@ fn install_parse(flags: &mut Flags, matches: &mut ArgMatches) {
}
fn jupyter_parse(flags: &mut Flags, matches: &mut ArgMatches) {
- let conn_file = matches.remove_one::<PathBuf>("conn");
+ let conn_file = matches.remove_one::<String>("conn");
let kernel = matches.get_flag("kernel");
let install = matches.get_flag("install");
@@ -3871,7 +3856,7 @@ fn upgrade_parse(flags: &mut Flags, matches: &mut ArgMatches) {
let force = matches.get_flag("force");
let canary = matches.get_flag("canary");
let version = matches.remove_one::<String>("version");
- let output = matches.remove_one::<PathBuf>("output");
+ let output = matches.remove_one::<String>("output");
flags.subcommand = DenoSubcommand::Upgrade(UpgradeFlags {
dry_run,
force,
@@ -3894,7 +3879,7 @@ fn vendor_parse(flags: &mut Flags, matches: &mut ArgMatches) {
.remove_many::<String>("specifiers")
.map(|p| p.collect())
.unwrap_or_default(),
- output_path: matches.remove_one::<PathBuf>("output"),
+ output_path: matches.remove_one::<String>("output"),
force: matches.get_flag("force"),
});
}
@@ -3936,19 +3921,19 @@ fn compile_args_without_check_parse(
fn permission_args_parse(flags: &mut Flags, matches: &mut ArgMatches) {
unsafely_ignore_certificate_errors_parse(flags, matches);
- if let Some(read_wl) = matches.remove_many::<PathBuf>("allow-read") {
+ if let Some(read_wl) = matches.remove_many::<String>("allow-read") {
flags.allow_read = Some(read_wl.collect());
}
- if let Some(read_wl) = matches.remove_many::<PathBuf>("deny-read") {
+ if let Some(read_wl) = matches.remove_many::<String>("deny-read") {
flags.deny_read = Some(read_wl.collect());
}
- if let Some(write_wl) = matches.remove_many::<PathBuf>("allow-write") {
+ if let Some(write_wl) = matches.remove_many::<String>("allow-write") {
flags.allow_write = Some(write_wl.collect());
}
- if let Some(write_wl) = matches.remove_many::<PathBuf>("deny-write") {
+ if let Some(write_wl) = matches.remove_many::<String>("deny-write") {
flags.deny_write = Some(write_wl.collect());
}
@@ -3992,12 +3977,12 @@ fn permission_args_parse(flags: &mut Flags, matches: &mut ArgMatches) {
debug!("sys info denylist: {:#?}", &flags.deny_sys);
}
- if let Some(ffi_wl) = matches.remove_many::<PathBuf>("allow-ffi") {
+ if let Some(ffi_wl) = matches.remove_many::<String>("allow-ffi") {
flags.allow_ffi = Some(ffi_wl.collect());
debug!("ffi allowlist: {:#?}", &flags.allow_ffi);
}
- if let Some(ffi_wl) = matches.remove_many::<PathBuf>("deny-ffi") {
+ if let Some(ffi_wl) = matches.remove_many::<String>("deny-ffi") {
flags.deny_ffi = Some(ffi_wl.collect());
debug!("ffi denylist: {:#?}", &flags.deny_ffi);
}
@@ -4191,8 +4176,8 @@ fn lock_args_parse(flags: &mut Flags, matches: &mut ArgMatches) {
fn lock_arg_parse(flags: &mut Flags, matches: &mut ArgMatches) {
if matches.contains_id("lock") {
let lockfile = matches
- .remove_one::<PathBuf>("lock")
- .unwrap_or_else(|| PathBuf::from("./deno.lock"));
+ .remove_one::<String>("lock")
+ .unwrap_or_else(|| String::from("./deno.lock"));
flags.lock = Some(lockfile);
}
}
@@ -4257,7 +4242,7 @@ fn watch_arg_parse(matches: &mut ArgMatches) -> Option<WatchFlags> {
fn watch_arg_parse_with_paths(
matches: &mut ArgMatches,
) -> Option<WatchFlagsWithPaths> {
- if let Some(paths) = matches.remove_many::<PathBuf>("watch") {
+ if let Some(paths) = matches.remove_many::<String>("watch") {
return Some(WatchFlagsWithPaths {
paths: paths.collect(),
hmr: false,
@@ -4266,7 +4251,7 @@ fn watch_arg_parse_with_paths(
}
matches
- .remove_many::<PathBuf>("hmr")
+ .remove_many::<String>("hmr")
.map(|paths| WatchFlagsWithPaths {
paths: paths.collect(),
hmr: true,
@@ -4349,6 +4334,24 @@ mod tests {
}
#[test]
+ fn upgrade_with_output_flag() {
+ let r = flags_from_vec(svec!["deno", "upgrade", "--output", "example.txt"]);
+ assert_eq!(
+ r.unwrap(),
+ Flags {
+ subcommand: DenoSubcommand::Upgrade(UpgradeFlags {
+ force: false,
+ dry_run: false,
+ canary: false,
+ version: None,
+ output: Some(String::from("example.txt")),
+ }),
+ ..Flags::default()
+ }
+ );
+ }
+
+ #[test]
fn version() {
let r = flags_from_vec(svec!["deno", "--version"]);
assert_eq!(
@@ -4458,7 +4461,7 @@ mod tests {
script: "script.ts".to_string(),
watch: Some(WatchFlagsWithPaths {
hmr: true,
- paths: vec![PathBuf::from("foo.txt")],
+ paths: vec![String::from("foo.txt")],
no_clear_screen: true,
}),
}),
@@ -4483,7 +4486,7 @@ mod tests {
script: "script.ts".to_string(),
watch: Some(WatchFlagsWithPaths {
hmr: false,
- paths: vec![PathBuf::from("file1"), PathBuf::from("file2")],
+ paths: vec![String::from("file1"), String::from("file2")],
no_clear_screen: false,
}),
}),
@@ -5517,7 +5520,7 @@ mod tests {
config_flag: ConfigFlag::Path("tsconfig.json".to_owned()),
type_check_mode: TypeCheckMode::None,
reload: true,
- lock: Some(PathBuf::from("lock.json")),
+ lock: Some(String::from("lock.json")),
lock_write: true,
ca_data: Some(CaData::File("example.crt".to_string())),
cached_only: true,
@@ -5632,7 +5635,7 @@ mod tests {
config_flag: ConfigFlag::Path("tsconfig.json".to_owned()),
type_check_mode: TypeCheckMode::None,
reload: true,
- lock: Some(PathBuf::from("lock.json")),
+ lock: Some(String::from("lock.json")),
lock_write: true,
ca_data: Some(CaData::File("example.crt".to_string())),
cached_only: true,
@@ -5701,18 +5704,18 @@ mod tests {
fn allow_read_allowlist() {
use test_util::TempDir;
let temp_dir_guard = TempDir::new();
- let temp_dir = temp_dir_guard.path().to_path_buf();
+ let temp_dir = temp_dir_guard.path().to_string();
let r = flags_from_vec(svec![
"deno",
"run",
- format!("--allow-read=.,{}", temp_dir.to_str().unwrap()),
+ format!("--allow-read=.,{}", temp_dir),
"script.ts"
]);
assert_eq!(
r.unwrap(),
Flags {
- allow_read: Some(vec![PathBuf::from("."), temp_dir]),
+ allow_read: Some(vec![String::from("."), temp_dir]),
subcommand: DenoSubcommand::Run(RunFlags::new_default(
"script.ts".to_string(),
)),
@@ -5725,18 +5728,18 @@ mod tests {
fn deny_read_denylist() {
use test_util::TempDir;
let temp_dir_guard = TempDir::new();
- let temp_dir = temp_dir_guard.path().to_path_buf();
+ let temp_dir = temp_dir_guard.path().to_string();
let r = flags_from_vec(svec![
"deno",
"run",
- format!("--deny-read=.,{}", temp_dir.to_str().unwrap()),
+ format!("--deny-read=.,{}", temp_dir),
"script.ts"
]);
assert_eq!(
r.unwrap(),
Flags {
- deny_read: Some(vec![PathBuf::from("."), temp_dir]),
+ deny_read: Some(vec![String::from("."), temp_dir]),
subcommand: DenoSubcommand::Run(RunFlags::new_default(
"script.ts".to_string(),
)),
@@ -5749,18 +5752,18 @@ mod tests {
fn allow_write_allowlist() {
use test_util::TempDir;
let temp_dir_guard = TempDir::new();
- let temp_dir = temp_dir_guard.path().to_path_buf();
+ let temp_dir = temp_dir_guard.path().to_string();
let r = flags_from_vec(svec![
"deno",
"run",
- format!("--allow-write=.,{}", temp_dir.to_str().unwrap()),
+ format!("--allow-write=.,{}", temp_dir),
"script.ts"
]);
assert_eq!(
r.unwrap(),
Flags {
- allow_write: Some(vec![PathBuf::from("."), temp_dir]),
+ allow_write: Some(vec![String::from("."), temp_dir]),
subcommand: DenoSubcommand::Run(RunFlags::new_default(
"script.ts".to_string(),
)),
@@ -5773,18 +5776,18 @@ mod tests {
fn deny_write_denylist() {
use test_util::TempDir;
let temp_dir_guard = TempDir::new();
- let temp_dir = temp_dir_guard.path().to_path_buf();
+ let temp_dir = temp_dir_guard.path().to_string();
let r = flags_from_vec(svec![
"deno",
"run",
- format!("--deny-write=.,{}", temp_dir.to_str().unwrap()),
+ format!("--deny-write=.,{}", temp_dir),
"script.ts"
]);
assert_eq!(
r.unwrap(),
Flags {
- deny_write: Some(vec![PathBuf::from("."), temp_dir]),
+ deny_write: Some(vec![String::from("."), temp_dir]),
subcommand: DenoSubcommand::Run(RunFlags::new_default(
"script.ts".to_string(),
)),
@@ -6226,7 +6229,7 @@ mod tests {
}),
type_check_mode: TypeCheckMode::Local,
lock_write: true,
- lock: Some(PathBuf::from("lock.json")),
+ lock: Some(String::from("lock.json")),
..Flags::default()
}
);
@@ -6523,7 +6526,7 @@ mod tests {
config_flag: ConfigFlag::Path("tsconfig.json".to_owned()),
type_check_mode: TypeCheckMode::None,
reload: true,
- lock: Some(PathBuf::from("lock.json")),
+ lock: Some(String::from("lock.json")),
lock_write: true,
ca_data: Some(CaData::File("example.crt".to_string())),
cached_only: true,
@@ -7054,7 +7057,7 @@ mod tests {
"script.ts".to_string(),
)),
lock_write: true,
- lock: Some(PathBuf::from("lock.json")),
+ lock: Some(String::from("lock.json")),
..Flags::default()
}
);
@@ -7085,7 +7088,7 @@ mod tests {
"script.ts".to_string(),
)),
lock_write: true,
- lock: Some(PathBuf::from("./deno.lock")),
+ lock: Some(String::from("./deno.lock")),
..Flags::default()
}
);
@@ -7105,7 +7108,7 @@ mod tests {
"script.ts".to_string(),
)),
lock_write: true,
- lock: Some(PathBuf::from("lock.json")),
+ lock: Some(String::from("lock.json")),
..Flags::default()
}
);
@@ -7692,7 +7695,7 @@ mod tests {
lint: false,
html: Some(DocHtmlFlag {
name: "My library".to_string(),
- output: PathBuf::from("./docs/"),
+ output: String::from("./docs/"),
}),
source_files: DocSourceFileFlag::Paths(svec!["path/to/module.ts"]),
filter: None,
@@ -7718,7 +7721,7 @@ mod tests {
json: false,
html: Some(DocHtmlFlag {
name: "My library".to_string(),
- output: PathBuf::from("./foo"),
+ output: String::from("./foo"),
}),
lint: true,
source_files: DocSourceFileFlag::Paths(svec!["path/to/module.ts"]),
@@ -7979,7 +7982,7 @@ mod tests {
subcommand: DenoSubcommand::Compile(CompileFlags {
source_file: "https://examples.deno.land/color-logging.ts"
.to_string(),
- output: Some(PathBuf::from("colors")),
+ output: Some(String::from("colors")),
args: svec!["foo", "bar", "-p", "8080"],
target: None,
no_terminal: true,
@@ -7990,7 +7993,7 @@ mod tests {
config_flag: ConfigFlag::Path("tsconfig.json".to_owned()),
type_check_mode: TypeCheckMode::None,
reload: true,
- lock: Some(PathBuf::from("lock.json")),
+ lock: Some(String::from("lock.json")),
lock_write: true,
ca_data: Some(CaData::File("example.crt".to_string())),
cached_only: true,
@@ -8046,7 +8049,7 @@ mod tests {
include: vec![r"^file:".to_string()],
exclude: vec![r"test\.(js|mjs|ts|jsx|tsx)$".to_string()],
r#type: CoverageType::Lcov,
- output: Some(PathBuf::from("foo.lcov")),
+ output: Some(String::from("foo.lcov")),
}),
..Flags::default()
}
@@ -8163,11 +8166,11 @@ mod tests {
subcommand: DenoSubcommand::Vendor(VendorFlags {
specifiers: svec!["mod.ts", "deps.test.ts"],
force: true,
- output_path: Some(PathBuf::from("out_dir")),
+ output_path: Some(String::from("out_dir")),
}),
config_flag: ConfigFlag::Path("deno.json".to_owned()),
import_map_path: Some("import_map.json".to_string()),
- lock: Some(PathBuf::from("lock.json")),
+ lock: Some(String::from("lock.json")),
reload: true,
..Flags::default()
}
@@ -8602,7 +8605,7 @@ mod tests {
subcommand: DenoSubcommand::Jupyter(JupyterFlags {
install: false,
kernel: true,
- conn_file: Some(PathBuf::from("path/to/conn/file")),
+ conn_file: Some(String::from("path/to/conn/file")),
}),
..Flags::default()
}
diff --git a/cli/args/mod.rs b/cli/args/mod.rs
index f22567d61..e7913eddc 100644
--- a/cli/args/mod.rs
+++ b/cli/args/mod.rs
@@ -1476,16 +1476,34 @@ impl CliOptions {
deny_hrtime: self.flags.deny_hrtime,
allow_net: self.flags.allow_net.clone(),
deny_net: self.flags.deny_net.clone(),
- allow_ffi: self.flags.allow_ffi.clone(),
- deny_ffi: self.flags.deny_ffi.clone(),
- allow_read: self.flags.allow_read.clone(),
- deny_read: self.flags.deny_read.clone(),
+ allow_ffi: convert_option_str_to_path_buf(
+ &self.flags.allow_ffi,
+ self.initial_cwd(),
+ ),
+ deny_ffi: convert_option_str_to_path_buf(
+ &self.flags.deny_ffi,
+ self.initial_cwd(),
+ ),
+ allow_read: convert_option_str_to_path_buf(
+ &self.flags.allow_read,
+ self.initial_cwd(),
+ ),
+ deny_read: convert_option_str_to_path_buf(
+ &self.flags.deny_read,
+ self.initial_cwd(),
+ ),
allow_run: self.flags.allow_run.clone(),
deny_run: self.flags.deny_run.clone(),
allow_sys: self.flags.allow_sys.clone(),
deny_sys: self.flags.deny_sys.clone(),
- allow_write: self.flags.allow_write.clone(),
- deny_write: self.flags.deny_write.clone(),
+ allow_write: convert_option_str_to_path_buf(
+ &self.flags.allow_write,
+ self.initial_cwd(),
+ ),
+ deny_write: convert_option_str_to_path_buf(
+ &self.flags.deny_write,
+ self.initial_cwd(),
+ ),
prompt: !self.no_prompt(),
}
}
@@ -1584,29 +1602,29 @@ impl CliOptions {
}
pub fn watch_paths(&self) -> Vec<PathBuf> {
- let mut paths = if let DenoSubcommand::Run(RunFlags {
+ let mut full_paths = Vec::new();
+ if let DenoSubcommand::Run(RunFlags {
watch: Some(WatchFlagsWithPaths { paths, .. }),
..
}) = &self.flags.subcommand
{
- paths.clone()
- } else {
- Vec::with_capacity(2)
- };
+ full_paths.extend(paths.iter().map(|path| self.initial_cwd.join(path)));
+ }
+
if let Ok(Some(import_map_path)) = self
.resolve_specified_import_map_specifier()
.map(|ms| ms.and_then(|ref s| s.to_file_path().ok()))
{
- paths.push(import_map_path);
+ full_paths.push(import_map_path);
}
if let Some(specifier) = self.maybe_config_file_specifier() {
if specifier.scheme() == "file" {
if let Ok(path) = specifier.to_file_path() {
- paths.push(path);
+ full_paths.push(path);
}
}
}
- paths
+ full_paths
}
}
@@ -1784,6 +1802,20 @@ pub fn npm_pkg_req_ref_to_binary_command(
binary_name.to_string()
}
+fn convert_option_str_to_path_buf(
+ flag: &Option<Vec<String>>,
+ initial_cwd: &Path,
+) -> Option<Vec<PathBuf>> {
+ if let Some(allow_ffi_paths) = &flag {
+ let mut full_paths = Vec::new();
+ full_paths
+ .extend(allow_ffi_paths.iter().map(|path| initial_cwd.join(path)));
+ Some(full_paths)
+ } else {
+ None
+ }
+}
+
#[cfg(test)]
mod test {
use crate::util::fs::FileCollector;