# exec-promise

> Testable CLIs with promises

Latest version **0.7.0** (published 2017-05-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install exec-promise
pnpm add exec-promise
yarn add exec-promise
bun add exec-promise
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.7.0 |
| Published | 2017-05-09 |
| First published | 2014-04-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Julien Fontanet |
| Maintainers | julien-f, marsaud |
| Keywords | cli, executable, promise |

## Links

- npm: https://www.npmjs.com/package/exec-promise
- Repository: https://github.com/JsCommunity/exec-promise
- Issues: https://github.com/JsCommunity/exec-promise/issues
- npm.io page: https://npm.io/package/exec-promise

## Dependencies (1)

- [log-symbols](https://npm.io/package/log-symbols.md) ^1.0.2

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 0.7.0 (latest) — 2017-05-09
- 0.6.1 — 2016-02-10
- 0.5.1 — 2014-10-08
- 0.5.0 — 2014-09-08
- 0.4.0 — 2014-08-02
- 0.3.0 — 2014-06-08
- 0.2.4 — 2014-05-22
- 0.2.3 — 2014-05-22
- 0.2.2 — 2014-05-22
- 0.2.1 — 2014-04-16
- 0.2.0 — 2014-04-15
- 0.1.0 — 2014-04-15

## README

# exec-promise

[![Build Status](https://img.shields.io/travis/JsCommunity/exec-promise/master.svg)](http://travis-ci.org/JsCommunity/exec-promise)
[![Dependency Status](https://david-dm.org/JsCommunity/exec-promise/status.svg?theme=shields.io)](https://david-dm.org/JsCommunity/exec-promise)
[![devDependency Status](https://david-dm.org/JsCommunity/exec-promise/dev-status.svg?theme=shields.io)](https://david-dm.org/JsCommunity/exec-promise#info=devDependencies)

> 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](https://github.com/JsCommunity/exec-promise/releases) or with package-manager.

#### [npm](https://npmjs.org/package/exec-promise)

```
npm install --save exec-promise
```

This library requires promises support, for Node versions prior to 0.12 [see
this page](https://github.com/JsCommunity/js-promise-toolbox#usage) to
enable them.

## Example

### ES 2015

```javascript
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

```javascript
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](https://github.com/JsCommunity/human-format/issues)
  you've encountered;
- fork and create a pull request.

## License

ISC © [Julien Fontanet](http://julien.isonoe.net)

---
_Source: https://npm.io/package/exec-promise · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
