0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 17:34:47 -05:00

add "deno run" subcommand (#2215)

This commit is contained in:
Bartek Iwańczuk 2019-05-03 23:15:16 +02:00 committed by Ryan Dahl
parent 3608117132
commit f6a9d7d717
54 changed files with 314 additions and 210 deletions

View file

@ -36,75 +36,41 @@ pub fn create_cli_app<'a, 'b>() -> App<'a, 'b> {
App::new("deno") App::new("deno")
.bin_name("deno") .bin_name("deno")
.global_settings(&[AppSettings::ColorNever]) .global_settings(&[AppSettings::ColorNever])
.settings(&[ .settings(&[AppSettings::DisableVersion])
AppSettings::AllowExternalSubcommands, .after_help(ENV_VARIABLES_HELP)
AppSettings::DisableVersion,
]).after_help(ENV_VARIABLES_HELP)
.arg( .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(
Arg::with_name("allow-env")
.long("allow-env")
.help("Allow environment access"),
).arg(
Arg::with_name("allow-run")
.long("allow-run")
.help("Allow running subprocesses"),
).arg(
Arg::with_name("allow-high-precision")
.long("allow-high-precision")
.help("Allow high precision time measurement"),
).arg(
Arg::with_name("allow-all")
.short("A")
.long("allow-all")
.help("Allow all permissions"),
).arg(
Arg::with_name("no-prompt")
.long("no-prompt")
.help("Do not use prompts"),
).arg(
Arg::with_name("no-fetch")
.long("no-fetch")
.help("Do not download remote modules"),
).arg(
Arg::with_name("log-debug") Arg::with_name("log-debug")
.short("D") .short("D")
.long("log-debug") .long("log-debug")
.help("Log debug output"), .help("Log debug output")
.global(true),
).arg( ).arg(
Arg::with_name("reload") Arg::with_name("reload")
.short("r") .short("r")
.long("reload") .long("reload")
.help("Reload source code cache (recompile TypeScript)"), .help("Reload source code cache (recompile TypeScript)")
.global(true),
).arg( ).arg(
Arg::with_name("config") Arg::with_name("config")
.short("c") .short("c")
.long("config") .long("config")
.value_name("FILE") .value_name("FILE")
.help("Load compiler configuration file") .help("Load compiler configuration file")
.takes_value(true), .takes_value(true)
.global(true),
).arg( ).arg(
Arg::with_name("v8-options") Arg::with_name("v8-options")
.long("v8-options") .long("v8-options")
.help("Print V8 command line options"), .help("Print V8 command line options")
.global(true),
).arg( ).arg(
Arg::with_name("v8-flags") Arg::with_name("v8-flags")
.long("v8-flags") .long("v8-flags")
.takes_value(true) .takes_value(true)
.use_delimiter(true) .use_delimiter(true)
.require_equals(true) .require_equals(true)
.help("Set V8 command line options"), .help("Set V8 command line options")
.global(true),
).subcommand( ).subcommand(
SubCommand::with_name("version") SubCommand::with_name("version")
.setting(AppSettings::DisableVersion) .setting(AppSettings::DisableVersion)
@ -196,7 +162,69 @@ Prettier dependencies on first run.
.required(true), .required(true),
), ),
).subcommand( ).subcommand(
SubCommand::with_name("xeval") SubCommand::with_name("run")
.settings(&[
AppSettings::AllowExternalSubcommands,
AppSettings::DisableHelpSubcommand,
AppSettings::DisableVersion,
AppSettings::SubcommandRequired,
]).about("Run a program given a filename or url to the source code")
.long_about(
"
Run a program given a filename or url to the source code.
By default all programs are run in sandbox without access to disk, network or
ability to spawn subprocesses.
deno run https://deno.land/welcome.ts
# run program with permission to read from disk and listen to network
deno run --allow-net --allow-read https://deno.land/std/http/file_server.ts
# run program with all permissions
deno run -A https://deno.land/std/http/file_server.ts
",
).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(
Arg::with_name("allow-env")
.long("allow-env")
.help("Allow environment access"),
).arg(
Arg::with_name("allow-run")
.long("allow-run")
.help("Allow running subprocesses"),
).arg(
Arg::with_name("allow-high-precision")
.long("allow-high-precision")
.help("Allow high precision time measurement"),
).arg(
Arg::with_name("allow-all")
.short("A")
.long("allow-all")
.help("Allow all permissions"),
).arg(
Arg::with_name("no-prompt")
.long("no-prompt")
.help("Do not use prompts"),
).subcommand(
// this is a fake subcommand - it's used in conjunction with
// AppSettings:AllowExternalSubcommand to treat it as an
// entry point script
SubCommand::with_name("<script>").about("Script to run"),
),
).subcommand(
SubCommand::with_name("xeval")
.setting(AppSettings::DisableVersion) .setting(AppSettings::DisableVersion)
.about("Eval a script on text segments from stdin") .about("Eval a script on text segments from stdin")
.long_about( .long_about(
@ -226,14 +254,8 @@ Otherwise '$' will be used as default variable name.
.help("Set delimiter, defaults to newline") .help("Set delimiter, defaults to newline")
.takes_value(true), .takes_value(true),
).arg(Arg::with_name("code").takes_value(true).required(true)), ).arg(Arg::with_name("code").takes_value(true).required(true)),
).subcommand(
// this is a fake subcommand - it's used in conjunction with
// AppSettings:AllowExternalSubcommand to treat it as an
// entry point script
SubCommand::with_name("<script>").about("Script to run"),
) )
} }
/// Parse ArgMatches into internal DenoFlags structure. /// Parse ArgMatches into internal DenoFlags structure.
/// This method should not make any side effects. /// This method should not make any side effects.
#[cfg_attr(feature = "cargo-clippy", allow(stutter))] #[cfg_attr(feature = "cargo-clippy", allow(stutter))]
@ -250,39 +272,6 @@ pub fn parse_flags(matches: ArgMatches) -> DenoFlags {
flags.reload = true; flags.reload = true;
} }
flags.config_path = matches.value_of("config").map(ToOwned::to_owned); flags.config_path = matches.value_of("config").map(ToOwned::to_owned);
if matches.is_present("allow-read") {
flags.allow_read = true;
}
if matches.is_present("allow-write") {
flags.allow_write = true;
}
if matches.is_present("allow-net") {
flags.allow_net = true;
}
if matches.is_present("allow-env") {
flags.allow_env = true;
}
if matches.is_present("allow-run") {
flags.allow_run = true;
}
if matches.is_present("allow-high-precision") {
flags.allow_high_precision = true;
}
if matches.is_present("allow-all") {
flags.allow_read = true;
flags.allow_env = true;
flags.allow_net = true;
flags.allow_run = true;
flags.allow_read = true;
flags.allow_write = true;
flags.allow_high_precision = true;
}
if matches.is_present("no-prompt") {
flags.no_prompts = true;
}
if matches.is_present("no-fetch") {
flags.no_fetch = true;
}
if matches.is_present("v8-options") { if matches.is_present("v8-options") {
let v8_flags = svec!["deno", "--help"]; let v8_flags = svec!["deno", "--help"];
flags.v8_flags = Some(v8_flags); flags.v8_flags = Some(v8_flags);
@ -298,6 +287,40 @@ pub fn parse_flags(matches: ArgMatches) -> DenoFlags {
flags.v8_flags = Some(v8_flags); flags.v8_flags = Some(v8_flags);
} }
// 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.is_present("allow-write") {
flags.allow_write = true;
}
if run_matches.is_present("allow-net") {
flags.allow_net = true;
}
if run_matches.is_present("allow-env") {
flags.allow_env = true;
}
if run_matches.is_present("allow-run") {
flags.allow_run = true;
}
if run_matches.is_present("allow-high-precision") {
flags.allow_high_precision = true;
}
if run_matches.is_present("allow-all") {
flags.allow_read = true;
flags.allow_env = true;
flags.allow_net = true;
flags.allow_run = true;
flags.allow_read = true;
flags.allow_write = true;
flags.allow_high_precision = true;
}
if run_matches.is_present("no-prompt") {
flags.no_prompts = true;
}
}
flags flags
} }
@ -314,6 +337,7 @@ pub enum DenoSubcommand {
Repl, Repl,
Run, Run,
Types, Types,
Version,
Xeval, Xeval,
} }
@ -327,6 +351,12 @@ pub fn flags_from_vec(
let subcommand = match matches.subcommand() { let subcommand = match matches.subcommand() {
("eval", Some(eval_match)) => { ("eval", Some(eval_match)) => {
flags.allow_net = true;
flags.allow_env = true;
flags.allow_run = true;
flags.allow_read = true;
flags.allow_write = true;
flags.allow_high_precision = true;
let code: &str = eval_match.value_of("code").unwrap(); let code: &str = eval_match.value_of("code").unwrap();
argv.extend(vec![code.to_string()]); argv.extend(vec![code.to_string()]);
DenoSubcommand::Eval DenoSubcommand::Eval
@ -356,6 +386,25 @@ pub fn flags_from_vec(
DenoSubcommand::Info DenoSubcommand::Info
} }
("types", Some(_)) => DenoSubcommand::Types, ("types", Some(_)) => DenoSubcommand::Types,
("run", Some(run_match)) => {
match run_match.subcommand() {
(script, Some(script_match)) => {
argv.extend(vec![script.to_string()]);
// check if there are any extra arguments that should
// be passed to script
if script_match.is_present("") {
let script_args: Vec<String> = script_match
.values_of("")
.unwrap()
.map(String::from)
.collect();
argv.extend(script_args);
}
DenoSubcommand::Run
}
_ => unreachable!(),
}
}
("xeval", Some(eval_match)) => { ("xeval", Some(eval_match)) => {
let code: &str = eval_match.value_of("code").unwrap(); let code: &str = eval_match.value_of("code").unwrap();
flags.xeval_replvar = flags.xeval_replvar =
@ -367,21 +416,16 @@ pub fn flags_from_vec(
argv.extend(vec![code.to_string()]); argv.extend(vec![code.to_string()]);
DenoSubcommand::Xeval DenoSubcommand::Xeval
} }
(script, Some(script_match)) => { ("version", Some(_)) => DenoSubcommand::Version,
argv.extend(vec![script.to_string()]); _ => {
// check if there are any extra arguments that should flags.allow_net = true;
// be passed to script flags.allow_env = true;
if script_match.is_present("") { flags.allow_run = true;
let script_args: Vec<String> = script_match flags.allow_read = true;
.values_of("") flags.allow_write = true;
.unwrap() flags.allow_high_precision = true;
.map(String::from) DenoSubcommand::Repl
.collect();
argv.extend(script_args);
}
DenoSubcommand::Run
} }
_ => DenoSubcommand::Repl,
}; };
(flags, subcommand, argv) (flags, subcommand, argv)
@ -401,14 +445,14 @@ mod tests {
..DenoFlags::default() ..DenoFlags::default()
} }
); );
assert_eq!(subcommand, DenoSubcommand::Run); assert_eq!(subcommand, DenoSubcommand::Version);
assert_eq!(argv, svec!["deno", "version"]); assert_eq!(argv, svec!["deno"]);
} }
#[test] #[test]
fn test_flags_from_vec_2() { fn test_flags_from_vec_2() {
let (flags, subcommand, argv) = let (flags, subcommand, argv) =
flags_from_vec(svec!["deno", "-r", "-D", "script.ts"]); flags_from_vec(svec!["deno", "-r", "-D", "run", "script.ts"]);
assert_eq!( assert_eq!(
flags, flags,
DenoFlags { DenoFlags {
@ -423,12 +467,19 @@ mod tests {
#[test] #[test]
fn test_flags_from_vec_3() { fn test_flags_from_vec_3() {
let (flags, subcommand, argv) = let (flags, subcommand, argv) = flags_from_vec(svec![
flags_from_vec(svec!["deno", "-r", "--allow-write", "script.ts"]); "deno",
"run",
"-r",
"-D",
"--allow-write",
"script.ts"
]);
assert_eq!( assert_eq!(
flags, flags,
DenoFlags { DenoFlags {
reload: true, reload: true,
log_debug: true,
allow_write: true, allow_write: true,
..DenoFlags::default() ..DenoFlags::default()
} }
@ -440,7 +491,7 @@ mod tests {
#[test] #[test]
fn test_flags_from_vec_4() { fn test_flags_from_vec_4() {
let (flags, subcommand, argv) = let (flags, subcommand, argv) =
flags_from_vec(svec!["deno", "-Dr", "--allow-write", "script.ts"]); flags_from_vec(svec!["deno", "-Dr", "run", "--allow-write", "script.ts"]);
assert_eq!( assert_eq!(
flags, flags,
DenoFlags { DenoFlags {
@ -457,7 +508,7 @@ mod tests {
#[test] #[test]
fn test_flags_from_vec_5() { fn test_flags_from_vec_5() {
let (flags, subcommand, argv) = let (flags, subcommand, argv) =
flags_from_vec(svec!["deno", "--v8-options"]); flags_from_vec(svec!["deno", "--v8-options", "run", "script.ts"]);
assert_eq!( assert_eq!(
flags, flags,
DenoFlags { DenoFlags {
@ -465,11 +516,15 @@ mod tests {
..DenoFlags::default() ..DenoFlags::default()
} }
); );
assert_eq!(subcommand, DenoSubcommand::Repl); assert_eq!(subcommand, DenoSubcommand::Run);
assert_eq!(argv, svec!["deno"]); assert_eq!(argv, svec!["deno", "script.ts"]);
let (flags, subcommand, argv) = let (flags, subcommand, argv) = flags_from_vec(svec![
flags_from_vec(svec!["deno", "--v8-flags=--expose-gc,--gc-stats=1"]); "deno",
"--v8-flags=--expose-gc,--gc-stats=1",
"run",
"script.ts"
]);
assert_eq!( assert_eq!(
flags, flags,
DenoFlags { DenoFlags {
@ -477,14 +532,20 @@ mod tests {
..DenoFlags::default() ..DenoFlags::default()
} }
); );
assert_eq!(subcommand, DenoSubcommand::Repl); assert_eq!(subcommand, DenoSubcommand::Run);
assert_eq!(argv, svec!["deno"]); assert_eq!(argv, svec!["deno", "script.ts"]);
} }
#[test] #[test]
fn test_flags_from_vec_6() { fn test_flags_from_vec_6() {
let (flags, subcommand, argv) = let (flags, subcommand, argv) = flags_from_vec(svec![
flags_from_vec(svec!["deno", "--allow-net", "gist.ts", "--title", "X"]); "deno",
"run",
"--allow-net",
"gist.ts",
"--title",
"X"
]);
assert_eq!( assert_eq!(
flags, flags,
DenoFlags { DenoFlags {
@ -499,7 +560,7 @@ mod tests {
#[test] #[test]
fn test_flags_from_vec_7() { fn test_flags_from_vec_7() {
let (flags, subcommand, argv) = let (flags, subcommand, argv) =
flags_from_vec(svec!["deno", "--allow-all", "gist.ts"]); flags_from_vec(svec!["deno", "run", "--allow-all", "gist.ts"]);
assert_eq!( assert_eq!(
flags, flags,
DenoFlags { DenoFlags {
@ -519,7 +580,7 @@ mod tests {
#[test] #[test]
fn test_flags_from_vec_8() { fn test_flags_from_vec_8() {
let (flags, subcommand, argv) = let (flags, subcommand, argv) =
flags_from_vec(svec!["deno", "--allow-read", "gist.ts"]); flags_from_vec(svec!["deno", "run", "--allow-read", "gist.ts"]);
assert_eq!( assert_eq!(
flags, flags,
DenoFlags { DenoFlags {
@ -533,8 +594,12 @@ mod tests {
#[test] #[test]
fn test_flags_from_vec_9() { fn test_flags_from_vec_9() {
let (flags, subcommand, argv) = let (flags, subcommand, argv) = flags_from_vec(svec![
flags_from_vec(svec!["deno", "--allow-high-precision", "script.ts"]); "deno",
"run",
"--allow-high-precision",
"script.ts"
]);
assert_eq!( assert_eq!(
flags, flags,
DenoFlags { DenoFlags {
@ -553,6 +618,7 @@ mod tests {
// script args as Deno.args // script args as Deno.args
let (flags, subcommand, argv) = flags_from_vec(svec![ let (flags, subcommand, argv) = flags_from_vec(svec![
"deno", "deno",
"run",
"--allow-write", "--allow-write",
"script.ts", "script.ts",
"-D", "-D",
@ -616,6 +682,60 @@ mod tests {
#[test] #[test]
fn test_flags_from_vec_15() { fn test_flags_from_vec_15() {
let (flags, subcommand, argv) =
flags_from_vec(svec!["deno", "run", "-c", "tsconfig.json", "script.ts"]);
assert_eq!(
flags,
DenoFlags {
config_path: Some("tsconfig.json".to_owned()),
..DenoFlags::default()
}
);
assert_eq!(subcommand, DenoSubcommand::Run);
assert_eq!(argv, svec!["deno", "script.ts"]);
}
#[test]
fn test_flags_from_vec_16() {
let (flags, subcommand, argv) =
flags_from_vec(svec!["deno", "eval", "'console.log(\"hello\")'"]);
assert_eq!(
flags,
DenoFlags {
allow_net: true,
allow_env: true,
allow_run: true,
allow_read: true,
allow_write: true,
allow_high_precision: true,
..DenoFlags::default()
}
);
assert_eq!(subcommand, DenoSubcommand::Eval);
assert_eq!(argv, svec!["deno", "'console.log(\"hello\")'"]);
}
#[test]
fn test_flags_from_vec_17() {
let (flags, subcommand, argv) = flags_from_vec(svec!["deno"]);
assert_eq!(
flags,
DenoFlags {
allow_net: true,
allow_env: true,
allow_run: true,
allow_read: true,
allow_write: true,
allow_high_precision: true,
..DenoFlags::default()
}
);
assert_eq!(subcommand, DenoSubcommand::Repl);
assert_eq!(argv, svec!["deno"]);
}
#[test]
fn test_flags_from_vec_18() {
let (flags, subcommand, argv) = flags_from_vec(svec![ let (flags, subcommand, argv) = flags_from_vec(svec![
"deno", "deno",
"xeval", "xeval",
@ -632,17 +752,4 @@ mod tests {
assert_eq!(subcommand, DenoSubcommand::Xeval); assert_eq!(subcommand, DenoSubcommand::Xeval);
assert_eq!(argv, svec!["deno", "console.log(val)"]); assert_eq!(argv, svec!["deno", "console.log(val)"]);
} }
#[test]
fn test_set_flags_11() {
let (flags, _, _) =
flags_from_vec(svec!["deno", "-c", "tsconfig.json", "script.ts"]);
assert_eq!(
flags,
DenoFlags {
config_path: Some("tsconfig.json".to_owned()),
..DenoFlags::default()
}
)
}
} }

View file

@ -300,6 +300,7 @@ fn main() {
DenoSubcommand::Repl => run_repl(flags, argv), DenoSubcommand::Repl => run_repl(flags, argv),
DenoSubcommand::Run => run_script(flags, argv), DenoSubcommand::Run => run_script(flags, argv),
DenoSubcommand::Types => types_command(), DenoSubcommand::Types => types_command(),
DenoSubcommand::Version => run_script(flags, argv),
DenoSubcommand::Xeval => xeval_command(flags, argv), DenoSubcommand::Xeval => xeval_command(flags, argv),
} }
} }

View file

@ -1,2 +1,2 @@
args: --reload tests/001_hello.js args: run --reload tests/001_hello.js
output: tests/001_hello.js.out output: tests/001_hello.js.out

View file

@ -1,2 +1,2 @@
args: --reload tests/002_hello.ts args: run --reload tests/002_hello.ts
output: tests/002_hello.ts.out output: tests/002_hello.ts.out

View file

@ -1,2 +1,2 @@
args: --reload tests/003_relative_import.ts args: run --reload tests/003_relative_import.ts
output: tests/003_relative_import.ts.out output: tests/003_relative_import.ts.out

View file

@ -1,2 +1,2 @@
args: --reload tests/004_set_timeout.ts args: run --reload tests/004_set_timeout.ts
output: tests/004_set_timeout.ts.out output: tests/004_set_timeout.ts.out

View file

@ -1,2 +1,2 @@
args: --reload tests/005_more_imports.ts args: run --reload tests/005_more_imports.ts
output: tests/005_more_imports.ts.out output: tests/005_more_imports.ts.out

View file

@ -1,2 +1,2 @@
args: --reload tests/006_url_imports.ts args: run --reload tests/006_url_imports.ts
output: tests/006_url_imports.ts.out output: tests/006_url_imports.ts.out

View file

@ -1,2 +1,2 @@
args: --reload tests/012_async.ts args: run --reload tests/012_async.ts
output: tests/012_async.ts.out output: tests/012_async.ts.out

View file

@ -1,2 +1,2 @@
args: --allow-read --reload tests/016_double_await.ts args: run --allow-read --reload tests/016_double_await.ts
output: tests/016_double_await.ts.out output: tests/016_double_await.ts.out

View file

@ -1,2 +1,2 @@
args: --reload tests/017_import_redirect.ts args: run --reload tests/017_import_redirect.ts
output: tests/017_import_redirect.ts.out output: tests/017_import_redirect.ts.out

View file

@ -1,2 +1,2 @@
args: --reload tests/018_async_catch.ts args: run --reload tests/018_async_catch.ts
output: tests/018_async_catch.ts.out output: tests/018_async_catch.ts.out

View file

@ -1,2 +1,2 @@
args: --reload tests/019_media_types.ts args: run --reload tests/019_media_types.ts
output: tests/019_media_types.ts.out output: tests/019_media_types.ts.out

View file

@ -1,2 +1,2 @@
args: --reload tests/020_json_modules.ts args: run --reload tests/020_json_modules.ts
output: tests/020_json_modules.ts.out output: tests/020_json_modules.ts.out

View file

@ -1,2 +1,2 @@
args: --reload tests/021_mjs_modules.ts args: run --reload tests/021_mjs_modules.ts
output: tests/021_mjs_modules.ts.out output: tests/021_mjs_modules.ts.out

View file

@ -1,2 +1,2 @@
args: --reload tests/023_no_ext_with_headers args: run --reload tests/023_no_ext_with_headers
output: tests/023_no_ext_with_headers.out output: tests/023_no_ext_with_headers.out

View file

@ -1,2 +1,2 @@
args: --reload tests/024_import_no_ext_with_headers.ts args: run --reload tests/024_import_no_ext_with_headers.ts
output: tests/024_import_no_ext_with_headers.ts.out output: tests/024_import_no_ext_with_headers.ts.out

View file

@ -1,2 +1,2 @@
args: --allow-high-precision --reload tests/025_high_precision.ts args: run --allow-high-precision --reload tests/025_high_precision.ts
output: tests/025_high_precision.ts.out output: tests/025_high_precision.ts.out

View file

@ -1,2 +1,2 @@
args: --reload tests/025_reload_js_type_error.js args: run --reload tests/025_reload_js_type_error.js
output: tests/025_reload_js_type_error.js.out output: tests/025_reload_js_type_error.js.out

View file

@ -1,2 +1,2 @@
args: --reload tests/026_redirect_javascript.js args: run --reload tests/026_redirect_javascript.js
output: tests/026_redirect_javascript.js.out output: tests/026_redirect_javascript.js.out

View file

@ -1,2 +1,2 @@
args: --reload tests/026_workers.ts args: run --reload tests/026_workers.ts
output: tests/026_workers.ts.out output: tests/026_workers.ts.out

View file

@ -1,2 +1,2 @@
args: --reload tests/027_redirect_typescript.ts args: run --reload tests/027_redirect_typescript.ts
output: tests/027_redirect_typescript.ts.out output: tests/027_redirect_typescript.ts.out

View file

@ -1,2 +1,2 @@
args: --reload tests/028_args.ts --arg1 val1 --arg2=val2 -- arg3 arg4 args: run --reload tests/028_args.ts --arg1 val1 --arg2=val2 -- arg3 arg4
output: tests/028_args.ts.out output: tests/028_args.ts.out

View file

@ -1,4 +1,4 @@
exit_code: 1 exit_code: 1
args: --reload tests/async_error.ts args: run --reload tests/async_error.ts
check_stderr: true check_stderr: true
output: tests/async_error.ts.out output: tests/async_error.ts.out

View file

@ -1,2 +1,2 @@
args: tests/circular1.js --reload args: run --reload tests/circular1.js
output: tests/circular1.js.out output: tests/circular1.js.out

View file

@ -1,4 +1,4 @@
args: --reload --config tests/config.tsconfig.json tests/config.ts args: run --reload --config tests/config.tsconfig.json tests/config.ts
check_stderr: true check_stderr: true
exit_code: 1 exit_code: 1
output: tests/config.ts.out output: tests/config.ts.out

View file

@ -1,4 +1,4 @@
args: --reload tests/error_001.ts args: run --reload tests/error_001.ts
check_stderr: true check_stderr: true
exit_code: 1 exit_code: 1
output: tests/error_001.ts.out output: tests/error_001.ts.out

View file

@ -1,4 +1,4 @@
args: --reload tests/error_002.ts args: run --reload tests/error_002.ts
check_stderr: true check_stderr: true
exit_code: 1 exit_code: 1
output: tests/error_002.ts.out output: tests/error_002.ts.out

View file

@ -1,3 +1,3 @@
args: --reload tests/error_003_typescript.ts args: run --reload tests/error_003_typescript.ts
exit_code: 1 exit_code: 1
output: tests/error_003_typescript.ts.out output: tests/error_003_typescript.ts.out

View file

@ -1,4 +1,4 @@
args: tests/error_004_missing_module.ts --reload args: run --reload tests/error_004_missing_module.ts
check_stderr: true check_stderr: true
exit_code: 1 exit_code: 1
output: tests/error_004_missing_module.ts.out output: tests/error_004_missing_module.ts.out

View file

@ -1,4 +1,4 @@
args: tests/error_005_missing_dynamic_import.ts --reload args: run --reload tests/error_005_missing_dynamic_import.ts
check_stderr: true check_stderr: true
exit_code: 1 exit_code: 1
output: tests/error_005_missing_dynamic_import.ts.out output: tests/error_005_missing_dynamic_import.ts.out

View file

@ -1,4 +1,4 @@
args: tests/error_006_import_ext_failure.ts --reload args: run --reload tests/error_006_import_ext_failure.ts
check_stderr: true check_stderr: true
exit_code: 1 exit_code: 1
output: tests/error_006_import_ext_failure.ts.out output: tests/error_006_import_ext_failure.ts.out

View file

@ -1,4 +1,4 @@
args: --reload tests/error_007_any.ts args: run --reload tests/error_007_any.ts
check_stderr: true check_stderr: true
exit_code: 1 exit_code: 1
output: tests/error_007_any.ts.out output: tests/error_007_any.ts.out

View file

@ -1,4 +1,4 @@
args: --reload tests/error_008_checkjs.js args: run --reload tests/error_008_checkjs.js
check_stderr: true check_stderr: true
exit_code: 1 exit_code: 1
output: tests/error_008_checkjs.js.out output: tests/error_008_checkjs.js.out

View file

@ -1,4 +1,4 @@
args: --reload tests/error_syntax.js args: run --reload tests/error_syntax.js
check_stderr: true check_stderr: true
exit_code: 1 exit_code: 1
output: tests/error_syntax.js.out output: tests/error_syntax.js.out

View file

@ -1,3 +1,3 @@
exit_code: 42 exit_code: 42
args: --reload tests/exit_error42.ts args: run --reload tests/exit_error42.ts
output: tests/exit_error42.ts.out output: tests/exit_error42.ts.out

View file

@ -1,2 +1,2 @@
args: --reload tests/https_import.ts args: run --reload tests/https_import.ts
output: tests/https_import.ts.out output: tests/https_import.ts.out

View file

@ -1,2 +1,2 @@
args: --reload tests/if_main.ts args: run --reload tests/if_main.ts
output: tests/if_main.ts.out output: tests/if_main.ts.out

View file

@ -1,2 +1,2 @@
args: --reload tests/import_meta.ts args: run --reload tests/import_meta.ts
output: tests/import_meta.ts.out output: tests/import_meta.ts.out

View file

@ -1,3 +1,3 @@
args: --reload tests/unbuffered_stderr.ts args: run --reload tests/unbuffered_stderr.ts
check_stderr: true check_stderr: true
output: tests/unbuffered_stderr.ts.out output: tests/unbuffered_stderr.ts.out

View file

@ -1,2 +1,2 @@
args: --reload tests/unbuffered_stdout.ts args: run --reload tests/unbuffered_stdout.ts
output: tests/unbuffered_stdout.ts.out output: tests/unbuffered_stdout.ts.out

View file

@ -1,2 +1,2 @@
args: --v8-flags=--expose-gc tests/v8_flags.js args: run --v8-flags=--expose-gc tests/v8_flags.js
output: tests/v8_flags.js.out output: tests/v8_flags.js.out

View file

@ -1,2 +1,2 @@
args: tests/wasm.ts args: run tests/wasm.ts
output: tests/wasm.ts.out output: tests/wasm.ts.out

View file

@ -143,7 +143,7 @@ def run_strace_benchmarks(deno_exe, new_data):
thread_count = {} thread_count = {}
syscall_count = {} syscall_count = {}
for (name, args) in exec_time_benchmarks: for (name, args) in exec_time_benchmarks:
s = get_strace_summary([deno_exe] + args) s = get_strace_summary([deno_exe, "run"] + args)
thread_count[name] = s["clone"]["calls"] + 1 thread_count[name] = s["clone"]["calls"] + 1
syscall_count[name] = s["total"]["calls"] syscall_count[name] = s["total"]["calls"]
new_data["thread_count"] = thread_count new_data["thread_count"] = thread_count
@ -162,7 +162,7 @@ def find_max_mem_in_bytes(time_v_output):
def run_max_mem_benchmark(deno_exe): def run_max_mem_benchmark(deno_exe):
results = {} results = {}
for (name, args) in exec_time_benchmarks: for (name, args) in exec_time_benchmarks:
cmd = ["/usr/bin/time", "-v", deno_exe] + args cmd = ["/usr/bin/time", "-v", deno_exe, "run"] + args
try: try:
out = subprocess.check_output(cmd, stderr=subprocess.STDOUT) out = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
@ -179,7 +179,8 @@ def run_exec_time(deno_exe, build_dir):
hyperfine, "--ignore-failure", "--export-json", benchmark_file, hyperfine, "--ignore-failure", "--export-json", benchmark_file,
"--warmup", "3" "--warmup", "3"
] + [ ] + [
deno_exe + " " + " ".join(args) for [_, args] in exec_time_benchmarks deno_exe + " run " + " ".join(args)
for [_, args] in exec_time_benchmarks
]) ])
hyperfine_results = read_json(benchmark_file) hyperfine_results = read_json(benchmark_file)
results = {} results = {}

View file

@ -35,7 +35,7 @@ def deno_dir_test(deno_exe, deno_dir):
def run_deno(deno_exe, deno_dir=None): def run_deno(deno_exe, deno_dir=None):
cmd = [deno_exe, "tests/002_hello.ts"] cmd = [deno_exe, "run", "tests/002_hello.ts"]
deno_dir_env = {"DENO_DIR": deno_dir} if deno_dir is not None else None deno_dir_env = {"DENO_DIR": deno_dir} if deno_dir is not None else None
run(cmd, quiet=True, env=deno_dir_env) run(cmd, quiet=True, env=deno_dir_env)

View file

@ -11,14 +11,14 @@ DURATION = "10s"
def deno_http_benchmark(deno_exe): def deno_http_benchmark(deno_exe):
deno_cmd = [deno_exe, "--allow-net", "tests/http_bench.ts", ADDR] deno_cmd = [deno_exe, "run", "--allow-net", "tests/http_bench.ts", ADDR]
print "http_benchmark testing DENO." print "http_benchmark testing DENO."
return run(deno_cmd) return run(deno_cmd)
def deno_net_http_benchmark(deno_exe): def deno_net_http_benchmark(deno_exe):
deno_cmd = [ deno_cmd = [
deno_exe, "--allow-net", deno_exe, "run", "--allow-net",
"js/deps/https/deno.land/std/http/http_bench.ts", ADDR "js/deps/https/deno.land/std/http/http_bench.ts", ADDR
] ]
print "http_benchmark testing DENO using net/http." print "http_benchmark testing DENO using net/http."

View file

@ -12,7 +12,7 @@ IS_TTY_TEST_TS = "tests/is_tty.ts"
def is_tty_test(deno_exe): def is_tty_test(deno_exe):
cmd = [deno_exe, IS_TTY_TEST_TS] cmd = [deno_exe, "run", IS_TTY_TEST_TS]
code, stdout, _ = tty_capture(cmd, b'') code, stdout, _ = tty_capture(cmd, b'')
assert code == 0 assert code == 0
assert str(stdin.isatty()).lower() in stdout assert str(stdin.isatty()).lower() in stdout

View file

@ -71,7 +71,8 @@ class Prompt(object):
def run(self, flags, args, bytes_input): def run(self, flags, args, bytes_input):
"Returns (return_code, stdout, stderr)." "Returns (return_code, stdout, stderr)."
cmd = [self.deno_exe] + flags + [PERMISSIONS_PROMPT_TEST_TS] + args cmd = [self.deno_exe, "run"] + flags + [PERMISSIONS_PROMPT_TEST_TS
] + args
return tty_capture(cmd, bytes_input) return tty_capture(cmd, bytes_input)
def warm_up(self): def warm_up(self):

View file

@ -19,7 +19,7 @@ class Repl(object):
def input(self, *lines, **kwargs): def input(self, *lines, **kwargs):
exit_ = kwargs.pop("exit", True) exit_ = kwargs.pop("exit", True)
sleep_ = kwargs.pop("sleep", 0) sleep_ = kwargs.pop("sleep", 0)
p = Popen([self.deno_exe, "-A"], stdout=PIPE, stderr=PIPE, stdin=PIPE) p = Popen([self.deno_exe], stdout=PIPE, stderr=PIPE, stdin=PIPE)
try: try:
# Note: The repl takes a >100ms until it's ready. # Note: The repl takes a >100ms until it's ready.
time.sleep(sleep_) time.sleep(sleep_)

View file

@ -30,16 +30,16 @@ def test_no_color(deno_exe):
sys.stdout.write("no_color test...") sys.stdout.write("no_color test...")
sys.stdout.flush() sys.stdout.flush()
t = os.path.join(tests_path, "no_color.js") t = os.path.join(tests_path, "no_color.js")
output = run_output([deno_exe, t], merge_env={"NO_COLOR": "1"}) output = run_output([deno_exe, "run", t], merge_env={"NO_COLOR": "1"})
assert output.strip() == "noColor true" assert output.strip() == "noColor true"
t = os.path.join(tests_path, "no_color.js") t = os.path.join(tests_path, "no_color.js")
output = run_output([deno_exe, t]) output = run_output([deno_exe, "run", t])
assert output.strip() == "noColor false" assert output.strip() == "noColor false"
print green_ok() print green_ok()
def exec_path_test(deno_exe): def exec_path_test(deno_exe):
cmd = [deno_exe, "tests/exec_path.ts"] cmd = [deno_exe, "run", "tests/exec_path.ts"]
output = run_output(cmd) output = run_output(cmd)
assert deno_exe in output.strip() assert deno_exe in output.strip()

View file

@ -19,7 +19,8 @@ ADDR = "127.0.0.1:4544"
def cat(deno_exe, megs): def cat(deno_exe, megs):
size = megs * MB size = megs * MB
start = time.time() start = time.time()
cmd = deno_exe + " --allow-read tests/cat.ts /dev/zero | head -c %s " % size cmd = deno_exe + " run --allow-read "
cmd += "tests/cat.ts /dev/zero | head -c %s " % size
print cmd print cmd
subprocess.check_output(cmd, shell=True) subprocess.check_output(cmd, shell=True)
end = time.time() end = time.time()
@ -30,7 +31,7 @@ def tcp(deno_exe, megs):
size = megs * MB size = megs * MB
# Run deno echo server in the background. # Run deno echo server in the background.
echo_server = subprocess.Popen( echo_server = subprocess.Popen(
[deno_exe, "--allow-net", "tests/echo_server.ts", ADDR]) [deno_exe, "run", "--allow-net", "tests/echo_server.ts", ADDR])
time.sleep(5) # wait for deno to wake up. TODO racy. time.sleep(5) # wait for deno to wake up. TODO racy.
try: try:

View file

@ -34,7 +34,7 @@ def run_unit_test2(cmd):
def run_unit_test(deno_exe, permStr, flags=None): def run_unit_test(deno_exe, permStr, flags=None):
if flags is None: if flags is None:
flags = [] flags = []
cmd = [deno_exe] + flags + ["js/unit_tests.ts", permStr] cmd = [deno_exe, "run"] + flags + ["js/unit_tests.ts", permStr]
run_unit_test2(cmd) run_unit_test2(cmd)

View file

@ -104,7 +104,7 @@ href="https://github.com/denoland/deno_install/blob/master/install.ps1">https://
<h2 id="example">Example <a href="#example">#</a></h2> <h2 id="example">Example <a href="#example">#</a></h2>
<p>Try running a simple program:</p> <p>Try running a simple program:</p>
<pre>deno https://deno.land/welcome.ts</pre> <pre>deno run https://deno.land/welcome.ts</pre>
<p>Or a more complex one:</p> <p>Or a more complex one:</p>

View file

@ -543,31 +543,24 @@ USAGE:
deno [FLAGS] [OPTIONS] [SUBCOMMAND] deno [FLAGS] [OPTIONS] [SUBCOMMAND]
FLAGS: FLAGS:
-A, --allow-all Allow all permissions -h, --help Prints help information
--allow-env Allow environment access -D, --log-debug Log debug output
--allow-high-precision Allow high precision time measurement -r, --reload Reload source code cache (recompile TypeScript)
--allow-net Allow network access --v8-options Print V8 command line options
--allow-read Allow file system read access
--allow-run Allow running subprocesses
--allow-write Allow file system write access
-h, --help Prints help information
-D, --log-debug Log debug output
--no-prompt Do not use prompts
-r, --reload Reload source code cache (recompile TypeScript)
--v8-options Print V8 command line options
OPTIONS: OPTIONS:
-c, --config <FILE> Load compiler configuration file
--v8-flags=<v8-flags> Set V8 command line options --v8-flags=<v8-flags> Set V8 command line options
SUBCOMMANDS: SUBCOMMANDS:
<script> Script to run eval Eval script
eval Eval script fetch Fetch the dependencies
fetch Fetch the dependencies fmt Format files
fmt Format files help Prints this message or the help of the given subcommand(s)
help Prints this message or the help of the given subcommand(s) info Show source file related info
info Show source file related info run Run a program given a filename or url to the source code
types Print runtime TypeScript declarations types Print runtime TypeScript declarations
version Print the version version Print the version
ENVIRONMENT VARIABLES: ENVIRONMENT VARIABLES:
DENO_DIR Set deno's base directory DENO_DIR Set deno's base directory