bash-fool
v1.1.1
Published
run a sequence of bash commands as specified by a json
Downloads
28
Readme
run a sequence of bash commands as specified by a json
Why
Frequently you need to have a cli execute several commands. The tools execa and listr make this easy, but why go to the trouble of repeating the same boilerplate each time?
What
A function that generates a listr for execution of a set of bash commands using execa. You just pass in an array of commands and a listr is generated for it. You can also have:
- targetDir a string indicating the directory that you can use in commands. Anywhere that you use a
$codeDir
placeholder, it will be dynamically replaced bytargetDir
. - session an object that lets you dynamically replace other strings in your commands. You must insert a key
keyName
intosession
, and then you can use it by placing into a command specification that string__session.keyName__
. For instance,__session.lastName__
could be used in a command, andsession
could be `{lastName: 'jones'}.
Usage
First, install the package:
npm i bash-fool
Here is a sample usage:
const bashFool = require('bash-fool')
const commands = [
{
'title': 'echo a string',
'file': 'echo',
'arguments': [
'this is echoed: __session:echoedString',
],
},
{
title: 'more nothing',
file: 'echo',
arguments: [
'second echoed function',
],
},
]
const echoedString = 'foobar'
const session = { echoedString }
const targetDir = 'nonexistent'
(async () => {
let listr = await bashFool(commands, targetDir, session)
await listr.run()
// will echo: `this is echoed: foobar`
// and then: `second echoed function`
})()