Class reference
Shell

Shell Command Opts

import { ShellCommandOpts } from "@vaibhavvenkat/aacod";
 
const opts: ShellCommandOpts  = {
    command: "ls",
    silent: false,
    chdir: `${process.env.HOME || "/"}`, // OPTIONAL
    // NOTE: chdir needs to be an absolute path (e.g, no ~)
}

Properties

NameTypeRequiredDescription
commandstringYesThe command to run
silentbooleanYesWhether to print the command output to stdout
chdirstringNoThe directory to run the command in (MUST BE AN ABSOLUTE PATH)
executablestringNoThe executable to run the command with (e.g, /bin/bash)

SafeRunResponse

import { ShellCommand, ShellCommandOpts, SafeRunResponse } from "@vaibhavvenkat/aacod";
 
async function main() {
    const opts: ShellCommandOpts  = {
        command: "ls",
        silent: false,
        chdir: `${process.env.HOME || "/"}`
    }
    const cmd = new ShellCommand(opts);
    const res: SafeRunResponse = await cmd.safeRun();
}
main()

Properties

NameTypeDescription
successbooleanWhether the command ran successfully
errorShellCommandError | nullThe error that was thrown if the command errored

ShellCommandError

Same properties as error, just with some internal properties for development

Shell Command

import { ShellCommand, ShellCommandOpts } from "@vaibhavvenkat/aacod";
 
async function main() {
    const opts: ShellCommandOpts  = {
        command: "ls",
        silent: false,
        chdir: `${process.env.HOME || "/"}`
    }
    const cmd = new ShellCommand(opts);
    const res = await cmd.safeRun();
    if (res.success) {
        console.log("Success!");
    } else if (res.error) {
        console.error(`Error! ${res.error.message}`);
    }
}
main()

Takes in a ShellCommandOpts object

Methods

NameReturned TypeDescription
safeRun()Promise<SafeRunResponse>Runs run(), but instead of throwing an error it returns a SafeRunResponse
run()Promise<void>Runs the command, prints the stdout if opts.silent is true. If the command errors it throws a ShellCommandError
Last updated on