How to use nopt - 10 common examples

To help you get started, we’ve selected a few nopt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github babobski / Beautify-js / content / js / lib / cli.js View on Github external
var debug = process.env.DEBUG_JSBEAUTIFY || process.env.JSBEAUTIFY_DEBUG ? function() {
  console.error.apply(console, arguments);
} : function() {};

var fs = require('fs'),
  cc = require('config-chain'),
  beautify = require('../index'),
  mkdirp = require('mkdirp'),
  nopt = require('nopt');

nopt.invalidHandler = function(key, val) {
  throw new Error(key + " was invalid with value \"" + val + "\"");
};

nopt.typeDefs.brace_style = {
  type: "brace_style",
  validate: function(data, key, val) {
    data[key] = val;
    // TODO: expand-strict is obsolete, now identical to expand.  Remove in future version
    // TODO: collapse-preserve-inline is obselete, now identical to collapse,preserve-inline = true. Remove in future version
    var validVals = ["collapse", "collapse-preserve-inline", "expand", "end-expand", "expand-strict", "none", "preserve-inline"];
    var valSplit = val.split(/[^a-zA-Z0-9_\-]+/); //Split will always return at least one parameter
    for (var i = 0; i < valSplit.length; i++) {
      if (validVals.indexOf(valSplit[i]) === -1) {
        return false;
      }
    }
    return true;
  }
};
var path = require('path'),
github beautify-web / js-beautify / js / lib / cli.js View on Github external
var debug = process.env.DEBUG_JSBEAUTIFY || process.env.JSBEAUTIFY_DEBUG ? function() {
    console.error.apply(console, arguments);
} : function() {};

var fs = require('fs'),
    cc = require('config-chain'),
    beautify = require('../index'),
    mkdirp = require('mkdirp'),
    nopt = require('nopt'),
    glob = require('glob');

nopt.invalidHandler = function(key, val) {
    throw new Error(key + " was invalid with value \"" + val + "\"");
};

nopt.typeDefs.brace_style = {
    type: "brace_style",
    validate: function(data, key, val) {
        data[key] = val;
        // TODO: expand-strict is obsolete, now identical to expand.  Remove in future version
        // TODO: collapse-preserve-inline is obselete, now identical to collapse,preserve-inline = true. Remove in future version
        var validVals = ["collapse", "collapse-preserve-inline", "expand", "end-expand", "expand-strict", "none", "preserve-inline"];
        var valSplit = val.split(/[^a-zA-Z0-9_\-]+/); //Split will always return at least one parameter
        for (var i = 0; i < valSplit.length; i++) {
            if (validVals.indexOf(valSplit[i]) === -1) {
                return false;
            }
        }
        return true;
    }
};
var path = require('path'),
github sx1989827 / DOClever / node_modules / js-beautify / js / lib / cli.js View on Github external
*/

var debug = process.env.DEBUG_JSBEAUTIFY || process.env.JSBEAUTIFY_DEBUG ? function() {
    console.error.apply(console, arguments);
} : function() {};

var fs = require('fs'),
    cc = require('config-chain'),
    beautify = require('../index'),
    mkdirp = require('mkdirp'),
    nopt = require('nopt');
nopt.invalidHandler = function(key, val, types) {
    throw new Error(key + " was invalid with value \"" + val + "\"");
}
nopt.typeDefs.brace_style = {
    type: "brace_style",
    validate: function(data, key, val) {
        data[key] = val;
        // TODO: expand-strict is obsolete, now identical to expand.  Remove in future version
        // TODO: collapse-preserve-inline is obselete, now identical to collapse,preserve-inline = true. Remove in future version
        var validVals = ["collapse", "collapse-preserve-inline", "expand", "end-expand", "expand-strict", "none", "preserve-inline"];
        var valSplit = val.split(/[^a-zA-Z0-9_\-]+/); //Split will always return at least one parameter
        for (var i = 0; i < valSplit.length; i++) {
            if (validVals.indexOf(valSplit[i]) === -1) {
                return false;
            }
        }
        return true;
    }
};
var path = require('path'),
github beautify-web / js-beautify / js / lib / cli.js View on Github external
*/
/*jshint strict:false */

var debug = process.env.DEBUG_JSBEAUTIFY || process.env.JSBEAUTIFY_DEBUG ? function() {
    console.error.apply(console, arguments);
} : function() {};

var fs = require('fs'),
    cc = require('config-chain'),
    beautify = require('../index'),
    mkdirp = require('mkdirp'),
    nopt = require('nopt'),
    glob = require('glob');

nopt.invalidHandler = function(key, val) {
    throw new Error(key + " was invalid with value \"" + val + "\"");
};

