diff --git a/cli/js/main.ts b/cli/js/main.ts index 8a0f805a80..0056862308 100644 --- a/cli/js/main.ts +++ b/cli/js/main.ts @@ -25,10 +25,8 @@ function denoMain(preserveDenoNamespace = true, name?: string): void { assert(s.mainModule.length > 0); setLocation(s.mainModule); } - log("cwd", s.cwd); - - for (let i = 1; i < s.argv.length; i++) { + for (let i = 0; i < s.argv.length; i++) { args.push(s.argv[i]); } log("args", args); diff --git a/cli/ops/os.rs b/cli/ops/os.rs index e01071230f..8add8759c0 100644 --- a/cli/ops/os.rs +++ b/cli/ops/os.rs @@ -41,11 +41,15 @@ fn op_start( _zero_copy: Option, ) -> Result { let gs = &state.global_state; - + let script_args = if gs.flags.argv.len() >= 2 { + gs.flags.argv.clone().split_off(2) + } else { + vec![] + }; Ok(JsonOp::Sync(json!({ "cwd": deno_fs::normalize_path(&env::current_dir().unwrap()), "pid": std::process::id(), - "argv": gs.flags.argv, + "argv": script_args, "mainModule": gs.main_module.as_ref().map(|x| x.to_string()), "debugFlag": gs.flags.log_level.map_or(false, |l| l == log::Level::Debug), "versionFlag": gs.flags.version, diff --git a/cli/tests/028_args.ts.out b/cli/tests/028_args.ts.out index fa36f6e4c8..0f1b5c59e9 100644 --- a/cli/tests/028_args.ts.out +++ b/cli/tests/028_args.ts.out @@ -1,4 +1,3 @@ -028_args.ts --arg1 val1 --arg2=val2 diff --git a/std/examples/cat.ts b/std/examples/cat.ts index 92d5ae3970..7b7af3145c 100644 --- a/std/examples/cat.ts +++ b/std/examples/cat.ts @@ -1,5 +1,5 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -const filenames = Deno.args.slice(1); +const filenames = Deno.args; for (const filename of filenames) { const file = await Deno.open(filename); await Deno.copy(Deno.stdout, file); diff --git a/std/examples/catj.ts b/std/examples/catj.ts index 2f578790d6..ef6fdb02f9 100644 --- a/std/examples/catj.ts +++ b/std/examples/catj.ts @@ -79,7 +79,7 @@ function print(data: any): void { } } -const parsedArgs = parse(Deno.args.slice(1)); +const parsedArgs = parse(Deno.args); if (parsedArgs.h || parsedArgs.help || parsedArgs._.length === 0) { console.log("Usage: catj [-h|--help] [file...]"); diff --git a/std/examples/gist.ts b/std/examples/gist.ts index c9a9b024b7..ead97c7e2e 100755 --- a/std/examples/gist.ts +++ b/std/examples/gist.ts @@ -14,7 +14,7 @@ if (!token) { Deno.exit(1); } -const parsedArgs = parse(Deno.args.slice(1)); +const parsedArgs = parse(Deno.args); if (parsedArgs._.length === 0) { console.error( diff --git a/std/fs/testdata/empty_dir.ts b/std/fs/testdata/empty_dir.ts index 6147679daa..aa9cf60a17 100644 --- a/std/fs/testdata/empty_dir.ts +++ b/std/fs/testdata/empty_dir.ts @@ -1,6 +1,6 @@ import { emptyDir } from "../empty_dir.ts"; -emptyDir(Deno.args[1]) +emptyDir(Deno.args[0]) .then(() => { Deno.stdout.write(new TextEncoder().encode("success")) }) diff --git a/std/fs/testdata/empty_dir_sync.ts b/std/fs/testdata/empty_dir_sync.ts index 3c0eb9031c..0bef81e910 100644 --- a/std/fs/testdata/empty_dir_sync.ts +++ b/std/fs/testdata/empty_dir_sync.ts @@ -1,7 +1,7 @@ import { emptyDirSync } from "../empty_dir.ts"; try { - emptyDirSync(Deno.args[1]) + emptyDirSync(Deno.args[0]) Deno.stdout.write(new TextEncoder().encode("success")) } catch (err) { Deno.stdout.write(new TextEncoder().encode(err.message)) diff --git a/std/fs/testdata/exists.ts b/std/fs/testdata/exists.ts index aee8574d87..93812a7038 100644 --- a/std/fs/testdata/exists.ts +++ b/std/fs/testdata/exists.ts @@ -1,6 +1,6 @@ import { exists } from "../exists.ts"; -exists(Deno.args[1]) +exists(Deno.args[0]) .then(isExist => { Deno.stdout.write(new TextEncoder().encode(isExist ? 'exist' :'not exist')) }) diff --git a/std/fs/testdata/exists_sync.ts b/std/fs/testdata/exists_sync.ts index 70b2071c11..27dee268b6 100644 --- a/std/fs/testdata/exists_sync.ts +++ b/std/fs/testdata/exists_sync.ts @@ -1,7 +1,7 @@ import { existsSync } from "../exists.ts"; try { - const isExist = existsSync(Deno.args[1]) + const isExist = existsSync(Deno.args[0]) Deno.stdout.write(new TextEncoder().encode(isExist ? 'exist' :'not exist')) } catch (err) { Deno.stdout.write(new TextEncoder().encode(err.message)) diff --git a/std/http/http_bench.ts b/std/http/http_bench.ts index 8ca389e5ca..9d19128317 100644 --- a/std/http/http_bench.ts +++ b/std/http/http_bench.ts @@ -1,7 +1,7 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { serve } from "./server.ts"; -const addr = Deno.args[1] || "127.0.0.1:4500"; +const addr = Deno.args[0] || "127.0.0.1:4500"; const server = serve(addr); const body = new TextEncoder().encode("Hello World"); diff --git a/std/installer/mod.ts b/std/installer/mod.ts index a8a280d93b..1d9558520d 100644 --- a/std/installer/mod.ts +++ b/std/installer/mod.ts @@ -276,7 +276,7 @@ export async function install( } async function main(): Promise { - const parsedArgs = parse(args.slice(1), { stopEarly: true }); + const parsedArgs = parse(args, { stopEarly: true }); if (parsedArgs.h || parsedArgs.help) { return showHelp(); diff --git a/std/installer/testdata/args.ts b/std/installer/testdata/args.ts index 484cab5aba..1c0ec0687f 100644 --- a/std/installer/testdata/args.ts +++ b/std/installer/testdata/args.ts @@ -6,4 +6,4 @@ function args(args: string[]) { Deno.stdout.write(new TextEncoder().encode(JSON.stringify(map))); } -args(Deno.args.slice(1)); +args(Deno.args); diff --git a/std/installer/testdata/echo.ts b/std/installer/testdata/echo.ts index 62ddd6d057..84a6454333 100644 --- a/std/installer/testdata/echo.ts +++ b/std/installer/testdata/echo.ts @@ -3,4 +3,4 @@ function echo(args: string[]) { Deno.stdout.write(new TextEncoder().encode(msg)); } -echo(Deno.args.slice(1)); +echo(Deno.args); diff --git a/std/manual.md b/std/manual.md index b09ce9364c..a92e45c26f 100644 --- a/std/manual.md +++ b/std/manual.md @@ -193,7 +193,7 @@ In this program each command-line argument is assumed to be a filename, the file is opened, and printed to stdout. ```ts -for (let i = 1; i < Deno.args.length; i++) { +for (let i = 0; i < Deno.args.length; i++) { let filename = Deno.args[i]; let file = await Deno.open(filename); await Deno.copy(Deno.stdout, file); @@ -386,7 +386,7 @@ By default when you use `Deno.run()` subprocess inherits `stdin`, `stdout` and you can use `"piped"` option. ```ts -const fileNames = Deno.args.slice(1); +const fileNames = Deno.args; const p = Deno.run({ args: [ diff --git a/std/prettier/main.ts b/std/prettier/main.ts index 248aff9a07..a61faa975c 100755 --- a/std/prettier/main.ts +++ b/std/prettier/main.ts @@ -565,7 +565,7 @@ async function main(opts): Promise { } main( - parse(args.slice(1), { + parse(args, { string: [ "ignore", "ignore-path", diff --git a/std/prettier/testdata/echox.ts b/std/prettier/testdata/echox.ts index 68c54b9995..5f8306b376 100644 --- a/std/prettier/testdata/echox.ts +++ b/std/prettier/testdata/echox.ts @@ -5,4 +5,4 @@ async function echox(args: string[]) { Deno.exit(0); } -echox(Deno.args.slice(1)); +echox(Deno.args); diff --git a/std/testing/runner.ts b/std/testing/runner.ts index d0d9ae2ecc..17d5942f89 100755 --- a/std/testing/runner.ts +++ b/std/testing/runner.ts @@ -243,7 +243,7 @@ export async function runTestModules({ } async function main(): Promise { - const parsedArgs = parse(args.slice(1), { + const parsedArgs = parse(args, { boolean: ["allow-none", "failfast", "help", "quiet"], string: ["exclude"], alias: { diff --git a/test_plugin/tests/test.js b/test_plugin/tests/test.js index cdbde4769a..49b126e62d 100644 --- a/test_plugin/tests/test.js +++ b/test_plugin/tests/test.js @@ -11,7 +11,7 @@ if (Deno.build.os === "mac") { filenameSuffix = ".dylib"; } -const filename = `../target/${Deno.args[1]}/${filenamePrefix}${filenameBase}${filenameSuffix}`; +const filename = `../target/${Deno.args[0]}/${filenamePrefix}${filenameBase}${filenameSuffix}`; const plugin = Deno.openPlugin(filename); diff --git a/tools/deno_http_proxy.ts b/tools/deno_http_proxy.ts index 75ea4b2414..589a14338d 100644 --- a/tools/deno_http_proxy.ts +++ b/tools/deno_http_proxy.ts @@ -1,8 +1,8 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { serve, ServerRequest } from "../std/http/server.ts"; -const addr = Deno.args[1] || "127.0.0.1:4500"; -const originAddr = Deno.args[2] || "127.0.0.1:4501"; +const addr = Deno.args[0] || "127.0.0.1:4500"; +const originAddr = Deno.args[1] || "127.0.0.1:4501"; const server = serve(addr); async function proxyRequest(req: ServerRequest): Promise { diff --git a/tools/deno_tcp.ts b/tools/deno_tcp.ts index 13ebe76afc..9a884cb705 100644 --- a/tools/deno_tcp.ts +++ b/tools/deno_tcp.ts @@ -2,7 +2,7 @@ // TODO Replace this with a real HTTP server once // https://github.com/denoland/deno/issues/726 is completed. // Note: this is a keep-alive server. -const addr = Deno.args[1] || "127.0.0.1:4500"; +const addr = Deno.args[0] || "127.0.0.1:4500"; const [hostname, port] = addr.split(":"); const listener = Deno.listen({ hostname, port: Number(port) }); const response = new TextEncoder().encode( diff --git a/tools/deno_tcp_proxy.ts b/tools/deno_tcp_proxy.ts index 487825648d..bf54ad1c0c 100644 --- a/tools/deno_tcp_proxy.ts +++ b/tools/deno_tcp_proxy.ts @@ -1,6 +1,6 @@ // Used for benchmarking Deno's tcp proxy perfromance. See tools/http_benchmark.py -const addr = Deno.args[1] || "127.0.0.1:4500"; -const originAddr = Deno.args[2] || "127.0.0.1:4501"; +const addr = Deno.args[0] || "127.0.0.1:4500"; +const originAddr = Deno.args[1] || "127.0.0.1:4501"; const [hostname, port] = addr.split(":"); const [originHostname, originPort] = originAddr.split(":");