1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -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")
.bin_name("deno")
.global_settings(&[AppSettings::ColorNever])
.settings(&[
AppSettings::AllowExternalSubcommands,
AppSettings::DisableVersion,
]).after_help(ENV_VARIABLES_HELP)
.settings(&[AppSettings::DisableVersion])
.after_help(ENV_VARIABLES_HELP)
.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")
.short("D")
.long("log-debug")
.help("Log debug output"),
.help("Log debug output")
.global(true),
).arg(
Arg::with_name("reload")
.short("r")
.long("reload")
.help("Reload source code cache (recompile TypeScript)"),
.help("Reload source code cache (recompile TypeScript)")
.global(true),
).arg(
Arg::with_name("config")
.short("c")
.long("config")
.value_name("FILE")
.help("Load compiler configuration file")
.takes_value(true),
.takes_value(true)
.global(true),
).arg(
Arg::with_name("v8-options")
.long("v8-options")
.help("Print V8 command line options"),
.help("Print V8 command line options")
.global(true),
).arg(
Arg::with_name("v8-flags")
.long("v8-flags")
.takes_value(true)
.use_delimiter(true)
.require_equals(true)
.help("Set V8 command line options"),
.help("Set V8 command line options")
.global(true),
).subcommand(
SubCommand::with_name("version")
.setting(AppSettings::DisableVersion)
@ -195,6 +161,68 @@ Prettier dependencies on first run.
.multiple(true)
.required(true),
),
).subcommand(
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)
@ -226,14 +254,8 @@ Otherwise '$' will be used as default variable name.
.help("Set delimiter, defaults to newline")
.takes_value(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.
/// This method should not make any side effects.
#[cfg_attr(feature = "cargo-clippy", allow(stutter))]
@ -250,39 +272,6 @@ pub fn parse_flags(matches: ArgMatches) -> DenoFlags {
flags.reload = true;
}
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") {
let v8_flags = svec!["deno", "--help"];
flags.v8_flags = Some(v8_flags);
@ -298,6 +287,40 @@ pub fn parse_flags(matches: ArgMatches) -> DenoFlags {
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
}
@ -314,6 +337,7 @@ pub enum DenoSubcommand {
Repl,
Run,
Types,
Version,
Xeval,
}
@ -327,6 +351,12 @@ pub fn flags_from_vec(
let subcommand = match matches.subcommand() {
("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();
argv.extend(vec![code.to_string()]);
DenoSubcommand::Eval
@ -356,17 +386,8 @@ pub fn flags_from_vec(
DenoSubcommand::Info
}
("types", Some(_)) => DenoSubcommand::Types,
("xeval", Some(eval_match)) => {
let code: &str = eval_match.value_of("code").unwrap();
flags.xeval_replvar =
Some(eval_match.value_of("replvar").unwrap_or("$").to_owned());
// Currently clap never escapes string,
// So -d "\n" won't expand to newline.
// Instead, do -d $'\n'
flags.xeval_delim = eval_match.value_of("delim").map(String::from);
argv.extend(vec![code.to_string()]);
DenoSubcommand::Xeval
}
("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
@ -381,7 +402,30 @@ pub fn flags_from_vec(
}
DenoSubcommand::Run
}
_ => DenoSubcommand::Repl,
_ => unreachable!(),
}
}
("xeval", Some(eval_match)) => {
let code: &str = eval_match.value_of("code").unwrap();
flags.xeval_replvar =
Some(eval_match.value_of("replvar").unwrap_or("$").to_owned());
// Currently clap never escapes string,
// So -d "\n" won't expand to newline.
// Instead, do -d $'\n'
flags.xeval_delim = eval_match.value_of("delim").map(String::from);
argv.extend(vec![code.to_string()]);
DenoSubcommand::Xeval
}
("version", Some(_)) => DenoSubcommand::Version,
_ => {
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;
DenoSubcommand::Repl
}
};
(flags, subcommand, argv)
@ -401,14 +445,14 @@ mod tests {
..DenoFlags::default()
}
);
assert_eq!(subcommand, DenoSubcommand::Run);
assert_eq!(argv, svec!["deno", "version"]);
assert_eq!(subcommand, DenoSubcommand::Version);
assert_eq!(argv, svec!["deno"]);
}
#[test]
fn test_flags_from_vec_2() {
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!(
flags,
DenoFlags {
@ -423,12 +467,19 @@ mod tests {
#[test]
fn test_flags_from_vec_3() {
let (flags, subcommand, argv) =
flags_from_vec(svec!["deno", "-r", "--allow-write", "script.ts"]);
let (flags, subcommand, argv) = flags_from_vec(svec![
"deno",
"run",
"-r",
"-D",
"--allow-write",
"script.ts"
]);
assert_eq!(
flags,
DenoFlags {
reload: true,
log_debug: true,
allow_write: true,
..DenoFlags::default()
}
@ -440,7 +491,7 @@ mod tests {
#[test]
fn test_flags_from_vec_4() {
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!(
flags,
DenoFlags {
@ -457,7 +508,7 @@ mod tests {
#[test]
fn test_flags_from_vec_5() {
let (flags, subcommand, argv) =
flags_from_vec(svec!["deno", "--v8-options"]);
flags_from_vec(svec!["deno", "--v8-options", "run", "script.ts"]);
assert_eq!(
flags,
DenoFlags {
@ -465,11 +516,15 @@ mod tests {
..DenoFlags::default()
}
);
assert_eq!(subcommand, DenoSubcommand::Repl);
assert_eq!(argv, svec!["deno"]);
assert_eq!(subcommand, DenoSubcommand::Run);
assert_eq!(argv, svec!["deno", "script.ts"]);
let (flags, subcommand, argv) =
flags_from_vec(svec!["deno", "--v8-flags=--expose-gc,--gc-stats=1"]);
let (flags, subcommand, argv) = flags_from_vec(svec![
"deno",
"--v8-flags=--expose-gc,--gc-stats=1",
"run",
"script.ts"
]);
assert_eq!(
flags,
DenoFlags {
@ -477,14 +532,20 @@ mod tests {
..DenoFlags::default()
}
);
assert_eq!(subcommand, DenoSubcommand::Repl);
assert_eq!(argv, svec!["deno"]);
assert_eq!(subcommand, DenoSubcommand::Run);
assert_eq!(argv, svec!["deno", "script.ts"]);
}
#[test]
fn test_flags_from_vec_6() {
let (flags, subcommand, argv) =
flags_from_vec(svec!["deno", "--allow-net", "gist.ts", "--title", "X"]);
let (flags, subcommand, argv) = flags_from_vec(svec![
"deno",
"run",
"--allow-net",
"gist.ts",
"--title",
"X"
]);
assert_eq!(
flags,
DenoFlags {
@ -499,7 +560,7 @@ mod tests {
#[test]
fn test_flags_from_vec_7() {
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!(
flags,
DenoFlags {
@ -519,7 +580,7 @@ mod tests {
#[test]
fn test_flags_from_vec_8() {
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!(
flags,
DenoFlags {
@ -533,8 +594,12 @@ mod tests {
#[test]
fn test_flags_from_vec_9() {
let (flags, subcommand, argv) =
flags_from_vec(svec!["deno", "--allow-high-precision", "script.ts"]);
let (flags, subcommand, argv) = flags_from_vec(svec![
"deno",
"run",
"--allow-high-precision",
"script.ts"
]);
assert_eq!(
flags,
DenoFlags {
@ -553,6 +618,7 @@ mod tests {
// script args as Deno.args
let (flags, subcommand, argv) = flags_from_vec(svec![
"deno",
"run",
"--allow-write",
"script.ts",
"-D",
@ -616,6 +682,60 @@ mod tests {
#[test]
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![
"deno",
"xeval",
@ -632,17 +752,4 @@ mod tests {
assert_eq!(subcommand, DenoSubcommand::Xeval);
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::Run => run_script(flags, argv),
DenoSubcommand::Types => types_command(),
DenoSubcommand::Version => run_script(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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

View file

@ -1,4 +1,4 @@
exit_code: 1
args: --reload tests/async_error.ts
args: run --reload tests/async_error.ts
check_stderr: true
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

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
exit_code: 1
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
exit_code: 1
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
exit_code: 1
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
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
exit_code: 1
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
exit_code: 1
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
exit_code: 1
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
exit_code: 1
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
exit_code: 1
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
exit_code: 1
output: tests/error_syntax.js.out

View file

@ -1,3 +1,3 @@
exit_code: 42
args: --reload tests/exit_error42.ts
args: run --reload tests/exit_error42.ts
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

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

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

View file

@ -1,3 +1,3 @@
args: --reload tests/unbuffered_stderr.ts
args: run --reload tests/unbuffered_stderr.ts
check_stderr: true
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

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

View file

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

View file

@ -143,7 +143,7 @@ def run_strace_benchmarks(deno_exe, new_data):
thread_count = {}
syscall_count = {}
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
syscall_count[name] = s["total"]["calls"]
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):
results = {}
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:
out = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError:
@ -179,7 +179,8 @@ def run_exec_time(deno_exe, build_dir):
hyperfine, "--ignore-failure", "--export-json", benchmark_file,
"--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)
results = {}

View file

@ -35,7 +35,7 @@ def deno_dir_test(deno_exe, deno_dir):
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
run(cmd, quiet=True, env=deno_dir_env)

View file

@ -11,14 +11,14 @@ DURATION = "10s"
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."
return run(deno_cmd)
def deno_net_http_benchmark(deno_exe):
deno_cmd = [
deno_exe, "--allow-net",
deno_exe, "run", "--allow-net",
"js/deps/https/deno.land/std/http/http_bench.ts", ADDR
]
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):
cmd = [deno_exe, IS_TTY_TEST_TS]
cmd = [deno_exe, "run", IS_TTY_TEST_TS]
code, stdout, _ = tty_capture(cmd, b'')
assert code == 0
assert str(stdin.isatty()).lower() in stdout

View file

@ -71,7 +71,8 @@ class Prompt(object):
def run(self, flags, args, bytes_input):
"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)
def warm_up(self):

View file

@ -19,7 +19,7 @@ class Repl(object):
def input(self, *lines, **kwargs):
exit_ = kwargs.pop("exit", True)
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:
# Note: The repl takes a >100ms until it's ready.
time.sleep(sleep_)

View file

@ -30,16 +30,16 @@ def test_no_color(deno_exe):
sys.stdout.write("no_color test...")
sys.stdout.flush()
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"
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"
print green_ok()
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)
assert deno_exe in output.strip()

View file

@ -19,7 +19,8 @@ ADDR = "127.0.0.1:4544"
def cat(deno_exe, megs):
size = megs * MB
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
subprocess.check_output(cmd, shell=True)
end = time.time()
@ -30,7 +31,7 @@ def tcp(deno_exe, megs):
size = megs * MB
# Run deno echo server in the background.
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.
try:

View file

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

View file

@ -543,29 +543,22 @@ USAGE:
deno [FLAGS] [OPTIONS] [SUBCOMMAND]
FLAGS:
-A, --allow-all Allow all permissions
--allow-env Allow environment access
--allow-high-precision Allow high precision time measurement
--allow-net Allow network access
--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:
-c, --config <FILE> Load compiler configuration file
--v8-flags=<v8-flags> Set V8 command line options
SUBCOMMANDS:
<script> Script to run
eval Eval script
fetch Fetch the dependencies
fmt Format files
help Prints this message or the help of the given subcommand(s)
info Show source file related info
run Run a program given a filename or url to the source code
types Print runtime TypeScript declarations
version Print the version