{"_id":"yargs-promise","_rev":"489636","name":"yargs-promise","description":"Use the headless yargs parser with promises","dist-tags":{"latest":"1.1.0"},"maintainers":[{"name":"eddywashere","email":"edward.d.hernandez@gmail.com"}],"time":{"modified":"2024-06-24T20:39:21.000Z","created":"2017-04-25T20:43:45.687Z","1.1.0":"2017-04-30T21:28:50.210Z","1.0.0":"2017-04-25T20:43:45.687Z"},"users":{},"author":{"name":"Eddy Hernandez","email":"edward.d.hernandez@gmail.com","url":"http://eddywashere.com"},"repository":{"type":"git","url":"git+ssh://git@github.com/eddywashere/yargs-promise.git"},"versions":{"1.1.0":{"name":"yargs-promise","version":"1.1.0","main":"index.js","description":"Use the headless yargs parser with promises","author":{"name":"Eddy Hernandez","email":"edward.d.hernandez@gmail.com","url":"http://eddywashere.com"},"license":"MIT","repository":{"type":"git","url":"git+ssh://git@github.com/eddywashere/yargs-promise.git"},"scripts":{"test":"jest"},"jest":{"testEnvironment":"node"},"devDependencies":{"jest":"^19.0.2","yargs":"^7.1.0"},"keywords":["yargs","parser","yargs-parser","promise","promises"],"gitHead":"47614bcd58732eba731ead48fef0d4d02a7d3d2f","bugs":{"url":"https://github.com/eddywashere/yargs-promise/issues"},"homepage":"https://github.com/eddywashere/yargs-promise#readme","_id":"yargs-promise@1.1.0","_shasum":"97ebb5198df734bb3b11745133ae5b501b16ab1f","_from":".","_npmVersion":"3.10.10","_nodeVersion":"6.9.5","_npmUser":{"name":"eddywashere","email":"edward.d.hernandez@gmail.com"},"dist":{"shasum":"97ebb5198df734bb3b11745133ae5b501b16ab1f","tarball":"http://registry-npm.ywwl.com/yargs-promise/download/yargs-promise-1.1.0.tgz","integrity":"sha512-nAw/GY9hhH7Y9uGW89sFLpiv9PKZUWIT5IyHdjkbrPpCDTRHn2T1b5SFhgEzut5ghki0HXTLk4HHYRaKlL26Iw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDSvgAX1eruNtsSoY+XcEh0tOLtlJsIUnG8ScDff4hnNAIhALsSGB12ml+HiDLSNbVpLFj+Dws4IEUSufD8fLUl/SrN"}],"size":23564,"noattachment":false,"key":"/yargs-promise/-/yargs-promise-1.1.0.tgz"},"maintainers":[{"name":"eddywashere","email":"edward.d.hernandez@gmail.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/yargs-promise-1.1.0.tgz_1493587728268_0.6491867683362216"},"directories":{},"publish_time":1493587730210,"_cnpm_publish_time":1493587730210},"1.0.0":{"name":"yargs-promise","version":"1.0.0","main":"index.js","description":"Use the headless yargs parser with promises","author":{"name":"Eddy Hernandez","email":"edward.d.hernandez@gmail.com","url":"http://eddywashere.com"},"license":"MIT","repository":{"type":"git","url":"git+ssh://git@github.com/eddywashere/yargs-promise.git"},"scripts":{"test":"jest"},"jest":{"testEnvironment":"node"},"devDependencies":{"jest":"^19.0.2","yargs":"^7.1.0"},"keywords":["yargs","parser","yargs-parser","promise","promises"],"gitHead":"11cbd66e7219bb349d619f0c6e522aa7da9feb00","bugs":{"url":"https://github.com/eddywashere/yargs-promise/issues"},"homepage":"https://github.com/eddywashere/yargs-promise#readme","_id":"yargs-promise@1.0.0","_shasum":"0bc8c9b8835fa365d127b7a6c8ff452afc095ff8","_from":".","_npmVersion":"3.10.10","_nodeVersion":"6.9.5","_npmUser":{"name":"eddywashere","email":"edward.d.hernandez@gmail.com"},"dist":{"shasum":"0bc8c9b8835fa365d127b7a6c8ff452afc095ff8","tarball":"http://registry-npm.ywwl.com/yargs-promise/download/yargs-promise-1.0.0.tgz","integrity":"sha512-t2CSmG+gx5jCGp8wM52NeICVv6CcZXfvftZJk00vZgmyLqv02Kb5wCRNAZrUEkAVYUd/JUV/SrH5IZbUM/v/1g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDDUguxExL4WY0A2HLINC5Sz4KG9mktozNuR+WO/ek42gIgeXs1m2Lrjb8p+kLp8J9ZtFcCMp5WCo/XrC2avCoVs5U="}],"size":23485,"noattachment":false,"key":"/yargs-promise/-/yargs-promise-1.0.0.tgz"},"maintainers":[{"name":"eddywashere","email":"edward.d.hernandez@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/yargs-promise-1.0.0.tgz_1493153023819_0.19708932586945593"},"directories":{},"publish_time":1493153025687,"_cnpm_publish_time":1493153025687}},"readme":"# yargs-promise\n\nUse the headless yargs parser with promises!\n\n## Install\n\nnpm\n\n```\nnpm install --save yargs-promise\n```\n\nyarn\n\n```\nyarn add --save yargs-promise\n```\n\n## Usage\n\nInstead of using a callback with  [yargs.parse](http://yargs.js.org/docs/#methods-parseargs-context-parsecallback), use a promise chain: `parser.parse(text).then().catch()`.\n\nExamples:\n\n```js\nconst yargs = require('yargs');\nconst YargsPromise = require('yargs-promise');\n\n// create the customized yargs parser\nconst parser = new YargsPromise(yargs);\n\n// setup command & command handler\nparser\n  .command('hello <name>', 'hello world parser' , ()=>{}, (argv) => {\n\n    // resolve a promise or other value\n    argv.resolve(doSomething);\n\n    // reject stuff\n    argv.reject(yourErrorData);\n\n    // or do nothing and reject/resolve will be handled internally\n    console.log('testing argv');\n  })\n  .help();\n\n// parse text input and use the returned promise\nparser.parse('hello world')\n  .then(({data, argv}) => {\n    // data is what your code resolved or what an internal command resolved\n  })\n  .catch(({error, argv}) => {\n    // `error` is what your code rejected or an internal error from yargs\n  });\n\n```\n\nCustomizing context example\n\n```js\nconst yargs = require('yargs');\nconst YargsPromise = require('yargs-promise');\n\nconst parser = new YargsPromise(\n  yargs,\n  // customize context\n  {\n    customContextMethod: () => {},\n    foo: 'bar'\n  }\n);\n\nparser\n  .command('hello <name>', 'hello world parser' , ()=>{}, (argv) => {\n    // argv now contains\n    argv.customContextMethod();\n    console.log(argv.foo);\n  })\n  .help();\n```\n\nNeed access to yargs object? Work with the direct `yargs` object prior to passing it into the yargs-promise constructor. For convenience, it is also available at `parser.yargs`. \n\n### How it works\n\nThis library does three things:\n\n- wraps the yargs.parse in a new Promise\n  - no more callbacks\n- attaches that Promises `resolve` & `reject` methods on the context passed to yargs.parse\n  - this enables you to call `argv.resolve` or `argv.reject` in command handler function\n- handles default behavior\n  - from Error validation\n  - output from internal commands like `.help()`\n  - unhandled output from custom handler\n\nCheckout the source code or tests for more information.\n\n### Why\n\nBuilding chatbots requires parsing and handling text input. This wraps up the most common needs I've come across for handling errors, simple commands, and commands with handlers.\n","_attachments":{},"homepage":"https://github.com/eddywashere/yargs-promise#readme","bugs":{"url":"https://github.com/eddywashere/yargs-promise/issues"},"license":"MIT"}