"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/touch/node_modules/nopt/bin/nopt.js" (11 Apr 2017, 1277 Bytes) of package /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    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 
   24 console.log("parsed", parsed)
   25 
   26 if (parsed.help) {
   27   console.log("")
   28   console.log("nopt cli tester")
   29   console.log("")
   30   console.log("types")
   31   console.log(Object.keys(types).map(function M (t) {
   32     var type = types[t]
   33     if (Array.isArray(type)) {
   34       return [t, type.map(function (type) { return type.name })]
   35     }
   36     return [t, type && type.name]
   37   }).reduce(function (s, i) {
   38     s[i[0]] = i[1]
   39     return s
   40   }, {}))
   41   console.log("")
   42   console.log("shorthands")
   43   console.log(shorthands)
   44 }