New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

shell-command-builder

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shell-command-builder

Construct and execute shell commands

latest
Source
npmnpm
Version
0.2.1
Version published
Maintainers
1
Created
Source

shell-command-builder

Construct and execute shell commands

Install:

yarn add shell-command-builder
# OR
npm install shell-command-builder

Require or import the module:

const { CommandBuilder, run, interactive } = require("shell-command-builder");
// OR 
import { CommandBuilder, run, interactive } from "shell-command-builder";

Build shell commands with arguments:

const command = new CommandBuilder("foo", [
  "file.text",
  "--flag-1",
  "--flag-2",
  "-a",
]); //=> foo file.text --flag-1 --flag-2 -a

Convert command to a string:

String(command);
command.toString();
`command = ${command}`;

Use fluent API to add args/flags after initial command is created:

const command = new CommandBuilder("foo");
command.arg("--hello");
console.log(command); //=> foo --hello

Pass in a truthy/falsy condition to optionally add args/flags:

const command = new CommandBuilder("foo");
const options = {
  watch: true,
  quiet: false,
};
command.arg("--watch", options.watch); // added
command.arg("--quiet", options.quiet); // not added
console.log(command); //=> foo --watch

Run commands:

const command = new CommandBuilder("echo 'hello, world!'");
const { stdout } = await command.run(); //=> hello, world!
// OR
const { stdout } = await run(command); //=> hello, world!
// OR
await command.interactive(); //=[shell]=> hello, world!
// OR
await interactive(command); //=[shell]=> hello, world!

FAQs

Package last updated on 18 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts