Git Product home page Git Product logo

yargs-promise-handler's Introduction

yargs-promise-handler

NPM version Downloads Build Status Coverage Status Dependency status Dev Dependency status Greenkeeper badge

Adds support for promises to yargs handlers and allows them to be composable.

NOTE: This module is deprecated because yargs now support async commands!

Installation

$ npm install yargs-promise-handler --save

Why?

yargs does not support command handlers that return promises. Users must handle promises and call process.exit() manually.

This packages does exactly that under the hood and exposes the original promise under handler.promise() to allow handlers to be composable.

Usage

// commands/random
export const command = 'random';
export const describe = 'A command that either fails or succeeds based on randomness';

export const builder = (argv) => argv;
export const handler = promiseHandler((argv) => Math.random() > 0.5 ?
    Promise.resolve() :
    Promise.reject(Object.assign(new Error('Oh noes'), { exitCode: 5 })));

The code above will either exit with code 0 or 5 if the promise either fulfills or rejects respectively.
Note that if the error.exitCode is undefined, it will default to 1.

The second argument of promiseHandler accepts an options object:

  • logError: Call console.error(err) before exiting if the promise fails, defaults to true

Tests

$ npm test
$ npm test -- --watch during development

License

MIT License

yargs-promise-handler's People

Contributors

greenkeeper[bot] avatar satazor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yargs-promise-handler's Issues

An in-range update of lint-staged is breaking the build 🚨

Version 4.2.0 of lint-staged just got published.

Branch Build failing 🚨
Dependency lint-staged
Current Version 4.1.3
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As lint-staged is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Release Notes v4.2.0

4.2.0 (2017-09-15)

Features

  • Print friendlier error if config is missing (#281) (30fa594)
Commits

The new version differs by 8 commits.

  • 30fa594 feat: Print friendlier error if config is missing (#281)
  • 0077644 chore: Cleanup package.json (#250)
  • 7abe23f ci: Disable email notifications from Travis CI
  • c9d0849 docs: Use emojis in the Readme
  • e976a3c docs: Add screenshot with the animated gif (#276)
  • 92e586b docs: Reformat code blocks
  • 9b0282a docs: Use diff formatting for code
  • 33da9b3 ci: Whitelist build branches to avoid duplicate builds (#269)

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.