Skip to content

Commit

Permalink
BREAKING CHANGE Rename Deno.run's args to cmd (denoland#4444)
Browse files Browse the repository at this point in the history
This is to avoid confusion with Deno.args which does not include the 
executable to be run.
  • Loading branch information
akshatagarwl authored Mar 21, 2020
1 parent b191c91 commit b8a5c29
Show file tree
Hide file tree
Showing 27 changed files with 60 additions and 60 deletions.
4 changes: 2 additions & 2 deletions cli/js/lib.deno.ns.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions cli/js/ops/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
6 changes: 3 additions & 3 deletions cli/js/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -108,15 +108,15 @@ interface RunResponse {
stderrRid: number | null;
}
export function run({
args,
cmd,
cwd = undefined,
env = {},
stdout = "inherit",
stderr = "inherit",
stdin = "inherit"
}: RunOptions): Process {
const res = runOp({
args: args.map(String),
cmd: cmd.map(String),
cwd,
env: Object.entries(env),
stdin: isRid(stdin) ? "" : stdin,
Expand Down
4 changes: 2 additions & 2 deletions cli/js/tests/chown_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion cli/js/tests/os_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
});
Expand Down
34 changes: 17 additions & 17 deletions cli/js/tests/process_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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"
});
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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.
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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');"
Expand Down Expand Up @@ -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
});

Expand All @@ -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', ''))"
Expand All @@ -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')"
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions cli/js/tests/unit_test_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function spawnWorkerRunner(
})
.join(",");

const args = [
const cmd = [
Deno.execPath(),
"run",
"-A",
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cli/ops/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions cli/tests/045_proxy_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: `https://${addr}`
Expand All @@ -38,7 +38,7 @@ async function testFetch(): Promise<void> {

async function testModuleDownload(): Promise<void> {
const http = Deno.run({
args: [
cmd: [
Deno.execPath(),
"--reload",
"fetch",
Expand Down
6 changes: 3 additions & 3 deletions cli/tests/lock_write_fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ try {
const fetchProc = Deno.run({
stdout: "null",
stderr: "null",
args: [
cmd: [
Deno.execPath(),
"fetch",
"--reload",
Expand All @@ -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",
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/permission_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()"
Expand Down
2 changes: 1 addition & 1 deletion std/examples/chat/server_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion std/examples/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion std/examples/tests/cat_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion std/examples/tests/catj_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion std/examples/tests/colors_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
});
Expand Down
2 changes: 1 addition & 1 deletion std/examples/tests/curl_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Deno.test({

const decoder = new TextDecoder();
const process = Deno.run({
args: [
cmd: [
Deno.execPath(),
"--allow-net",
"curl.ts",
Expand Down
2 changes: 1 addition & 1 deletion std/examples/tests/echo_server_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
});
Expand Down
Loading

0 comments on commit b8a5c29

Please sign in to comment.