{"_id":"posix-argv-parser","_rev":"942666","name":"posix-argv-parser","description":"POSIX compliant command-line argument parser.","dist-tags":{"latest":"2.0.0"},"maintainers":[{"name":"augustl","email":"august@augustl.com"},{"name":"dominykas","email":"hello@dominykas.com"},{"name":"dwittner","email":"d.wittner@gmx.de"}],"time":{"modified":"2021-09-23T02:08:52.000Z","created":"2012-06-20T21:38:39.169Z","2.0.0":"2015-11-18T21:36:34.691Z","1.0.2":"2014-04-23T14:24:16.615Z","1.0.1":"2014-03-25T21:13:19.000Z","1.0.0":"2013-09-16T22:32:23.947Z","0.4.2":"2013-01-19T11:57:35.876Z","0.4.1":"2012-07-09T22:31:00.454Z","0.4.0":"2012-06-20T21:38:39.169Z"},"users":{"craigsapp":true,"abarth500":true},"author":{"name":"August Lilleaas"},"repository":{"type":"git","url":"git+https://github.com/busterjs/posix-argv-parser.git"},"versions":{"2.0.0":{"name":"posix-argv-parser","version":"2.0.0","description":"POSIX compliant command-line argument parser.","homepage":"http://busterjs.org/docs/posix-argv-parser","author":{"name":"August Lilleaas"},"contributors":[{"name":"Christian Johansen","email":"christian@cjohansen.no","url":"http://cjohansen.no"},{"name":"August Lilleaas","email":"august.lilleaas@gmail.com","url":"http://augustl.com"},{"name":"Stein Magnus Jodal","email":"stein.magnus@jodal.no","url":"http://jodal.no"}],"license":"BSD-3-Clause","main":"./lib/posix-argv-parser","engines":{"node":">= 4"},"repository":{"type":"git","url":"git+https://github.com/busterjs/posix-argv-parser.git"},"scripts":{"test":"node run-tests.js"},"dependencies":{"when":"3.x"},"devDependencies":{"buster-node":"0.7.x"},"gitHead":"9af6333454a5ece28f4db704f8005bdd66664bfe","bugs":{"url":"https://github.com/busterjs/posix-argv-parser/issues"},"_id":"posix-argv-parser@2.0.0","_shasum":"c384db319d36f7e3bb54bc89f0f9105ff0d65a5d","_from":".","_npmVersion":"3.3.12","_nodeVersion":"4.2.2","_npmUser":{"name":"dominykas","email":"hello@dominykas.com"},"dist":{"shasum":"c384db319d36f7e3bb54bc89f0f9105ff0d65a5d","size":17608,"noattachment":false,"key":"/posix-argv-parser/-/posix-argv-parser-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/posix-argv-parser/download/posix-argv-parser-2.0.0.tgz"},"maintainers":[{"name":"augustl","email":"august@augustl.com"},{"name":"dominykas","email":"hello@dominykas.com"},{"name":"dwittner","email":"d.wittner@gmx.de"}],"directories":{},"publish_time":1447882594691,"_cnpm_publish_time":1447882594691,"_hasShrinkwrap":false,"deprecated":"No longer maintained"},"1.0.2":{"name":"posix-argv-parser","version":"1.0.2","description":"POSIX compliant command-line argument parser.","homepage":"http://busterjs.org/docs/posix-argv-parser","author":{"name":"August Lilleaas"},"contributors":[{"name":"Christian Johansen","email":"christian@cjohansen.no","url":"http://cjohansen.no"},{"name":"August Lilleaas","email":"august.lilleaas@gmail.com","url":"http://augustl.com"},{"name":"Stein Magnus Jodal","email":"stein.magnus@jodal.no","url":"http://jodal.no"}],"main":"./lib/posix-argv-parser","repository":{"type":"git","url":"https://github.com/busterjs/posix-argv-parser.git"},"license":{"type":"BSD","url":"https://github.com/busterjs/posix-argv-parser/blob/master/LICENSE"},"scripts":{"test":"node run-tests.js"},"dependencies":{"when":"https://github.com/cujojs/when/tarball/1.8.1"},"devDependencies":{"buster-node":"*"},"bugs":{"url":"https://github.com/busterjs/posix-argv-parser/issues"},"_id":"posix-argv-parser@1.0.2","dist":{"shasum":"f43db33e62a94f80d946c9deccebda0176c5be76","size":17702,"noattachment":false,"key":"/posix-argv-parser/-/posix-argv-parser-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/posix-argv-parser/download/posix-argv-parser-1.0.2.tgz"},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"dwittner","email":"d.wittner@gmx.de"},"maintainers":[{"name":"augustl","email":"august@augustl.com"},{"name":"dominykas","email":"hello@dominykas.com"},{"name":"dwittner","email":"d.wittner@gmx.de"}],"directories":{},"publish_time":1398263056615,"_cnpm_publish_time":1398263056615,"_hasShrinkwrap":false,"deprecated":"No longer maintained"},"1.0.1":{"name":"posix-argv-parser","version":"1.0.1","description":"POSIX compliant command-line argument parser.","homepage":"http://busterjs.org/docs/posix-argv-parser","author":{"name":"August Lilleaas"},"contributors":[{"name":"Christian Johansen","email":"christian@cjohansen.no","url":"http://cjohansen.no"},{"name":"August Lilleaas","email":"august.lilleaas@gmail.com","url":"http://augustl.com"},{"name":"Stein Magnus Jodal","email":"stein.magnus@jodal.no","url":"http://jodal.no"}],"main":"./lib/posix-argv-parser","repository":{"type":"git","url":"https://github.com/busterjs/posix-argv-parser.git"},"license":{"type":"BSD","url":"https://github.com/busterjs/posix-argv-parser/blob/master/LICENSE"},"scripts":{"test":"node run-tests.js"},"dependencies":{"when":"https://github.com/cujojs/when/tarball/1.8.1"},"devDependencies":{"buster-node":"*"},"bugs":{"url":"https://github.com/busterjs/posix-argv-parser/issues"},"_id":"posix-argv-parser@1.0.1","dist":{"shasum":"c33033152871bf72b6a712b6f1acfd7064eeb30e","size":17520,"noattachment":false,"key":"/posix-argv-parser/-/posix-argv-parser-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/posix-argv-parser/download/posix-argv-parser-1.0.1.tgz"},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"dwittner","email":"d.wittner@gmx.de"},"maintainers":[{"name":"augustl","email":"august@augustl.com"},{"name":"dominykas","email":"hello@dominykas.com"},{"name":"dwittner","email":"d.wittner@gmx.de"}],"directories":{},"publish_time":1395781999000,"_cnpm_publish_time":1395781999000,"_hasShrinkwrap":false,"deprecated":"No longer maintained"},"1.0.0":{"name":"posix-argv-parser","version":"1.0.0","description":"POSIX compliant command-line argument parser.","homepage":"http://busterjs.org/docs/posix-argv-parser","author":{"name":"August Lilleaas"},"contributors":[{"name":"Christian Johansen","email":"christian@cjohansen.no","url":"http://cjohansen.no"},{"name":"August Lilleaas","email":"august.lilleaas@gmail.com","url":"http://augustl.com"},{"name":"Stein Magnus Jodal","email":"stein.magnus@jodal.no","url":"http://jodal.no"}],"main":"./lib/posix-argv-parser","repository":{"type":"git","url":"https://github.com/busterjs/posix-argv-parser.git"},"license":{"type":"BSD","url":"https://github.com/busterjs/posix-argv-parser/blob/master/LICENSE"},"scripts":{"test":"node run-tests.js"},"dependencies":{"when":"https://github.com/cujojs/when/tarball/1.8.1"},"devDependencies":{"buster-node":"0.1"},"_id":"posix-argv-parser@1.0.0","dist":{"shasum":"3f05ccd1fe7d2cc79e838d18844b6af835237964","size":17235,"noattachment":false,"key":"/posix-argv-parser/-/posix-argv-parser-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/posix-argv-parser/download/posix-argv-parser-1.0.0.tgz"},"maintainers":[{"name":"augustl","email":"august@augustl.com"},{"name":"dominykas","email":"hello@dominykas.com"},{"name":"dwittner","email":"d.wittner@gmx.de"}],"directories":{},"publish_time":1379370743947,"_cnpm_publish_time":1379370743947,"_hasShrinkwrap":false,"deprecated":"No longer maintained"},"0.4.2":{"name":"posix-argv-parser","version":"0.4.2","description":"POSIX compliant command-line argument parser.","homepage":"http://busterjs.org/docs/posix-argv-parser","author":{"name":"August Lilleaas"},"contributors":[{"name":"Christian Johansen","email":"christian@cjohansen.no","url":"http://cjohansen.no"},{"name":"August Lilleaas","email":"august.lilleaas@gmail.com","url":"http://augustl.com"},{"name":"Stein Magnus Jodal","email":"stein.magnus@jodal.no","url":"http://jodal.no"}],"main":"./lib/posix-argv-parser","repository":{"type":"git","url":"https://github.com/busterjs/posix-argv-parser.git"},"license":{"type":"BSD","url":"https://github.com/busterjs/posix-argv-parser/blob/master/LICENSE"},"scripts":{"test":"./node_modules/buster/bin/buster-test"},"dependencies":{"when":"https://github.com/cujojs/when/tarball/1.3.0"},"devDependencies":{"buster":"0.6.11"},"readmeFilename":"Readme.md","_id":"posix-argv-parser@0.4.2","dist":{"shasum":"7ac7f896c2de56c16d5543966d803c3798ccd7f3","size":16906,"noattachment":false,"key":"/posix-argv-parser/-/posix-argv-parser-0.4.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/posix-argv-parser/download/posix-argv-parser-0.4.2.tgz"},"_npmVersion":"1.1.65","_npmUser":{"name":"cjohansen","email":"christian@cjohansen.no"},"maintainers":[{"name":"augustl","email":"august@augustl.com"},{"name":"dominykas","email":"hello@dominykas.com"},{"name":"dwittner","email":"d.wittner@gmx.de"}],"directories":{},"publish_time":1358596655876,"_cnpm_publish_time":1358596655876,"_hasShrinkwrap":false,"deprecated":"No longer maintained"},"0.4.1":{"name":"posix-argv-parser","version":"0.4.1","description":"POSIX compliant command-line argument parser.","homepage":"http://busterjs.org/docs/posix-argv-parser","author":{"name":"August Lilleaas and Christian Johansen"},"contributors":[{"name":"Christian Johansen","email":"christian@cjohansen.no","url":"http://cjohansen.no"},{"name":"August Lilleaas","email":"august.lilleaas@gmail.com","url":"http://augustl.com"}],"main":"./lib/posix-argv-parser","repository":{"type":"git","url":"git://gitorious.org/buster/posix-argv-parser"},"license":{"type":"BSD","url":"http://gitorious.org/buster/posix-argv-parser/blobs/master/LICENSE"},"scripts":{"test":"./node_modules/buster/bin/buster-test"},"dependencies":{"buster-core":">=0.6.2","when":"https://github.com/cujojs/when/tarball/1.3.0"},"devDependencies":{"buster":"*"},"_npmUser":{"name":"cjohansen","email":"christian@cjohansen.no"},"_id":"posix-argv-parser@0.4.1","engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.0-alpha-6","_nodeVersion":"v0.6.5","_defaultsLoaded":true,"dist":{"shasum":"b435b7b82f0a56a8d45620967a757edfd83eed11","size":12203,"noattachment":false,"key":"/posix-argv-parser/-/posix-argv-parser-0.4.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/posix-argv-parser/download/posix-argv-parser-0.4.1.tgz"},"maintainers":[{"name":"augustl","email":"august@augustl.com"},{"name":"dominykas","email":"hello@dominykas.com"},{"name":"dwittner","email":"d.wittner@gmx.de"}],"directories":{},"publish_time":1341873060454,"_cnpm_publish_time":1341873060454,"_hasShrinkwrap":false,"deprecated":"No longer maintained"},"0.4.0":{"name":"posix-argv-parser","version":"0.4.0","description":"POSIX compliant command-line argument parser.","homepage":"http://busterjs.org/docs/posix-argv-parser","author":{"name":"August Lilleaas and Christian Johansen"},"contributors":[{"name":"Christian Johansen","email":"christian@cjohansen.no","url":"http://cjohansen.no"},{"name":"August Lilleaas","email":"august.lilleaas@gmail.com","url":"http://augustl.com"}],"main":"./lib/posix-argv-parser","repository":{"type":"git","url":"git://gitorious.org/buster/posix-argv-parser"},"license":{"type":"BSD","url":"http://gitorious.org/buster/posix-argv-parser/blobs/master/LICENSE"},"scripts":{"test":"./node_modules/buster/bin/buster-test"},"dependencies":{"buster-core":">=0.6.2","when":"~1.3"},"devDependencies":{"buster":"*"},"_npmUser":{"name":"cjohansen","email":"christian@cjohansen.no"},"_id":"posix-argv-parser@0.4.0","engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.0-alpha-6","_nodeVersion":"v0.6.5","_defaultsLoaded":true,"dist":{"shasum":"293e52a054235940528f321cf210dba8ba0f730e","size":12103,"noattachment":false,"key":"/posix-argv-parser/-/posix-argv-parser-0.4.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/posix-argv-parser/download/posix-argv-parser-0.4.0.tgz"},"maintainers":[{"name":"augustl","email":"august@augustl.com"},{"name":"dominykas","email":"hello@dominykas.com"},{"name":"dwittner","email":"d.wittner@gmx.de"}],"directories":{},"publish_time":1340228319169,"_cnpm_publish_time":1340228319169,"_hasShrinkwrap":false,"deprecated":"No longer maintained"}},"readme":"# posix-argv-parser\n\n[![Build status](https://secure.travis-ci.org/busterjs/posix-argv-parser.png?branch=master)](http://travis-ci.org/busterjs/posix-argv-parser)\n\nThe Node.JS argument parser that helps you be a good Unix citizen and\ndoesn't make an ass out of u and me.\n\n`posix-argv-parser` is a command line interface (CLI) argument parser that is:\n\n* [POSIX \"Utility Argument Syntax\"](http://pubs.opengroup.org/onlinepubs/9699919799/) compliant\n* **Unobtrusive** - Does not mandate flow control, does not print to STDOUT on\n  your behalf, and does not magically manage `--help`\n* **Ambiguity aware** - lets you specify how to handle ambiguities such as\n  `-bar`, which can mean both `-b -a -r` and `-b=ar`.\n\n```js\nvar pap = require(\"posix-argv-parser\");\nvar args = pap.create();\nvar v = pap.validators;\n\nargs.createOption([\"-p\", \"--port\"], {\n    // All options are optional\n\n    // Implies hasValue: true, which allows parser to read -p2345 as -p=2345\n    defaultValue: 8282,\n\n    // Both built-in and custom validations supported,\n    // synchronous as well as asynchronous (promise based)\n    validators: [v.integer(\"Custom message. ${1} must be a number.\")],\n\n    // Transforms allow you to get more intelligent values\n    // than raw strings back\n    transform: function (value) { return parseInt(value, 10); }\n});\n\nargs.createOption([\"-v\"], {\n    validators: [function (opt) {\n        // See also asynchronous validators\n        if (opt.timesSet < 1) {\n            throw new Error(\"Set \" + opt.signature + \" at least once!\");\n        }\n    }]\n});\n\n// Operands are statements without options.\n// Example: the path in `mything --port=1234 path/to/stuff`\nargs.createOperand(\"rootPath\", {\n    // Used in error msgs\n    signature: \"Presentation root directory\",\n    // Both will use default error messages\n    validators: [v.file(), v.required()]\n});\n\nargs.parse(process.argv.slice(2), function (errors, options) {\n    if (errors) { return console.log(errors[0]); }\n\n    // Various useful ways to get the values from the options.\n    options[\"-v\"].timesSet;\n    options[\"--port\"].isSet;\n    // Will be a true number thanks to the transform\n    options[\"--port\"].value;\n    options.rootPath.value;\n});\n```\n\n## Methods\n\n### `posixArgvParser.create()`\n\n```js\nvar args = require(\"posix-argv-parser\").create();\n```\n\nCreates a new instance of posix-argv-parser that holds a collection of\noptions and operands.\n\n### `args.createOption(flags[, options])`\n\n```js\nargs.createOption([\"-h\", \"--help\"]);\n```\n\nCreates a new `option`. An option has all the properties of an\n`argument`, as well as `option.hasValue` and `option.timesSet`. The\n`options` object is optional.\n\n### `args.addShorthand(opt, [argv1, ...])`\n\nA shorthand is a convenience method for adding options to your CLI\nthat simply set other options.\n\n```js\nargs.createOption(\"--env\", { hasValue: true });\nargs.addShorthand(\"--dev\", [\"--env\", \"dev\"]);\nargs.addShorthand(\"--prod\", [\"--env\", \"prod\"]);\n```\n\nThis makes passing `--dev` an equlvalent to passing `--env dev`.\n\n### `args.createOperand([name][, options])`\n\n```js\nargs.createOperand();\n```\n\nCreates a new operand. An operand has all the properties of an\n`argument`, as well as `greedy: true|false` - i.e. whether or not it\nwill eat many arguments or just one (defaults to `false`, just one).\nThe name is optional, and should be a string. The name is used to\naccess the value through the `options` object passed to the `parse`\ncallback. If not provided, it defaults to \"OPD\" (beware when using\nmore than one operand).\n\n### `args.parse(args, callback)`\n\nPerforms parsing and validation of argv. In Node.JS, make sure to discard\nthe first two items of [process.argv](http://nodejs.org/api/process.html#process_process_argv>), as they\ncontain unrelated arguments (\"node\" and the file name).\n\nThe callback is called with two arguments, `errors`, which is either\nundefined, or an array of errors and/or validation messages, and an\n`options` object, which is used to retrieve data from configured options.\n\n```js\nvar args = require(\"posix-argv-parser\").create();\nargs.handle(process.argv.slice(2), function (errors, options) {\n    if (errors) {\n        // Print an error msg, i.e. console.log(errors[0])\n        return;\n    }\n    // Continue with normal operation. I.e. options[\"-v\"].hasValue,\n    // options[\"-v\"].timesSet, options[\"-p\"].value, etc.\n});\n```\n\n## Arguments (options and operands)\n\nOptions (`args.createOption` and operands (`args.createOperand`) are\nthe two types of arguments handled by posix-argv-parser, and they\nshare common functionality, listed below this introduction.\n\nAn **option** is a flag, with or without a value. `-p`, `-p abc`,\n`-pabc`, `-p=abc`, `--port abc` and `--port=abc` are all supported by\nposix-argv-parser.\n\n`-pabc` can mean both `-p -a -b -c` and `-p=abc`. posix-argv-parser\nuses `opt.hasValue` to separate the two. With `opt.hasValue` set to\ntrue, `-pabc` will be handled as `-p=abc`. When false (default), it\nwill be handled as `-p -a -b -c`. In that case you also need to have\noption handlers for `-a`, `-b` and `-c`, or you'll get a validation\nerror such as `\"unknown option -a\"` (depending on which option\nposix-argv-parser first encountered that didn't exist).\n\nAn **operand** is an option-less value, i.e. `foo` (with no `-b` or\n`--myopt` prefixing it). It's commonly used for arguments that always\nhave to be passed. Examples are `nano path/to/file.txt`, `git checkout\nmaster`, `rmdir my_dir`, etc. The validators `validators.file`,\n`validators.directory`, and `validators.fileOrDirectory` are very\nuseful for operands.\n\nNote that the parser can handle a mix and match of options and\noperands in any order, i.e. `mycommand --port 1234 my/directory` and\n`mycommand my/directory --port 1234` will both work.\n\nMultiple operands will be applied in order of creation. I.e.\n`mycommand something` with two operands will assign `\"something\"` to\nthe first and `undefined` to the second, unless the first is greedy,\nin which case it will receive all the operand values.\n\nSee example usage at the beginning of this document for more\ninformation.\n\nWhen creating options and operands, the following properties can be\npassed in with the \"options\" object.\n\n### `opt.validators`\n\nAn array of validators. A validator is a function that accepts the\nargument result object as input. See below for a description of\nargument result objects. To fail validation, the validator can either\nthrow an error, or return a rejecting promise.\n\n### `opt.transform`\n\nA function that transforms the raw string value provided before\nassigning it to the `opt.value` property of an argument result object.\nThe function receives the string value as input, and should return any\nvalue back.\n\n### `opt.hasValue`\n\nIf the argument takes a value, set to `true`. Defaults to `false` for\noptions, is always `true` for operands (thus it can be omitted).\n\n### `opt.defaultValue`\n\nThe default value to use if the argument was not provided. When\n`opt.defaultValue` is provided, `opt.hasValue` is implied\nand can be omitted. The default value should be a string, and will be\nvalidated and transformed like actual values.\n\n### `opt.signature`\n\nThe signature is used to identify options and operands in validation errors.\nOptions automatically gets a signature consisting of the option flags assigned\nto it::\n\n```js\nvar opt = args.createOption([\"-v\", \"--version\"]);\nopt.signature; // \"-v/--version\"\nopt.signature = \"-v\"; // custom signature\n```\n\nSpecifying a signature is more useful for operands, since an operand doesn't\nhave any data that it can use to auto generate a signature (their default signature\nis \"OPD\").\n\n```js\nvar rootDir = args.createOperand();\nrootDir.signature; // \"OPD\", as the default name\nrootDir.signature = \"Root directory\";\n```\n\n## Options\n\nOptions has additional properties that operands doesn't have.\n\n### `opt.requiresValue`\n\nOnly makes sense if `opt.hasValue` is `true`. When this property\nis `false`, an option can both be provided as a flag with no value or\nas an option with a value.\n\nA common example of options that work with and without values are help\noptions, that may be provided alone to get general help, e.g. `mything\n--help`, and with values to get help for specific topics, e.g.\n`mything --help bisect`.\n\n## Argument result\n\nArgument result objects are produced when calling `args.parse` to\nparse `argv` into the predefined options and operands. There is one\nresult object per original option/operand. These objects have the\nfollowing properties:\n\n### `argumentResult.isSet`\n\n`true` or `false` depending on whether or not the argument was present\nin `argv`.\n\n### `argumentResult.value`\n\nThe value of the argument. Is normally a string, but may be any object\nif the argument had a transform function.\n\n### `argumentResult.timesSet`\n\nThe number of times an argument was set. Useful for options like `-v`\n(verbose) which you might want to allow setting multiple times, giving the\nuser more and more verbose output from your program:\n\n```js\n-v // 1\n-vv // 2\n-v -v -v -v // 4\n-v -vv -vv -vvv // 8\n```\n\n## Validators\n\nValidators let you add requirements with associated error messages to\noptions and operands.\n\nposix-argv-parser has a number of built-in validators, and creating\ncustom ones is dead simple, as a validator is just a function.\n\n### Built-in validators\n\nThe built in validators provides a selection of generic validators.\nYou can customize the error messages by passing strings with tokens\nlike `\"${1}\"` in them. The number and value maps are documented for\neach validator.\n\nValidators are functions, yet the built-in validators are used by\ncalling them directly with custom error messages. This works because\nthe built-in validators all return the actual validation function.\n\n```js\n// Uses built-in error message\nposixArgvParser.validators.required();\n\n// Specify your own error message\nposixArgvParser.validators.required(\"${1} has to be set\");\n```\n\n### `validators.required(errorMessage)`\n\nFails if the option is not set.\n\nCustom error message:\n\n`${1}`: The option `opt.signature`\n\n### `validators.integer(errorMessage)`\n\nWill fail validation if the option was not an integer, i.e. `\"foo\"`\nand `42.5`.\n\nCustom error message:\n\n`${1}`: The specified number\n`${2}`: The option `opt.signature`\n\n### `validators.number(errorMessage)`\n\nWill fail validation if the option was not a number, i.e. `\"foo\"` and\n`?`.\n\nCustom error message:\n\n`${1}`: The specified number\n`${2}`: The option `opt.signature`\n\n### `validators.file(errorMessage)`\n\nWill fail validation if the option was not a path pointing to an\nexisting file in the file system.\n\nCustom error message:\n\n`${1}`: The specified file\n`${2}`: The option `opt.signature`\n\n### `validators.directory(errorMessage)`\n\nWill fail validation if the option was not a path pointing to an\nexisting directory in the file system.\n\nCustom error message:\n\n`${1}`: The specified directory\n`${2}`: The option `opt.signature`\n\n### `validators.fileOrDirectory(errorMessage)`\n\nWill fail validation if the option was not a path pointing to an\nexisting file or directory in the file system. Will fail for block\ndevices, sockets, etc.\n\nCustom error message:\n\n`${1}`: The specified file or directory\n`${2}`: The option `opt.signature`\n\n## Custom validators\n\nA validator is a function that throws an error or returns a promise.\nIf it does not do any of those things, it is immediately considered\npassed. The function is passed an argument result object.\n\n```js\nargs.createOption(\"-v\", {\n    validators: [function (opt) {\n        if (opt.value == \"can not be this value\") {\n            throw new Error(\"This is the error message.\");\n        }\n    }]\n});\n```\n\nPromises are used to facilitate asynchronous validators. Here's an\nexample of a validator that checks if a file is larger than 1MB::\n\n```js\nvar when = require(\"when\");\nargs.createOption([\"-f\"], {\n    validators: [function (opt) {\n        var deferred = when.defer();\n        fs.stat(opt.value, function (err, stat) {\n            if (err) { deferred.reject(\"Unknown error: \" + err); }\n\n            if (stat.size > 1024) {\n                deferred.reject(opt.value +\n                    \" (\" + opt.signature + \") was larger than 1MB\");\n            } else {\n                deferred.resolve();\n            }\n        });\n        return deferred.promise;\n    }]\n});\n```\n\nGiven `--myopt /path/to/file` and the file is larger than 1MB, you'll\nget the error message `\"/path/to/file (--myopt) was larger than 1MB\"`.\n\nRejecting the promise counts as an error. The first argument should be\na string, and is the error message. (TODO: This will likely change to\nan error object with a `message` property).\n\n## Transforms\n\nTransforms can mutate the values of options. A transform is a simple\nfunction that receives the raw string value as input, and can return\nwhatever it likes.::\n\n```js\nargs.createOption([\"-p\"], {\n    transform: function (value) { return parseInt(value, 10); }\n});\n```\n\n## Types\n\nTypes are predefined \"options\" objects that you can pass when creating\noptions and/or operands. For instance, the \"number\" type includes the\nnumber validator, sets `opt.hasValue` to `true`, and includes a\ntransform that converts the raw string to an actual number (by way of\n`parseFloat`)::\n\n```js\nargs.createOption([\"-n\"], args.types.number());\n```\n\nNote that the type is a function call - it returns the options object.\nYou can pass in additional options. The following example piggy-backs\nthe number type to create an option that only takes positive numbers::\n\n```js\nargs.createOption([\"-n\"], args.types.number({\n    validators: [function (opt) {\n        if (parseFloat(opt.value) < 0) {\n            throw new Error(\"Oh noes, negative number!\");\n        }\n    }]\n}));\n```\n\n## Providing `--help`\n\nIt's not in the nature of posix-argv-parser to automatically handle\n`--help` for you. It is however very easy to add such an option to\nyour program. To help you keep all CLI option data in one place,\noptions and operands are allowed to have a `opt.description`\nproperty that posix-argv-parser does not care about::\n\n```js\nvar args = require(\"posix-argv-parser\").create();\n\nargs.createOption([\"--port\"], {\n    defaultValue: 1234\n    description: \"The port to start the server on.\"\n});\n\nargs.createOption([\"-v\"], {\n    description: \"Level of detail in output. \" +\n        \"Pass multiple times (i.e. -vvv) for more output.\"\n});\n\nargs.createOption([\"--help\", \"-h\"], { description: \"Show this text\" });\nhelp.helpText = \"Show this text\";\n\nargs.parse(process.argv.slice(2), function (errors, options) {\n    if (errors) { return console.log(errors[0]); }\n\n    if (options[\"-h\"].isSet) {\n        args.options.forEach(function (opt) {\n            console.log(opt.signature + \": \" + opt.description);\n        });\n    } else {\n        // Proceed with normal program operation\n    }\n});\n```\n\n## Changelog\n\n**2.0.0** (2015-Nov-18)\n\n* Potentially breaking: updated when.js v1 to v3 (no more zalgo in promises)\n* Added `engines` property in `package.json` with a node v4+ requirement\n\n**1.0.2** (2014-Apr-23)\n\n* additional fix for issue [#391](https://github.com/busterjs/buster/issues/391), [not call pop for string arg with trailing dash](https://github.com/busterjs/posix-argv-parser/commit/923797b4896523128586dc901567b4f0ffe2d837)\n\n\n**1.0.1** (2014-Mar-25)\n\n* Fix for issue [#391, posix-argv-parser fails when short option is combined with shorthand](https://github.com/busterjs/buster/issues/391)\n* Fix for issue [#394, Compound short options and operands are conflated](https://github.com/busterjs/buster/issues/394)\n\n","_attachments":{},"homepage":"http://busterjs.org/docs/posix-argv-parser","bugs":{"url":"https://github.com/busterjs/posix-argv-parser/issues"},"license":"BSD-3-Clause"}