npm i @reggi/command-plus --save
This project is a wrapper around the @reggi/command
module that allows functions that return "normal" values to be handled in unix terminal in a consistent way.
- A returned
boolean
oftrue
will return with an exit code of0
- A returned
boolean
offalse
will return with an exit code of1
- A returned
string
will be written tostdout
with an exit code0
- Anything else returned will be
json
stringified with an exit code0
- Any thrown error will be caught, the message will be written to
stderr
with an exit code of1
import commandPlus from '@reggi/command-plus'
export default commandPlus(module, async () => {
return false // return with an exit code of `1`
})
import commandPlus from '@reggi/command-plus'
export default commandPlus(module, async () => {
return true // return with an exit code of `0`
})
import commandPlus from '@reggi/command-plus'
export default commandPlus(module, async () => {
return 'Hello World' // will be written to `stdout` with an exit code `0`
})
import commandPlus from '@reggi/command-plus'
export default commandPlus(module, async () => {
return {greeting: 'Hi'} // will be `json` stringified with an exit code `0`
})
import commandPlus from '@reggi/command-plus'
export default commandPlus(module, async () => {
throw new Error('Not good') // message will be written to `stderr` with an exit code of `1`
})