react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / nopt / bin / nopt.js
80684 views#!/usr/bin/env node1var nopt = require("../lib/nopt")2, path = require("path")3, types = { num: Number4, bool: Boolean5, help: Boolean6, list: Array7, "num-list": [Number, Array]8, "str-list": [String, Array]9, "bool-list": [Boolean, Array]10, str: String11, clear: Boolean12, config: Boolean13, length: Number14, file: path15}16, shorthands = { s: [ "--str", "astring" ]17, b: [ "--bool" ]18, nb: [ "--no-bool" ]19, tft: [ "--bool-list", "--no-bool-list", "--bool-list", "true" ]20, "?": ["--help"]21, h: ["--help"]22, H: ["--help"]23, n: [ "--num", "125" ]24, c: ["--config"]25, l: ["--length"]26, f: ["--file"]27}28, parsed = nopt( types29, shorthands30, process.argv31, 2 )3233console.log("parsed", parsed)3435if (parsed.help) {36console.log("")37console.log("nopt cli tester")38console.log("")39console.log("types")40console.log(Object.keys(types).map(function M (t) {41var type = types[t]42if (Array.isArray(type)) {43return [t, type.map(function (type) { return type.name })]44}45return [t, type && type.name]46}).reduce(function (s, i) {47s[i[0]] = i[1]48return s49}, {}))50console.log("")51console.log("shorthands")52console.log(shorthands)53}545556