import { CommandBuilder } from "https://deno.land/x/dax@0.22.0/mod.ts";
Underlying builder API for executing commands.
This is what $
uses to execute commands. Using this provides
a way to provide a raw text command or an array of arguments.
Command builders are immutable where each method call creates a new command builder.
const builder = new CommandBuilder()
.cwd("./src")
.command("echo $MY_VAR");
// outputs 5
console.log(await builder.env("MY_VAR", "5").text());
// outputs 6
console.log(await builder.env("MY_VAR", "6").text());
Methods
Sets stdout as quiet, spawns the command, and gets stdout as a Uint8Array.
Shorthand for:
const data = (await $`command`.quiet("stdout")).stdoutBytes;
Sets multiple environment variables to use at the same time via an object literal.
Sets a single environment variable to use.
Exports the environment of the command to the executing process.
So for example, changing the directory in a command or exporting an environment variable will actually change the environment of the executing process.
await $`cd src && export SOME_VALUE=5`;
console.log(Deno.env.get("SOME_VALUE")); // 5
console.log(Deno.cwd()); // will be in the src directory
Sets stdout as quiet, spawns the command, and gets stdout as JSON.
Shorthand for:
const data = (await $`command`.quiet("stdout")).stdoutJson;
Prints the command text before executing the command.
For example:
const text = "example";
await $`echo ${text}`.printCommand();
Outputs:
> echo example
example
Ensures stdout and stderr are piped if they have the default behaviour or are inherited.
// ensure both stdout and stderr is not logged to the console
await $`echo 1`.quiet();
// ensure stdout is not logged to the console
await $`echo 1`.quiet("stdout");
// ensure stderr is not logged to the console
await $`echo 1`.quiet("stderr");
Mutates the command builder to change the logger used
for printCommand()
.
Explicit way to spawn a command.
This is an alias for awaiting the command builder or calling .then(...)
Sets stdout as quiet, spawns the command, and gets stdout as a string without the last newline.
Shorthand for:
const data = (await $`command`.quiet("stdout")).stdout.replace(/\r?\n$/, "");