Skip to content

Commit

Permalink
apply -c, --lock, --lock-write to fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Nov 23, 2019
1 parent 1d70b93 commit f958891
Showing 1 changed file with 57 additions and 39 deletions.
96 changes: 57 additions & 39 deletions cli/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,16 +380,30 @@ fn info_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
fn fetch_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
flags.subcommand = DenoSubcommand::Fetch;
reload_arg_parse(flags, matches);
lock_args_parse(flags, matches);
importmap_arg_parse(flags, matches);
config_arg_parse(flags, matches);
if let Some(file) = matches.value_of("file") {
flags.argv.push(file.into());
}
}

fn lock_args_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
if matches.is_present("lock") {
let lockfile = matches.value_of("lock").unwrap();
flags.lock = Some(lockfile.to_string());
}
if matches.is_present("lock-write") {
flags.lock_write = true;
}
}

// Shared between the run and test subcommands. They both take similar options.
fn run_test_args_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
reload_arg_parse(flags, matches);
lock_args_parse(flags, matches);
importmap_arg_parse(flags, matches);
config_arg_parse(flags, matches);

if matches.is_present("allow-read") {
if matches.value_of("allow-read").is_some() {
Expand Down Expand Up @@ -450,8 +464,6 @@ fn run_test_args_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
flags.current_thread = true;
}

flags.config_path = matches.value_of("config").map(ToOwned::to_owned);

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);
Expand All @@ -473,15 +485,6 @@ fn run_test_args_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
}
}
}

if matches.is_present("lock") {
let lockfile = matches.value_of("lock").unwrap();
flags.lock = Some(lockfile.to_string());
}

if matches.is_present("lock-write") {
flags.lock_write = true;
}
}

fn run_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) {
Expand Down Expand Up @@ -852,7 +855,10 @@ TypeScript compiler cache: directory containing TS compiler output",
fn fetch_subcommand<'a, 'b>() -> App<'a, 'b> {
SubCommand::with_name("fetch")
.arg(reload_arg())
.arg(lock_arg())
.arg(lock_write_arg())
.arg(importmap_arg())
.arg(config_arg())
.arg(Arg::with_name("file").takes_value(true).required(true))
.about("Fetch the dependencies")
.long_about(
Expand All @@ -876,6 +882,7 @@ fn run_test_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
app
.arg(importmap_arg())
.arg(reload_arg())
.arg(config_arg())
.arg(
Arg::with_name("allow-read")
.long("allow-read")
Expand Down Expand Up @@ -929,14 +936,6 @@ fn run_test_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
.long("no-fetch")
.help("Do not download remote modules"),
)
.arg(
Arg::with_name("config")
.short("c")
.long("config")
.value_name("FILE")
.help("Load tsconfig.json configuration file")
.takes_value(true),
)
.arg(
Arg::with_name("current-thread")
.long("current-thread")
Expand All @@ -953,18 +952,6 @@ fn run_test_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
Err(_) => Err("Seed should be a number".to_string()),
}),
)
.arg(
Arg::with_name("lock")
.long("lock")
.value_name("FILE")
.help("Check the specified lock file")
.takes_value(true),
)
.arg(
Arg::with_name("lock-write")
.long("lock-write")
.help("Write lock file. Use with --lock."),
)
.arg(
Arg::with_name("v8-flags")
.long("v8-flags")
Expand All @@ -978,6 +965,8 @@ fn run_test_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
fn run_subcommand<'a, 'b>() -> App<'a, 'b> {
run_test_args(SubCommand::with_name("run"))
.setting(AppSettings::TrailingVarArg)
.arg(lock_arg())
.arg(lock_write_arg())
.arg(script_arg())
.about("Run a program given a filename or url to the source code")
.long_about(
Expand All @@ -1004,14 +993,7 @@ With only permission to read whitelist files from disk

fn test_subcommand<'a, 'b>() -> App<'a, 'b> {
run_test_args(SubCommand::with_name("test"))
.about("Run tests")
.long_about(
"Run tests using test runner
Automatically downloads test runner on first run.
deno test **/*_test.ts **/test.ts",
)
.arg(lock_arg()) // Note: purposely not including lock_write for deno test.
.arg(
Arg::with_name("failfast")
.short("f")
Expand Down Expand Up @@ -1039,6 +1021,15 @@ Automatically downloads test runner on first run.
.takes_value(true)
.multiple(true),
)
.about("Run tests")
.long_about(
"Run tests using test runner
Searches the specified directories for all files that end in _test.ts or
_test.js and executes them.
deno test src/",
)
}

fn script_arg<'a, 'b>() -> Arg<'a, 'b> {
Expand All @@ -1056,6 +1047,33 @@ fn script_arg_parse(flags: &mut DenoFlags, matches: &ArgMatches) {
}
}

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")
.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")
.help("Load tsconfig.json configuration file")
.takes_value(true)
}

fn config_arg_parse(flags: &mut DenoFlags, matches: &ArgMatches) {
flags.config_path = matches.value_of("config").map(ToOwned::to_owned);
}

fn reload_arg<'a, 'b>() -> Arg<'a, 'b> {
Arg::with_name("reload")
.short("r")
Expand Down

0 comments on commit f958891

Please sign in to comment.