暫無描述

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env node
  2. var nopt = require("../lib/nopt")
  3. , types = { num: Number
  4. , bool: Boolean
  5. , help: Boolean
  6. , list: Array
  7. , "num-list": [Number, Array]
  8. , "str-list": [String, Array]
  9. , "bool-list": [Boolean, Array]
  10. , str: String }
  11. , shorthands = { s: [ "--str", "astring" ]
  12. , b: [ "--bool" ]
  13. , nb: [ "--no-bool" ]
  14. , tft: [ "--bool-list", "--no-bool-list", "--bool-list", "true" ]
  15. , "?": ["--help"]
  16. , h: ["--help"]
  17. , H: ["--help"]
  18. , n: [ "--num", "125" ] }
  19. , parsed = nopt( types
  20. , shorthands
  21. , process.argv
  22. , 2 )
  23. console.log("parsed", parsed)
  24. if (parsed.help) {
  25. console.log("")
  26. console.log("nopt cli tester")
  27. console.log("")
  28. console.log("types")
  29. console.log(Object.keys(types).map(function M (t) {
  30. var type = types[t]
  31. if (Array.isArray(type)) {
  32. return [t, type.map(function (type) { return type.name })]
  33. }
  34. return [t, type && type.name]
  35. }).reduce(function (s, i) {
  36. s[i[0]] = i[1]
  37. return s
  38. }, {}))
  39. console.log("")
  40. console.log("shorthands")
  41. console.log(shorthands)
  42. }