Skip to content

Commit

Permalink
feat: Deno.args now does not include script (denoland#3628)
Browse files Browse the repository at this point in the history
Previously Deno.args was ["script.js", "arg1", "arg2"]
Now it is just ["arg1", "arg2"]
BREAKING CHANGE
  • Loading branch information
ry committed Jan 9, 2020
1 parent c50cab9 commit d492c5a
Show file tree
Hide file tree
Showing 22 changed files with 29 additions and 28 deletions.
4 changes: 1 addition & 3 deletions cli/js/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions cli/ops/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@ fn op_start(
_zero_copy: Option<PinnedBuf>,
) -> Result<JsonOp, ErrBox> {
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,
Expand Down
1 change: 0 additions & 1 deletion cli/tests/028_args.ts.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
028_args.ts
--arg1
val1
--arg2=val2
Expand Down
2 changes: 1 addition & 1 deletion std/examples/cat.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion std/examples/catj.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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...]");
Expand Down
2 changes: 1 addition & 1 deletion std/examples/gist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion std/fs/testdata/empty_dir.ts
Original file line number Diff line number Diff line change
@@ -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"))
})
Expand Down
2 changes: 1 addition & 1 deletion std/fs/testdata/empty_dir_sync.ts
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
2 changes: 1 addition & 1 deletion std/fs/testdata/exists.ts
Original file line number Diff line number Diff line change
@@ -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'))
})
Expand Down
2 changes: 1 addition & 1 deletion std/fs/testdata/exists_sync.ts
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
2 changes: 1 addition & 1 deletion std/http/http_bench.ts
Original file line number Diff line number Diff line change
@@ -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");

Expand Down
2 changes: 1 addition & 1 deletion std/installer/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export async function install(
}

async function main(): Promise<void> {
const parsedArgs = parse(args.slice(1), { stopEarly: true });
const parsedArgs = parse(args, { stopEarly: true });

if (parsedArgs.h || parsedArgs.help) {
return showHelp();
Expand Down
2 changes: 1 addition & 1 deletion std/installer/testdata/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion std/installer/testdata/echo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ function echo(args: string[]) {
Deno.stdout.write(new TextEncoder().encode(msg));
}

echo(Deno.args.slice(1));
echo(Deno.args);
4 changes: 2 additions & 2 deletions std/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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: [
Expand Down
2 changes: 1 addition & 1 deletion std/prettier/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ async function main(opts): Promise<void> {
}

main(
parse(args.slice(1), {
parse(args, {
string: [
"ignore",
"ignore-path",
Expand Down
2 changes: 1 addition & 1 deletion std/prettier/testdata/echox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ async function echox(args: string[]) {
Deno.exit(0);
}

echox(Deno.args.slice(1));
echox(Deno.args);
2 changes: 1 addition & 1 deletion std/testing/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export async function runTestModules({
}

async function main(): Promise<void> {
const parsedArgs = parse(args.slice(1), {
const parsedArgs = parse(args, {
boolean: ["allow-none", "failfast", "help", "quiet"],
string: ["exclude"],
alias: {
Expand Down
2 changes: 1 addition & 1 deletion test_plugin/tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions tools/deno_http_proxy.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
Expand Down
2 changes: 1 addition & 1 deletion tools/deno_tcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions tools/deno_tcp_proxy.ts
Original file line number Diff line number Diff line change
@@ -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(":");
Expand Down

0 comments on commit d492c5a

Please sign in to comment.