1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

feat: Deno.args now does not include script (#3628)

Previously Deno.args was ["script.js", "arg1", "arg2"]
Now it is just ["arg1", "arg2"]
BREAKING CHANGE
This commit is contained in:
Ry Dahl 2020-01-09 11:37:01 -07:00 committed by GitHub
parent c50cab90a0
commit d492c5abe3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 29 additions and 28 deletions

View file

@ -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);

View file

@ -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,

View file

@ -1,4 +1,3 @@
028_args.ts
--arg1
val1
--arg2=val2

View file

@ -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);

View file

@ -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...]");

View file

@ -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(

View file

@ -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"))
})

View file

@ -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))

View file

@ -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'))
})

View file

@ -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))

View file

@ -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");

View file

@ -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();

View file

@ -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);

View file

@ -3,4 +3,4 @@ function echo(args: string[]) {
Deno.stdout.write(new TextEncoder().encode(msg));
}
echo(Deno.args.slice(1));
echo(Deno.args);

View file

@ -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: [

View file

@ -565,7 +565,7 @@ async function main(opts): Promise<void> {
}
main(
parse(args.slice(1), {
parse(args, {
string: [
"ignore",
"ignore-path",

View file

@ -5,4 +5,4 @@ async function echox(args: string[]) {
Deno.exit(0);
}
echox(Deno.args.slice(1));
echox(Deno.args);

View file

@ -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: {

View file

@ -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);

View file

@ -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> {

View file

@ -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(

View file

@ -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(":");