{"name":"subcommand","version":"2.0.3","description":"create CLI tools with subcommands","main":"index.js","scripts":{"test":"standard && node test.js"},"repository":{"type":"git","url":"https://github.com/maxogden/subcommand.git"},"keywords":["minimist"],"author":{"name":"max ogden"},"license":"BSD","bugs":{"url":"https://github.com/maxogden/subcommand/issues"},"homepage":"https://github.com/maxogden/subcommand","dependencies":{"cliclopts":"^1.1.0","debug":"^2.1.3","minimist":"^1.2.0","xtend":"^4.0.0"},"devDependencies":{"standard":"^3.3.2","tape":"^4.0.0"},"readme":"# subcommand\n\nCreate CLI tools with subcommands. A minimalist CLI router based on [minimist](https://www.npmjs.com/package/minimist) and [cliclopts](https://www.npmjs.com/package/cliclopts).\n\n[![NPM](https://nodei.co/npm/subcommand.png)](https://nodei.co/npm/subcommand/)\n\n[![js-standard-style](https://raw.githubusercontent.com/feross/standard/master/badge.png)](https://github.com/feross/standard)\n\n[![Build Status](https://travis-ci.org/maxogden/subcommand.svg?branch=master)](https://travis-ci.org/maxogden/subcommand)\n\n## basic usage\n\nfirst, define your CLI API in JSON like this:\n\n```js\nvar commands = [\n  {\n    name: 'foo',\n    options: [ // cliclopts options\n      {\n        name: 'loud',\n        boolean: true,\n        default: false,\n        abbr: 'v'\n      }\n    ],\n    command: function foo (args) {\n      // called when `foo` is matched\n    }\n  },\n  {\n    name: 'bar',\n    command: function bar (args) {\n      // called when `bar` is matched\n    }\n  }\n]\n```\n\nthen pass them into `subcommand`:\n\n```js\nvar subcommand = require('subcommand')\nvar match = subcommand(config, opts)\n```\n\n`subcommand` returns a function (called `match` above) that you can use to match/route arguments to their subcommands\n\nthe return value will be `true` if a subcommand was matched, or `false` if no subcommand was matched\n\n```js\nvar matched = match(['foo'])\n// matched will be true, and foo's `command` function will be called\n\nvar matched = match(['foo', 'baz', 'taco'])\n// matched will be true, and foo's `command` function will be called with `['baz', 'taco']`\n\nvar matched = match(['bar'])\n// matched will be true, and bar's `command` function will be called\n\nvar matched = match(['uhoh'])\n// matched will be false\n```\n\n## advanced usage\n\ninstead of an array, you can also pass an object that looks like this as the first argument to `subcommand`:\n\n```\n{\n  root: // root command options and handler\n  defaults: // default options\n  all: // function that gets called always, regardless of match or no match\n  none: // function that gets called only when there is no matched subcommand\n  commands: // the commands array from basic usage\n}\n```\n\nsee `test.js` for a concrete example\n\n### root\n\nto pass options to the 'root' command (e.g. when no subcommand is passed in), set up your config like this:\n\n```js\nvar config = {\n  root: {\n    options: [ // cliclopts options\n      {\n        name: 'loud',\n        boolean: true,\n        default: false,\n        abbr: 'v'\n      }\n    ],\n    command: function (args) {\n      // called when no subcommand is specified\n    }\n  },\n  commands: yourSubCommandsArray\n}\n```\n\n### defaults\n\nyou can pass in a defaults options array, and all subcommands as well as the root command will inherit the default options\n\n```js\nvar config = {\n  defaults: [\n    {name: 'path', default: process.cwd()} // all commands (and root) will now always have a 'path' default option\n  ],\n  commands: yourSubCommandsArray\n}\n```\n\n### all\n\npass a function under the `all` key and it will get called with the parsed arguments 100% of the time\n\n```js\nvar config = {\n  all: function all (args) { /** will be called always in addition to the command/root `command` handlers **/ },\n  commands: yourSubCommandsArray\n}\n```\n\n### none\n\npass a function under the `none` key and it will get called when no subcommand is matched\n\n```js\nvar config = {\n  none: function none (args) { /** will only be called when no subcommand is matched **/ },\n  commands: yourSubCommandsArray\n}\n```\n","readmeFilename":"readme.md","_id":"subcommand@2.0.3","_shasum":"9b3fd1a753e3c441f00410cb44131d8655f52c32","_from":"https://registry.npmjs.org/subcommand/-/subcommand-2.0.3.tgz","_resolved":"https://registry.npmjs.org/subcommand/-/subcommand-2.0.3.tgz"}