Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

exec-promise

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

exec-promise

Testable CLIs with promises

  • 0.7.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

exec-promise

Build Status Dependency Status devDependency Status

Testable CLIs with promises

Features

  • executes the passed function with command line arguments
  • wait for completion (sync or promise) before stopping Node
  • in case of exception: pretty print the value and exit with exit code 1
  • in case of returned value (not undefined):
    • if valid exit code (integer), exit Node with it
    • otherwise, pretty print it

Introduction

TODO

  • executables should be testable
  • the execution flow should be predictable and followable (promises)

Install

Download manually or with package-manager.

npm
npm install --save exec-promise

This library requires promises support, for Node versions prior to 0.12 see this page to enable them.

Example

ES 2015

import execPromise from 'exec-promise'

// - The command line arguments are passed as first parameter.
// - Node will exists as soon as the promise is settled (with a code
//   different than 0 in case of an error).
// - All errors are catched and properly displayed with a stack
//   trace.
// - Any returned value (i.e. not undefined) will be prettily
//   displayed
execPromise(async args => {
  // ... do what you want here!
})

ES5

module.exports = function (args) {
  if (args.indexOf('-h') !== -1) {
    return 'Usage: my-program [-h | -v]'
  }

  if (args.indexOf('-v') !== -1) {
    var pkg = require('./package')
    return 'MyProgram version ' + pkg.version
  }

  var server = require('http').createServer()
  server.listen(80)

  // The program will run until the server closes or encounters an
  // error.
  return require('event-to-promise')(server, 'close')
}

// Executes the exported function if this module has been called
// directly.
if (!module.parent) {
  require('exec-promise')(module.exports)
}

Contributing

Contributions are very welcome, either on the documentation or on the code.

You may:

  • report any issue you've encountered;
  • fork and create a pull request.

License

ISC © Julien Fontanet

Keywords

FAQs

Package last updated on 09 May 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc