mirror of
https://github.com/denoland/deno.git
synced 2025-03-04 01:44: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:
parent
c50cab90a0
commit
d492c5abe3
22 changed files with 29 additions and 28 deletions
|
@ -25,10 +25,8 @@ function denoMain(preserveDenoNamespace = true, name?: string): void {
|
||||||
assert(s.mainModule.length > 0);
|
assert(s.mainModule.length > 0);
|
||||||
setLocation(s.mainModule);
|
setLocation(s.mainModule);
|
||||||
}
|
}
|
||||||
|
|
||||||
log("cwd", s.cwd);
|
log("cwd", s.cwd);
|
||||||
|
for (let i = 0; i < s.argv.length; i++) {
|
||||||
for (let i = 1; i < s.argv.length; i++) {
|
|
||||||
args.push(s.argv[i]);
|
args.push(s.argv[i]);
|
||||||
}
|
}
|
||||||
log("args", args);
|
log("args", args);
|
||||||
|
|
|
@ -41,11 +41,15 @@ fn op_start(
|
||||||
_zero_copy: Option<PinnedBuf>,
|
_zero_copy: Option<PinnedBuf>,
|
||||||
) -> Result<JsonOp, ErrBox> {
|
) -> Result<JsonOp, ErrBox> {
|
||||||
let gs = &state.global_state;
|
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!({
|
Ok(JsonOp::Sync(json!({
|
||||||
"cwd": deno_fs::normalize_path(&env::current_dir().unwrap()),
|
"cwd": deno_fs::normalize_path(&env::current_dir().unwrap()),
|
||||||
"pid": std::process::id(),
|
"pid": std::process::id(),
|
||||||
"argv": gs.flags.argv,
|
"argv": script_args,
|
||||||
"mainModule": gs.main_module.as_ref().map(|x| x.to_string()),
|
"mainModule": gs.main_module.as_ref().map(|x| x.to_string()),
|
||||||
"debugFlag": gs.flags.log_level.map_or(false, |l| l == log::Level::Debug),
|
"debugFlag": gs.flags.log_level.map_or(false, |l| l == log::Level::Debug),
|
||||||
"versionFlag": gs.flags.version,
|
"versionFlag": gs.flags.version,
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
028_args.ts
|
|
||||||
--arg1
|
--arg1
|
||||||
val1
|
val1
|
||||||
--arg2=val2
|
--arg2=val2
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// 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) {
|
for (const filename of filenames) {
|
||||||
const file = await Deno.open(filename);
|
const file = await Deno.open(filename);
|
||||||
await Deno.copy(Deno.stdout, file);
|
await Deno.copy(Deno.stdout, 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) {
|
if (parsedArgs.h || parsedArgs.help || parsedArgs._.length === 0) {
|
||||||
console.log("Usage: catj [-h|--help] [file...]");
|
console.log("Usage: catj [-h|--help] [file...]");
|
||||||
|
|
|
@ -14,7 +14,7 @@ if (!token) {
|
||||||
Deno.exit(1);
|
Deno.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsedArgs = parse(Deno.args.slice(1));
|
const parsedArgs = parse(Deno.args);
|
||||||
|
|
||||||
if (parsedArgs._.length === 0) {
|
if (parsedArgs._.length === 0) {
|
||||||
console.error(
|
console.error(
|
||||||
|
|
2
std/fs/testdata/empty_dir.ts
vendored
2
std/fs/testdata/empty_dir.ts
vendored
|
@ -1,6 +1,6 @@
|
||||||
import { emptyDir } from "../empty_dir.ts";
|
import { emptyDir } from "../empty_dir.ts";
|
||||||
|
|
||||||
emptyDir(Deno.args[1])
|
emptyDir(Deno.args[0])
|
||||||
.then(() => {
|
.then(() => {
|
||||||
Deno.stdout.write(new TextEncoder().encode("success"))
|
Deno.stdout.write(new TextEncoder().encode("success"))
|
||||||
})
|
})
|
||||||
|
|
2
std/fs/testdata/empty_dir_sync.ts
vendored
2
std/fs/testdata/empty_dir_sync.ts
vendored
|
@ -1,7 +1,7 @@
|
||||||
import { emptyDirSync } from "../empty_dir.ts";
|
import { emptyDirSync } from "../empty_dir.ts";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
emptyDirSync(Deno.args[1])
|
emptyDirSync(Deno.args[0])
|
||||||
Deno.stdout.write(new TextEncoder().encode("success"))
|
Deno.stdout.write(new TextEncoder().encode("success"))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Deno.stdout.write(new TextEncoder().encode(err.message))
|
Deno.stdout.write(new TextEncoder().encode(err.message))
|
||||||
|
|
2
std/fs/testdata/exists.ts
vendored
2
std/fs/testdata/exists.ts
vendored
|
@ -1,6 +1,6 @@
|
||||||
import { exists } from "../exists.ts";
|
import { exists } from "../exists.ts";
|
||||||
|
|
||||||
exists(Deno.args[1])
|
exists(Deno.args[0])
|
||||||
.then(isExist => {
|
.then(isExist => {
|
||||||
Deno.stdout.write(new TextEncoder().encode(isExist ? 'exist' :'not exist'))
|
Deno.stdout.write(new TextEncoder().encode(isExist ? 'exist' :'not exist'))
|
||||||
})
|
})
|
||||||
|
|
2
std/fs/testdata/exists_sync.ts
vendored
2
std/fs/testdata/exists_sync.ts
vendored
|
@ -1,7 +1,7 @@
|
||||||
import { existsSync } from "../exists.ts";
|
import { existsSync } from "../exists.ts";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const isExist = existsSync(Deno.args[1])
|
const isExist = existsSync(Deno.args[0])
|
||||||
Deno.stdout.write(new TextEncoder().encode(isExist ? 'exist' :'not exist'))
|
Deno.stdout.write(new TextEncoder().encode(isExist ? 'exist' :'not exist'))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Deno.stdout.write(new TextEncoder().encode(err.message))
|
Deno.stdout.write(new TextEncoder().encode(err.message))
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { serve } from "./server.ts";
|
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 server = serve(addr);
|
||||||
const body = new TextEncoder().encode("Hello World");
|
const body = new TextEncoder().encode("Hello World");
|
||||||
|
|
||||||
|
|
|
@ -276,7 +276,7 @@ export async function install(
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main(): Promise<void> {
|
async function main(): Promise<void> {
|
||||||
const parsedArgs = parse(args.slice(1), { stopEarly: true });
|
const parsedArgs = parse(args, { stopEarly: true });
|
||||||
|
|
||||||
if (parsedArgs.h || parsedArgs.help) {
|
if (parsedArgs.h || parsedArgs.help) {
|
||||||
return showHelp();
|
return showHelp();
|
||||||
|
|
2
std/installer/testdata/args.ts
vendored
2
std/installer/testdata/args.ts
vendored
|
@ -6,4 +6,4 @@ function args(args: string[]) {
|
||||||
Deno.stdout.write(new TextEncoder().encode(JSON.stringify(map)));
|
Deno.stdout.write(new TextEncoder().encode(JSON.stringify(map)));
|
||||||
}
|
}
|
||||||
|
|
||||||
args(Deno.args.slice(1));
|
args(Deno.args);
|
||||||
|
|
2
std/installer/testdata/echo.ts
vendored
2
std/installer/testdata/echo.ts
vendored
|
@ -3,4 +3,4 @@ function echo(args: string[]) {
|
||||||
Deno.stdout.write(new TextEncoder().encode(msg));
|
Deno.stdout.write(new TextEncoder().encode(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
echo(Deno.args.slice(1));
|
echo(Deno.args);
|
||||||
|
|
|
@ -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.
|
is opened, and printed to stdout.
|
||||||
|
|
||||||
```ts
|
```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 filename = Deno.args[i];
|
||||||
let file = await Deno.open(filename);
|
let file = await Deno.open(filename);
|
||||||
await Deno.copy(Deno.stdout, file);
|
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.
|
you can use `"piped"` option.
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const fileNames = Deno.args.slice(1);
|
const fileNames = Deno.args;
|
||||||
|
|
||||||
const p = Deno.run({
|
const p = Deno.run({
|
||||||
args: [
|
args: [
|
||||||
|
|
|
@ -565,7 +565,7 @@ async function main(opts): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
main(
|
main(
|
||||||
parse(args.slice(1), {
|
parse(args, {
|
||||||
string: [
|
string: [
|
||||||
"ignore",
|
"ignore",
|
||||||
"ignore-path",
|
"ignore-path",
|
||||||
|
|
2
std/prettier/testdata/echox.ts
vendored
2
std/prettier/testdata/echox.ts
vendored
|
@ -5,4 +5,4 @@ async function echox(args: string[]) {
|
||||||
Deno.exit(0);
|
Deno.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
echox(Deno.args.slice(1));
|
echox(Deno.args);
|
||||||
|
|
|
@ -243,7 +243,7 @@ export async function runTestModules({
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main(): Promise<void> {
|
async function main(): Promise<void> {
|
||||||
const parsedArgs = parse(args.slice(1), {
|
const parsedArgs = parse(args, {
|
||||||
boolean: ["allow-none", "failfast", "help", "quiet"],
|
boolean: ["allow-none", "failfast", "help", "quiet"],
|
||||||
string: ["exclude"],
|
string: ["exclude"],
|
||||||
alias: {
|
alias: {
|
||||||
|
|
|
@ -11,7 +11,7 @@ if (Deno.build.os === "mac") {
|
||||||
filenameSuffix = ".dylib";
|
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);
|
const plugin = Deno.openPlugin(filename);
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { serve, ServerRequest } from "../std/http/server.ts";
|
import { serve, ServerRequest } from "../std/http/server.ts";
|
||||||
|
|
||||||
const addr = Deno.args[1] || "127.0.0.1:4500";
|
const addr = Deno.args[0] || "127.0.0.1:4500";
|
||||||
const originAddr = Deno.args[2] || "127.0.0.1:4501";
|
const originAddr = Deno.args[1] || "127.0.0.1:4501";
|
||||||
const server = serve(addr);
|
const server = serve(addr);
|
||||||
|
|
||||||
async function proxyRequest(req: ServerRequest): Promise<void> {
|
async function proxyRequest(req: ServerRequest): Promise<void> {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
// TODO Replace this with a real HTTP server once
|
// TODO Replace this with a real HTTP server once
|
||||||
// https://github.com/denoland/deno/issues/726 is completed.
|
// https://github.com/denoland/deno/issues/726 is completed.
|
||||||
// Note: this is a keep-alive server.
|
// 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 [hostname, port] = addr.split(":");
|
||||||
const listener = Deno.listen({ hostname, port: Number(port) });
|
const listener = Deno.listen({ hostname, port: Number(port) });
|
||||||
const response = new TextEncoder().encode(
|
const response = new TextEncoder().encode(
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Used for benchmarking Deno's tcp proxy perfromance. See tools/http_benchmark.py
|
// Used for benchmarking Deno's tcp proxy perfromance. See tools/http_benchmark.py
|
||||||
const addr = Deno.args[1] || "127.0.0.1:4500";
|
const addr = Deno.args[0] || "127.0.0.1:4500";
|
||||||
const originAddr = Deno.args[2] || "127.0.0.1:4501";
|
const originAddr = Deno.args[1] || "127.0.0.1:4501";
|
||||||
|
|
||||||
const [hostname, port] = addr.split(":");
|
const [hostname, port] = addr.split(":");
|
||||||
const [originHostname, originPort] = originAddr.split(":");
|
const [originHostname, originPort] = originAddr.split(":");
|
||||||
|
|
Loading…
Add table
Reference in a new issue