argv-options

2019-11-10 admin

argv-options是什么

什么是argv-options,opinionated argv options parser

argv-options使用教程帮助文档

argv-options

npm Travis

argv-options subjectively parses your argv options, i.e., it makes assumptions about how your CLI is designed to keep the API simple. It expects your argv object to be supplied in the format of -p foo --param bar, i.e., simple key-value arguments that may be aliased (using --).

API

parseOptions(argv, options)

This method will return the parsed options in a key-value based object, including all found options and their respective aliases. The following arugments are mandatory:

  • argv The arguments array, as space-split array of all parameters. In your average usage case, passing process.argv.slice(2) will do.
  • options The possible options, as object:
{
  "p": {
    "optional": false,
    "alias": "param"
  },

  "a": {
    "optional": true,
    "alias": "argument"
  }
}

Parameters are required (optional is false) by default. Alternatively, for more convenient use, aliases may be specified by using the key’s value:

{
  "p": "param"
}

If any non-optional parameters are missing or undocumented parameters occur, parseOptions will throw an error.

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-78909.html

文章标题:argv-options

回到顶部