0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -05:00

BREAKING CHANGE Rename Deno.run's args to cmd (#4444)

This is to avoid confusion with Deno.args which does not include the 
executable to be run.
This commit is contained in:
Akshat Agarwal 2020-03-22 03:14:18 +05:30 committed by GitHub
parent b191c919f3
commit b8a5c29bf8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 60 additions and 60 deletions

View file

@ -1900,12 +1900,12 @@ declare namespace Deno {
signal?: number;
}
/** **UNSTABLE**: Maybe rename `args` to `argv` to differentiate from
/** **UNSTABLE**: `args` has been recently renamed to `cmd` to differentiate from
* `Deno.args`. */
export interface RunOptions {
/** Arguments to pass. Note, the first element needs to be a path to the
* binary */
args: string[];
cmd: string[];
cwd?: string;
env?: {
[key: string]: string;

View file

@ -17,7 +17,7 @@ export function runStatus(rid: number): Promise<RunStatusResponse> {
}
interface RunRequest {
args: string[];
cmd: string[];
cwd?: string;
env?: Array<[string, string]>;
stdin: string;
@ -37,6 +37,6 @@ interface RunResponse {
}
export function run(request: RunRequest): RunResponse {
assert(request.args.length > 0);
assert(request.cmd.length > 0);
return sendSync("op_run", request);
}

View file

@ -10,7 +10,7 @@ export type ProcessStdio = "inherit" | "piped" | "null";
// TODO Maybe extend VSCode's 'CommandOptions'?
// See https://code.visualstudio.com/docs/editor/tasks-appendix#_schema-for-tasksjson
export interface RunOptions {
args: string[];
cmd: string[];
cwd?: string;
env?: { [key: string]: string };
stdout?: ProcessStdio | number;
@ -108,7 +108,7 @@ interface RunResponse {
stderrRid: number | null;
}
export function run({
args,
cmd,
cwd = undefined,
env = {},
stdout = "inherit",
@ -116,7 +116,7 @@ export function run({
stdin = "inherit"
}: RunOptions): Process {
const res = runOp({
args: args.map(String),
cmd: cmd.map(String),
cwd,
env: Object.entries(env),
stdin: isRid(stdin) ? "" : stdin,

View file

@ -7,11 +7,11 @@ if (Deno.build.os !== "win") {
// get the user ID and group ID of the current process
const uidProc = Deno.run({
stdout: "piped",
args: ["python", "-c", "import os; print(os.getuid())"]
cmd: ["python", "-c", "import os; print(os.getuid())"]
});
const gidProc = Deno.run({
stdout: "piped",
args: ["python", "-c", "import os; print(os.getgid())"]
cmd: ["python", "-c", "import os; print(os.getgid())"]
});
assertEquals((await uidProc.status()).code, 0);

View file

@ -65,7 +65,7 @@ unitTest(
${JSON.stringify(Object.keys(expectedEnv))}.map(k => Deno.env(k))
)`;
const proc = Deno.run({
args: [Deno.execPath(), "eval", src],
cmd: [Deno.execPath(), "eval", src],
env: inputEnv,
stdout: "piped"
});

View file

@ -10,7 +10,7 @@ const { kill, run, readFile, open, makeTempDir, writeFile } = Deno;
unitTest(function runPermissions(): void {
let caughtError = false;
try {
Deno.run({ args: ["python", "-c", "print('hello world')"] });
Deno.run({ cmd: ["python", "-c", "print('hello world')"] });
} catch (e) {
caughtError = true;
assert(e instanceof Deno.errors.PermissionDenied);
@ -20,7 +20,7 @@ unitTest(function runPermissions(): void {
unitTest({ perms: { run: true } }, async function runSuccess(): Promise<void> {
const p = run({
args: ["python", "-c", "print('hello world')"],
cmd: ["python", "-c", "print('hello world')"],
stdout: "piped",
stderr: "null"
});
@ -36,7 +36,7 @@ unitTest(
{ perms: { run: true } },
async function runCommandFailedWithCode(): Promise<void> {
const p = run({
args: ["python", "-c", "import sys;sys.exit(41 + 1)"]
cmd: ["python", "-c", "import sys;sys.exit(41 + 1)"]
});
const status = await p.status();
assertEquals(status.success, false);
@ -54,7 +54,7 @@ unitTest(
},
async function runCommandFailedWithSignal(): Promise<void> {
const p = run({
args: ["python", "-c", "import os;os.kill(os.getpid(), 9)"]
cmd: ["python", "-c", "import os;os.kill(os.getpid(), 9)"]
});
const status = await p.status();
assertEquals(status.success, false);
@ -67,7 +67,7 @@ unitTest(
unitTest({ perms: { run: true } }, function runNotFound(): void {
let error;
try {
run({ args: ["this file hopefully doesn't exist"] });
run({ cmd: ["this file hopefully doesn't exist"] });
} catch (e) {
error = e;
}
@ -102,7 +102,7 @@ while True:
Deno.writeFileSync(`${cwd}/${pyProgramFile}.py`, enc.encode(pyProgram));
const p = run({
cwd,
args: ["python", `${pyProgramFile}.py`]
cmd: ["python", `${pyProgramFile}.py`]
});
// Write the expected exit code *after* starting python.
@ -122,7 +122,7 @@ unitTest({ perms: { run: true } }, async function runStdinPiped(): Promise<
void
> {
const p = run({
args: ["python", "-c", "import sys; assert 'hello' == sys.stdin.read();"],
cmd: ["python", "-c", "import sys; assert 'hello' == sys.stdin.read();"],
stdin: "piped"
});
assert(p.stdin);
@ -146,7 +146,7 @@ unitTest({ perms: { run: true } }, async function runStdoutPiped(): Promise<
void
> {
const p = run({
args: ["python", "-c", "import sys; sys.stdout.write('hello')"],
cmd: ["python", "-c", "import sys; sys.stdout.write('hello')"],
stdout: "piped"
});
assert(!p.stdin);
@ -175,7 +175,7 @@ unitTest({ perms: { run: true } }, async function runStderrPiped(): Promise<
void
> {
const p = run({
args: ["python", "-c", "import sys; sys.stderr.write('hello')"],
cmd: ["python", "-c", "import sys; sys.stderr.write('hello')"],
stderr: "piped"
});
assert(!p.stdin);
@ -202,7 +202,7 @@ unitTest({ perms: { run: true } }, async function runStderrPiped(): Promise<
unitTest({ perms: { run: true } }, async function runOutput(): Promise<void> {
const p = run({
args: ["python", "-c", "import sys; sys.stdout.write('hello')"],
cmd: ["python", "-c", "import sys; sys.stdout.write('hello')"],
stdout: "piped"
});
const output = await p.output();
@ -215,7 +215,7 @@ unitTest({ perms: { run: true } }, async function runStderrOutput(): Promise<
void
> {
const p = run({
args: ["python", "-c", "import sys; sys.stderr.write('error')"],
cmd: ["python", "-c", "import sys; sys.stderr.write('error')"],
stderr: "piped"
});
const error = await p.stderrOutput();
@ -232,7 +232,7 @@ unitTest(
const file = await open(fileName, "w");
const p = run({
args: [
cmd: [
"python",
"-c",
"import sys; sys.stderr.write('error\\n'); sys.stdout.write('output\\n');"
@ -264,7 +264,7 @@ unitTest(
const file = await open(fileName, "r");
const p = run({
args: ["python", "-c", "import sys; assert 'hello' == sys.stdin.read();"],
cmd: ["python", "-c", "import sys; assert 'hello' == sys.stdin.read();"],
stdin: file.rid
});
@ -277,7 +277,7 @@ unitTest(
unitTest({ perms: { run: true } }, async function runEnv(): Promise<void> {
const p = run({
args: [
cmd: [
"python",
"-c",
"import os, sys; sys.stdout.write(os.environ.get('FOO', '') + os.environ.get('BAR', ''))"
@ -296,7 +296,7 @@ unitTest({ perms: { run: true } }, async function runEnv(): Promise<void> {
unitTest({ perms: { run: true } }, async function runClose(): Promise<void> {
const p = run({
args: [
cmd: [
"python",
"-c",
"from time import sleep; import sys; sleep(10000); sys.stderr.write('error')"
@ -343,7 +343,7 @@ if (Deno.build.os !== "win") {
void
> {
const p = run({
args: ["python", "-c", "from time import sleep; sleep(10000)"]
cmd: ["python", "-c", "from time import sleep; sleep(10000)"]
});
assertEquals(Deno.Signal.SIGINT, 2);
@ -361,7 +361,7 @@ if (Deno.build.os !== "win") {
unitTest({ perms: { run: true } }, function killFailed(): void {
const p = run({
args: ["python", "-c", "from time import sleep; sleep(10000)"]
cmd: ["python", "-c", "from time import sleep; sleep(10000)"]
});
assert(!p.stdin);
assert(!p.stdout);

View file

@ -86,7 +86,7 @@ function spawnWorkerRunner(
})
.join(",");
const args = [
const cmd = [
Deno.execPath(),
"run",
"-A",
@ -97,14 +97,14 @@ function spawnWorkerRunner(
];
if (filter) {
args.push("--");
args.push(filter);
cmd.push("--");
cmd.push(filter);
}
const ioMode = verbose ? "inherit" : "null";
const p = Deno.run({
args,
cmd,
stdin: ioMode,
stdout: ioMode,
stderr: ioMode

View file

@ -49,7 +49,7 @@ fn subprocess_stdio_map(s: &str) -> std::process::Stdio {
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct RunArgs {
args: Vec<String>,
cmd: Vec<String>,
cwd: Option<String>,
env: Vec<(String, String)>,
stdin: String,
@ -74,7 +74,7 @@ fn op_run(
state.check_run()?;
let state_ = state.clone();
let args = run_args.args;
let args = run_args.cmd;
let env = run_args.env;
let cwd = run_args.cwd;

View file

@ -24,7 +24,7 @@ async function proxyRequest(req: ServerRequest): Promise<void> {
async function testFetch(): Promise<void> {
const c = Deno.run({
args: [Deno.execPath(), "--reload", "--allow-net", "045_proxy_client.ts"],
cmd: [Deno.execPath(), "--reload", "--allow-net", "045_proxy_client.ts"],
stdout: "piped",
env: {
HTTP_PROXY: `http://${addr}`
@ -38,7 +38,7 @@ async function testFetch(): Promise<void> {
async function testModuleDownload(): Promise<void> {
const http = Deno.run({
args: [
cmd: [
Deno.execPath(),
"--reload",
"fetch",

View file

@ -5,7 +5,7 @@ try {
const fetchProc = Deno.run({
stdout: "null",
stderr: "null",
args: [
cmd: [
Deno.execPath(),
"fetch",
"--reload",
@ -21,7 +21,7 @@ console.log(`fetch code: ${fetchCode}`);
const fetchCheckProc = Deno.run({
stdout: "null",
stderr: "null",
args: [
cmd: [
Deno.execPath(),
"fetch",
"--lock=lock_write_fetch.json",
@ -35,7 +35,7 @@ console.log(`fetch check code: ${fetchCheckProcCode}`);
const runProc = Deno.run({
stdout: "null",
stderr: "null",
args: [Deno.execPath(), "--lock=lock_write_fetch.json", "https_import.ts"]
cmd: [Deno.execPath(), "--lock=lock_write_fetch.json", "https_import.ts"]
});
const runCode = (await runProc.status()).code;

View file

@ -18,7 +18,7 @@ const test: { [key: string]: Function } = {
},
runRequired(): void {
run({
args: [
cmd: [
"python",
"-c",
"import sys; sys.stdout.write('hello'); sys.stdout.flush()"

View file

@ -12,7 +12,7 @@ const { test, build } = Deno;
async function startServer(): Promise<Deno.Process> {
const server = Deno.run({
args: [
cmd: [
Deno.execPath(),
"--allow-net",
"--allow-read",

View file

@ -14,7 +14,7 @@ Deno.test(function t2(): void {
/** A more complicated test that runs a subprocess. */
Deno.test(async function catSmoke(): Promise<void> {
const p = run({
args: [
cmd: [
Deno.execPath(),
"run",
"--allow-read",

View file

@ -4,7 +4,7 @@ import { assertStrictEq } from "../../testing/asserts.ts";
Deno.test("[examples/cat] print multiple files", async () => {
const decoder = new TextDecoder();
const process = Deno.run({
args: [
cmd: [
Deno.execPath(),
"--allow-read",
"cat.ts",

View file

@ -77,7 +77,7 @@ Deno.test("[examples/catj] read from stdin", async () => {
function catj(...files: string[]): Deno.Process {
return Deno.run({
args: [Deno.execPath(), "--allow-read", "catj.ts", ...files],
cmd: [Deno.execPath(), "--allow-read", "catj.ts", ...files],
cwd: "examples",
stdin: "piped",
stdout: "piped",

View file

@ -4,7 +4,7 @@ import { assertStrictEq } from "../../testing/asserts.ts";
Deno.test("[examples/colors] print a colored text", async () => {
const decoder = new TextDecoder();
const process = Deno.run({
args: [Deno.execPath(), "colors.ts"],
cmd: [Deno.execPath(), "colors.ts"],
cwd: "examples",
stdout: "piped"
});

View file

@ -19,7 +19,7 @@ Deno.test({
const decoder = new TextDecoder();
const process = Deno.run({
args: [
cmd: [
Deno.execPath(),
"--allow-net",
"curl.ts",

View file

@ -8,7 +8,7 @@ Deno.test("[examples/echo_server]", async () => {
const encoder = new TextEncoder();
const decoder = new TextDecoder();
const process = Deno.run({
args: [Deno.execPath(), "--allow-net", "echo_server.ts", `${port}`],
cmd: [Deno.execPath(), "--allow-net", "echo_server.ts", `${port}`],
cwd: "examples",
stdout: "piped"
});

View file

@ -4,7 +4,7 @@ import { assertStrictEq } from "../../testing/asserts.ts";
Deno.test("[examples/welcome] print a welcome message", async () => {
const decoder = new TextDecoder();
const process = Deno.run({
args: [Deno.execPath(), "welcome.ts"],
cmd: [Deno.execPath(), "welcome.ts"],
cwd: "examples",
stdout: "piped"
});

View file

@ -29,7 +29,7 @@ Deno.test({
name: "xevalCliReplvar",
fn: async function(): Promise<void> {
const p = run({
args: [execPath(), xevalPath, "--replvar=abc", "console.log(abc)"],
cmd: [execPath(), xevalPath, "--replvar=abc", "console.log(abc)"],
stdin: "piped",
stdout: "piped",
stderr: "null"
@ -45,7 +45,7 @@ Deno.test({
Deno.test(async function xevalCliSyntaxError(): Promise<void> {
const p = run({
args: [execPath(), xevalPath, "("],
cmd: [execPath(), xevalPath, "("],
stdin: "null",
stdout: "piped",
stderr: "piped"

View file

@ -221,7 +221,7 @@ for (const s of scenes) {
const p = Deno.run({
stdout: "piped",
cwd: testdataDir,
args: args
cmd: args
});
assert(p.stdout);

View file

@ -124,7 +124,7 @@ for (const s of scenes) {
const p = Deno.run({
stdout: "piped",
cwd: testdataDir,
args: args
cmd: args
});
const output = await p.output();

View file

@ -120,7 +120,7 @@ Deno.test(async function expandGlobIncludeDirs(): Promise<void> {
Deno.test(async function expandGlobPermError(): Promise<void> {
const exampleUrl = new URL("testdata/expand_wildcard.js", import.meta.url);
const p = run({
args: [execPath(), exampleUrl.toString()],
cmd: [execPath(), exampleUrl.toString()],
stdin: "null",
stdout: "piped",
stderr: "piped"

View file

@ -9,7 +9,7 @@ let fileServer: Deno.Process;
const port = randomPort();
async function startFileServer(): Promise<void> {
fileServer = Deno.run({
args: [
cmd: [
Deno.execPath(),
"run",
"--allow-read",
@ -109,7 +109,7 @@ test(async function serveWithUnorthodoxFilename(): Promise<void> {
test(async function servePermissionDenied(): Promise<void> {
const _port = randomPort();
const deniedServer = Deno.run({
args: [
cmd: [
Deno.execPath(),
"run",
"--allow-net",
@ -143,7 +143,7 @@ test(async function servePermissionDenied(): Promise<void> {
test(async function printHelp(): Promise<void> {
const helpProcess = Deno.run({
args: [Deno.execPath(), "run", "http/file_server.ts", "--help"],
cmd: [Deno.execPath(), "run", "http/file_server.ts", "--help"],
stdout: "piped"
});
assert(helpProcess.stdout != null);

View file

@ -8,7 +8,7 @@ const { connect, run, test } = Deno;
let server: Deno.Process;
async function startServer(): Promise<void> {
server = run({
args: [
cmd: [
Deno.execPath(),
"run",
"-A",

View file

@ -358,7 +358,7 @@ test({
// Runs a simple server as another process
const port = randomPort();
const p = Deno.run({
args: [
cmd: [
Deno.execPath(),
"--allow-net",
"http/testdata/simple_server.ts",
@ -405,7 +405,7 @@ test({
const port = randomPort();
// Runs a simple server as another process
const p = Deno.run({
args: [
cmd: [
Deno.execPath(),
"--allow-net",
"--allow-read",

View file

@ -366,7 +366,7 @@ Example:
```ts
// create subprocess
const p = Deno.run({
args: ["echo", "hello"]
cmd: ["echo", "hello"]
});
// await its completion
@ -393,7 +393,7 @@ you can use `"piped"` option.
const fileNames = Deno.args;
const p = Deno.run({
args: [
cmd: [
"deno",
"run",
"--allow-read",