{"name":"@iarna/cli","version":"2.0.1","description":"Some simple CLI scaffolding for promise returning applications.","main":"app.js","scripts":{"test":"tap --100 test/scenarios.js"},"keywords":[],"author":{"name":"Rebecca Turner","email":"me@re-becca.org","url":"http://re-becca.org/"},"license":"ISC","dependencies":{"signal-exit":"^3.0.2"},"files":["app.js"],"devDependencies":{"@perl/qr":"^1.2.0","@perl/qx":"^1.0.2","glob":"^7.1.2","tap":"^12.0.1","update-notifier":"^2.2.0","yargs":"^8.0.2"},"repository":{"type":"git","url":"git+https://github.com/iarna/cli.git"},"bugs":{"url":"https://github.com/iarna/cli/issues"},"homepage":"https://github.com/iarna/cli#readme","gitHead":"810365aa2fd9cd09d266dacb9ad1fed15016e859","_id":"@iarna/cli@2.0.1","_npmVersion":"6.1.0","_nodeVersion":"10.4.0","_npmUser":{"name":"iarna","email":"me@re-becca.org"},"dist":{"integrity":"sha512-FMQNnzgDBFgEkP2oaMFzdVbycFTP2fdvjgpxjzmcPjpqwU1cnuuUfSV5prcQ28KDk2BX2CTP2l5TQaa6U/3M5w==","shasum":"7ba8f72119aaeec805e86a88952cc51421db2ab5","tarball":"http://registry-npm.ywwl.com/@iarna/cli/download/@iarna/cli-2.0.1.tgz","fileCount":4,"unpackedSize":9704,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbGjgZCRA9TVsSAnZWagAAbqYP/iloA54BxfOlPnl78vka\nGS3xuVYWCi5BmdmrVFgLmmQPdweqW0sZfhZk9UDA9NzUlH0DMGlU7z3xNn4D\n6HA1N7WrSYD++9etc+Am5DAsX+ZOyzBqztZDeuyxbjC7gvxKBF/1XWfhyphS\n2kafhIdV9LjLKG9TuBtZzPB/JlUl+jmyUOxUe3kcsuRTy2HrJBdg3iyYBTRy\nbYxAYVL7Yahju2H+A6PIICh2rmVlb4wgJRHca+SwegAiHEYSLI5yfPafELNa\na2y407YBeYEfSlYSun0r5frUm526hIKrb5K09WIYLEgvrxITK9YXe2L6WjQD\n5+DKUAx2K2i8jsqqNvHUYNO8DiV4kHNXHkE0LBvOIPvZ5Io5o/UF+8q75M1P\nkpYpPjGwDjOHmdryfbp0muRdd5U1oL/z19amQUfNgSOOZ3BPfFeOWNJ29lav\nYobiqN7Vh3zcj8QrmKZN0olq/ngvNH1yeJOidlFHHR4MJXkJbY3srikCriqk\n0DxGh7/RwxFa6OxiHq36a2bTq3jFJ0Ej7DDMH6wznzhSFQFTuKI/yle9ZAoP\nS9rbd5onivNrKLav6j/dR5ikt6Wte/IyBuzb+IOynC8kYXhEd0/g3RZUGgd1\nOp6RyOHqLzWULMOeJftD5xTnlD56D3ABmg3hVvxHI7ZhOpCVqsv9ra7vF822\nmyTe\r\n=Lr42\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC/dN2H3KjwbKmLzxpi5W5gbVqzbIR8gO2ssLcRC6GGgQIhAKLOa/bHLMZ66CwlLBv3A2UbE0fewgpHpCuFZIFkkPqK"}],"size":3954,"noattachment":false,"key":"/@iarna/cli/-/@iarna/cli-2.0.1.tgz"},"maintainers":[{"name":"iarna","email":"me@re-becca.org"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cli_2.0.1_1528444953114_0.1953496965815289"},"_hasShrinkwrap":false,"readme":"# @iarna/cli\n\nSome simple CLI scaffolding for promise returning applications.\n\n[![Coverage Status](https://coveralls.io/repos/github/iarna/cli/badge.svg?branch=latest)](https://coveralls.io/github/iarna/cli?branch=latest)\n\n## EXAMPLE\n\n`example.js`\n```js\nrequire('@iarna/cli')(main)\n\nconst util = require('util');\nconst sleep = util.promisify(setTimeout);\n\n// opts will only contain the _ var, for compatibility with yargs\nasync function main (opts, arg1, arg2, arg3) {\n  console.log('Got:', arg1, arg2, arg3)\n  await sleep(40)\n}\n```\n\n## WHAT YOU GET\n\n* Automatic glob parsing on Windows so that your passing `*.foo` works the\n  same on Mac/Linux/Windows.\n* Error detetion and handling:\n  * _exit without resolving warnings_ - If your program finishes without\n    resolving its promises (like if it crashes hard or you process.exit, or\n    you just don't resolve the promise) then we warn about that.\n  * If your entry point function rejects then that's reported with a stack\n    trace (if the rejected value has `.stack`) else with the rejected value\n    and your process will exit with an error code.\n* Optional `yargs` support.  If `yargs` is requirable then it will be used. \n  The wrapper around the main function returns a yargs object, so you can\n  configure it as usual.  The `argv` object is passed in as the first\n  argument of your entry point function.  The rest of your positional\n  arguments are passed in as the remaining function arguments.\n* Optional `update-notifier` support.  If `update-notifier` is requirable\n  then it will be used.  A default update notifier is setup for your app so\n  users will learn about new versions when you publish them.  Your app needs\n  to have a name, version and bin entry in its `package.json`.  (The bin\n  entry needs to have the script using `@iarna/cli` in it for the update\n  notifier to trigger.)\n\n## With Yargs\n\nIf you have yargs installed as a dependency you can customize it further by\nchaining off the require in the usual yargsish way.\n\n`example.js`\n```js\nrequire('@iarna/cli')(main)\n  .boolean('silent')\n  .boolean('exit')\n  .boolean('error')\n  .boolean('reject')\n  .boolean('code50')\n  .version()\n  .help()\n\nconst util = require('util');\nconst sleep = util.promisify(setTimeout);\n\nfunction main (opts, arg1, arg2, arg3) {\n  if (!opts.silent) console.error('Starting up!')\n  console.log('Got:', arg1, arg2, arg3)\n  if (opts.exit) process.exit()\n  if (opts.error) throw new Error('throw')\n  if (opts.reject) return Promise.reject(new Error('reject'))\n  if (opts.code50) return Promise.reject(50)\n  return sleep(10000)\n}\n\n// alternatively use:\n// function main (opts, ...args) {\n```\n\n```console\n$ node example hello there world\nStarting up!\nGot: hello there world\n$ node example hello there world\nStarting up!\nGot: hello there world\n^C\nAbnormal exit: SIGINT\n$ node example --silent hello there world\nGot: hello there world\n$ node example --silent hello there world --exit\nGot: hello there world\nAbnormal exit: Promises not resolved\n$ node example --silent hello there world --error\nGot: hello there world\nError: throw\n    at main (/Users/rebecca/code/cli/example.js:11:25)\n    at Immediate.setImmediate (/Users/rebecca/code/cli/app.js:38:32)\n    at runCallback (timers.js:800:20)\n    at tryOnImmediate (timers.js:762:5)\n    at processImmediate [as _immediateCallback] (timers.js:733:5)\n$ node example --silent hello there world --reject\nGot: hello there world\nError: reject\n    at main (/Users/rebecca/code/cli/example.js:12:42)\n    at Immediate.setImmediate [as _onImmediate] (/Users/rebecca/code/cli/app.js:38:32)\n    at runCallback (timers.js:800:20)\n    at tryOnImmediate (timers.js:762:5)\n    at processImmediate [as _immediateCallback] (timers.js:733:5)\n$ node example --silent hello there world --code50\nGot: hello there world\n$ echo $?\n50\n```\n\n## WHAT ITS NOT\n\nA full framework for writing cli apps.  You'll likely outgrow the error\nhandling pretty fast if this is anything beyond a little one off.  This\nmostly exists to scratch my own itch.  I kept on writing this code and I\nwanted to stop.  =D\n\nIt's designed to be only be as heavy as it needs to be.  It only has one\ndirect dependency, but it can provide enhanced functionality if you depend on\n`yargs` or `update-notifier`.\n\n## USAGE\n\n### require('@iarna/cli')(entryPointFunction) → [yargs]\n\nThe module itself exports a function that you need to call with the name of\nyour main function.  Your main function is like `main` in C, it's the entry\npoint for your program.  It needs to return a promise that resolves when\nyour program completes.\n\nThe return value from the call is, if you have `yargs` installed, a `yargs`\nobject you can use to configure what options your script takes. If you\ndon't have yargs installed then it's a proxy that throws if you try to do\nanything with it.\n\nYour entry point function can be named anything, but it needs to return a\npromise and it takes arguments like this:\n\n`main(opts, arg1, arg2, …, argn) → Promise`\n\nIf you have `yargs` installed then the `opts` argument is `yargs.argv`\nand the additional arguments are from `argv._`, so `arg1 === argv._[0]`,\n`arg2 === argv._[1]` and so on.\n\nIf you don't have `yargs` installed then `opts` argument is an object with\nan `_` property containing all arguments, for compatibility with the `yargs`\nmode.  As with that mode `arg1 === argv._[0]`, `arg2 === argv._[1]` and so\non.\n","publish_time":1528444953197,"_cnpm_publish_time":1528444953197,"dist-tags":{"latest":"2.2.0"}}