nopt.typeDefs.brace_style = {
    type: "brace_style",
    validate: function(data, key, val) {
        data[key] = val;
        // TODO: expand-strict is obsolete, now identical to expand.  Remove in future version
        // TODO: collapse-preserve-inline is obselete, now identical to collapse,preserve-inline = true. Remove in future version
        var validVals = ["collapse", "collapse-preserve-inline", "expand", "end-expand", "expand-strict", "none", "preserve-inline"];
        var valSplit = val.split(/[^a-zA-Z0-9_\-]+/); //Split will always return at least one parameter
        for (var i = 0; i < valSplit.length; i++) {
            if (validVals.indexOf(valSplit[i]) === -1) {
                return false;
            }
        }
github cytle / wechat_web_devtools / package.nw / node_modules / js-beautify / js / lib / cli.js View on Github external
-------------------------------------

  Written by Daniel Stockman (daniel.stockman@gmail.com)

*/

var debug = process.env.DEBUG_JSBEAUTIFY || process.env.JSBEAUTIFY_DEBUG ? function() {
    console.error.apply(console, arguments);
} : function() {};

var fs = require('fs'),
    cc = require('config-chain'),
    beautify = require('../index'),
    mkdirp = require('mkdirp'),
    nopt = require('nopt');
nopt.invalidHandler = function(key, val, types) {
    throw new Error(key + " was invalid with value \"" + val + "\"");
}
nopt.typeDefs.brace_style = {
    type: "brace_style",
    validate: function(data, key, val) {
        data[key] = val;
        // TODO: expand-strict is obsolete, now identical to expand.  Remove in future version
        // TODO: collapse-preserve-inline is obselete, now identical to collapse,preserve-inline = true. Remove in future version
        var validVals = ["collapse", "collapse-preserve-inline", "expand", "end-expand", "expand-strict", "none", "preserve-inline"];
        var valSplit = val.split(/[^a-zA-Z0-9_\-]+/); //Split will always return at least one parameter
        for (var i = 0; i < valSplit.length; i++) {
            if (validVals.indexOf(valSplit[i]) === -1) {
                return false;
            }
        }
        return true;
github njh / marquette / marquette.js View on Github external
// development only
if (process.env.NODE_ENV === 'development') {
  app.use(errorhandler());
}


var knownOpts = {
    "settings":[path],
    "v": Boolean,
    "help": Boolean
};
var shortHands = {
    "s":["--settings"],
    "?":["--help"]
};
nopt.invalidHandler = function(k,v,t) {
    console.log(k,v,t);
}

var parsedArgs = nopt(knownOpts,shortHands,process.argv,2)

if (parsedArgs.help) {
    console.log("Marquette");
    console.log("Usage: node marquette.js [-v] [-?] [--settings settings.js]");
    console.log("");
    console.log("Options:");
    console.log("  -s, --settings FILE  use specified settings file");
    console.log("  -v                   enable verbose output");
    console.log("  -?, --help           show usage");
    process.exit();
}
github orchoban / react.cordova / node_modules / npm / lib / config / core.js View on Github external
function validate (cl) {
  // warn about invalid configs at every level.
  cl.list.forEach(function (conf) {
    nopt.clean(conf, configDefs.types)
  })

  nopt.clean(cl.root, configDefs.types)
}
github graalvm / graaljs / deps / npm / lib / config / core.js View on Github external
function validate (cl) {
  // warn about invalid configs at every level.
  cl.list.forEach(function (conf) {
    nopt.clean(conf, configDefs.types)
  })

  nopt.clean(cl.root, configDefs.types)
}
github liquidg3 / altair / node_modules / npm / lib / config / core.js View on Github external
function validate (cl) {
  // warn about invalid configs at every level.
  cl.list.forEach(function (conf) {
    nopt.clean(conf, configDefs.types)
  })

  nopt.clean(cl.root, configDefs.types)
}
github feedhenry / fh-fhc / lib / utils / config-defs.js View on Github external
// defaults, types, and shorthands.

var path = require("path");
var url = require("url");
var Stream = require("stream").Stream;
var semver = require("semver");
var stableFamily = semver.parse(process.version);
var os = require("os");
var nopt = require("nopt");
var log = require("./log");

nopt.typeDefs.semver = { type: semver, validate: validateSemver };

function validateSemver(data, k, val) {
  if (!semver.valid(val)) {
    return false;
  }
  data[k] = semver.valid(val);
}

nopt.invalidHandler = function(k, val) {
  log.warn(k + "=" + JSON.stringify(val), "invalid config");
};

if (!stableFamily || (+stableFamily[2] % 2)) {
  stableFamily = null;
} else {
  stableFamily = stableFamily[1] + "." + stableFamily[2];

nopt

Option parsing for Node, supporting types, shorthands, etc. Used by npm.

ISC
Latest version published 11 months ago

Package Health Score

85 / 100
Full package analysis