Skip to content

Commit

Permalink
add "deno run" subcommand (denoland#2215)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomieju authored and ry committed May 3, 2019
1 parent 3608117 commit f6a9d7d
Show file tree
Hide file tree
Showing 54 changed files with 314 additions and 210 deletions.
371 changes: 239 additions & 132 deletions cli/flags.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions cli/main.rs
Expand Up @@ -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),
}
}
2 changes: 1 addition & 1 deletion tests/001_hello.test
@@ -1,2 +1,2 @@
args: --reload tests/001_hello.js
args: run --reload tests/001_hello.js
output: tests/001_hello.js.out
2 changes: 1 addition & 1 deletion tests/002_hello.test
@@ -1,2 +1,2 @@
args: --reload tests/002_hello.ts
args: run --reload tests/002_hello.ts
output: tests/002_hello.ts.out
2 changes: 1 addition & 1 deletion tests/003_relative_import.test
@@ -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
2 changes: 1 addition & 1 deletion tests/004_set_timeout.test
@@ -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
2 changes: 1 addition & 1 deletion tests/005_more_imports.test
@@ -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
2 changes: 1 addition & 1 deletion tests/006_url_imports.test
@@ -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
2 changes: 1 addition & 1 deletion tests/012_async.test
@@ -1,2 +1,2 @@
args: --reload tests/012_async.ts
args: run --reload tests/012_async.ts
output: tests/012_async.ts.out
2 changes: 1 addition & 1 deletion tests/016_double_await.test
@@ -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
2 changes: 1 addition & 1 deletion tests/017_import_redirect.test
@@ -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
2 changes: 1 addition & 1 deletion tests/018_async_catch.test
@@ -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
2 changes: 1 addition & 1 deletion tests/019_media_types.test
@@ -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
2 changes: 1 addition & 1 deletion tests/020_json_modules.test
@@ -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
2 changes: 1 addition & 1 deletion tests/021_mjs_modules.test
@@ -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
2 changes: 1 addition & 1 deletion tests/023_no_ext_with_headers.test
@@ -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
2 changes: 1 addition & 1 deletion tests/024_import_no_ext_with_headers.test
@@ -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
2 changes: 1 addition & 1 deletion tests/025_high_precision.test
@@ -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
2 changes: 1 addition & 1 deletion tests/025_reload_js_type_error.test
@@ -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
2 changes: 1 addition & 1 deletion tests/026_redirect_javascript.js.test
@@ -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
2 changes: 1 addition & 1 deletion tests/026_workers.test
@@ -1,2 +1,2 @@
args: --reload tests/026_workers.ts
args: run --reload tests/026_workers.ts
output: tests/026_workers.ts.out
2 changes: 1 addition & 1 deletion tests/027_redirect_typescript.ts.test
@@ -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
2 changes: 1 addition & 1 deletion tests/028_args.test
@@ -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
2 changes: 1 addition & 1 deletion tests/async_error.test
@@ -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
2 changes: 1 addition & 1 deletion tests/circular1.test
@@ -1,2 +1,2 @@
args: tests/circular1.js --reload
args: run --reload tests/circular1.js
output: tests/circular1.js.out
2 changes: 1 addition & 1 deletion tests/config.test
@@ -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
2 changes: 1 addition & 1 deletion tests/error_001.test
@@ -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
2 changes: 1 addition & 1 deletion tests/error_002.test
@@ -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
2 changes: 1 addition & 1 deletion tests/error_003_typescript.test
@@ -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
2 changes: 1 addition & 1 deletion tests/error_004_missing_module.test
@@ -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
2 changes: 1 addition & 1 deletion tests/error_005_missing_dynamic_import.test
@@ -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
2 changes: 1 addition & 1 deletion tests/error_006_import_ext_failure.test
@@ -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
2 changes: 1 addition & 1 deletion tests/error_007_any.test
@@ -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
2 changes: 1 addition & 1 deletion tests/error_008_checkjs.test
@@ -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
2 changes: 1 addition & 1 deletion tests/error_syntax.test
@@ -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
2 changes: 1 addition & 1 deletion tests/exit_error42.test
@@ -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
2 changes: 1 addition & 1 deletion tests/https_import.test
@@ -1,2 +1,2 @@
args: --reload tests/https_import.ts
args: run --reload tests/https_import.ts
output: tests/https_import.ts.out
2 changes: 1 addition & 1 deletion tests/if_main.test
@@ -1,2 +1,2 @@
args: --reload tests/if_main.ts
args: run --reload tests/if_main.ts
output: tests/if_main.ts.out
2 changes: 1 addition & 1 deletion tests/import_meta.test
@@ -1,2 +1,2 @@
args: --reload tests/import_meta.ts
args: run --reload tests/import_meta.ts
output: tests/import_meta.ts.out
2 changes: 1 addition & 1 deletion tests/unbuffered_stderr.test
@@ -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
2 changes: 1 addition & 1 deletion tests/unbuffered_stdout.test
@@ -1,2 +1,2 @@
args: --reload tests/unbuffered_stdout.ts
args: run --reload tests/unbuffered_stdout.ts
output: tests/unbuffered_stdout.ts.out
2 changes: 1 addition & 1 deletion tests/v8_flags.test
@@ -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
4 changes: 2 additions & 2 deletions tests/wasm.test
@@ -1,2 +1,2 @@
args: tests/wasm.ts
output: tests/wasm.ts.out
args: run tests/wasm.ts
output: tests/wasm.ts.out
7 changes: 4 additions & 3 deletions tools/benchmark.py
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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 = {}
Expand Down
2 changes: 1 addition & 1 deletion tools/deno_dir_test.py
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions tools/http_benchmark.py
Expand Up @@ -11,14 +11,14 @@


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."
Expand Down
2 changes: 1 addition & 1 deletion tools/is_tty_test.py
Expand Up @@ -12,7 +12,7 @@


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
Expand Down
3 changes: 2 additions & 1 deletion tools/permission_prompt_test.py
Expand Up @@ -71,7 +71,8 @@ def __init__(self, deno_exe, test_types):

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):
Expand Down
2 changes: 1 addition & 1 deletion tools/repl_test.py
Expand Up @@ -19,7 +19,7 @@ def _warm_up(self):
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_)
Expand Down
6 changes: 3 additions & 3 deletions tools/test.py
Expand Up @@ -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()

Expand Down
5 changes: 3 additions & 2 deletions tools/throughput_benchmark.py
Expand Up @@ -19,7 +19,8 @@
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()
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tools/unit_tests.py
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion website/index.html
Expand Up @@ -104,7 +104,7 @@ <h2 id="install">Install <a href="#install">#</a></h2>
<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>

Expand Down
33 changes: 13 additions & 20 deletions website/manual.md
Expand Up @@ -543,31 +543,24 @@ 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
-h, --help Prints help information
-D, --log-debug Log debug output
-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
types Print runtime TypeScript declarations
version Print the version
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

ENVIRONMENT VARIABLES:
DENO_DIR Set deno's base directory
Expand Down

0 comments on commit f6a9d7d

Please sign in to comment.