cmd-template
v0.0.1
Published
an intuitive shell utility via template literal
Downloads
2
Readme
cmd-template
introduction
an intuitive shell utility using template literal.
installation
npm i cmd-template
usage
import {sh, CmdTemplate} from 'cmd-template'
const opt1 = {
follow: true,
H: [
"User-Agent: google-chrome",
"x-api-key: xyz"
]
};
const url = "https://myserver/hello";
CmdTemplate`curl ${opt1} ${url}`;
// => String(curl --follow -H "User-Agent: google-chrome" -H "x-api-key: xyz" "https://myserver/hello")
// all the argument is automatically stringify.
// similarly the utility function sh
async function task () {
const [stdout, stderr] = await sh`curl ${opt1} ${url}`;
// use node's exec from spawn_process
// by default runs with {shell: process.env['SHELL'], print: true}
// if more fine control need, please use spawn
// "print" is a custom property for piping the exec's stdout, stderr to process's stdio
// to override option
await sh.withOptions({print: false})`echo hello world`
// => nothing will be printed
}