项目作者: juliandavidmr

项目描述 :
Toolkit for creating command line interfaces without writing so much code.
高级语言: JavaScript
项目地址: git://github.com/juliandavidmr/menu-args.git
创建时间: 2018-04-21T05:30:59Z
项目社区:https://github.com/juliandavidmr/menu-args

开源协议:MIT License

下载


menu-args

Toolkit for creating command line interfaces without writing so much code.

menu-args uses the args package.

  1. const menu = require('menu-args')
  2. var args = menu(`
  3. Commands
  4. serve "Run server"
  5. build
  6. reload
  7. Options
  8. user "Username"
  9. pass "Password system"
  10. state
  11. port (8080) "Port, default value"
  12. `)
  13. console.log(args.parse(process.argv))

If the command is executed:

  1. node test.js -u the.user -p 1a2b3c

it is obtained:

  1. /* { P: '8080',
  2. port: '8080',
  3. u: 'the.user',
  4. user: 'the.user',
  5. p: '1a2b3c',
  6. pass: '1a2b3c' } */

Note that the variable args is exactly the args package

Install

  1. npm install menu-args --save

Example

If you run function args.showHelp(), we’ll see:

  1. Usage: test.js [options] [command]
  2. Commands:
  3. build, b
  4. help Display help
  5. reload undefined
  6. serve "Run server"
  7. version Display version
  8. Options:
  9. -h, --help Output usage information
  10. -p, --pass Password system
  11. -P, --port [value] Port, default value (defaults to "8080")
  12. -s, --state
  13. -u, --user "Username"
  14. -v, --version Output the version number

License MIT