Skip to content

reggi/command-plus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@reggi/command-plus

npm i @reggi/command-plus --save

Why

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 of true will return with an exit code of 0
  • A returned boolean of false will return with an exit code of 1
  • A returned string will be written to stdout with an exit code 0
  • Anything else returned will be json stringified with an exit code 0
  • Any thrown error will be caught, the message will be written to stderr with an exit code of 1

Examples

boolean false

import commandPlus from '@reggi/command-plus'

export default commandPlus(module, async () => {
  return false // return with an exit code of `1`
})

boolean true

import commandPlus from '@reggi/command-plus'

export default commandPlus(module, async () => {
  return true // return with an exit code of `0`
})

strings

import commandPlus from '@reggi/command-plus'

export default commandPlus(module, async () => {
  return 'Hello World' // will be written to `stdout` with an exit code `0` 
})

object

import commandPlus from '@reggi/command-plus'

export default commandPlus(module, async () => {
  return {greeting: 'Hi'} // will be `json` stringified with an exit code `0`
})

thrown Error

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`
})

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published