Socket
Socket
Sign inDemoInstall

nomnom

Package Overview
Dependencies
1
Maintainers
0
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0 to 0.3.0

test/._argv.js

2

._test.js

@@ -1,1 +0,1 @@

Mac OS X  2��ATTR����� � com.macromates.caretx���R������<[k0?'3/«��
Mac OS X  2��ATTR���� � com.macromates.caretx���R������<[k0?'3/«��

@@ -6,4 +6,7 @@ var _ = require("underscore")._;

// for nomnom.parseArgs()
var parser = ArgParser();
ArgParser.parseArgs = parser.parseArgs.bind(parser);
var argParser = ArgParser();
for(var i in argParser) {
if(typeof argParser[i] == "function")
ArgParser[i] = argParser[i];
}

@@ -15,3 +18,3 @@ function ArgParser() {

var match = Opt({});
parser.opts.forEach(function(opt) {
parser.specs.forEach(function(opt) {
if(opt.matches(arg))

@@ -28,3 +31,4 @@ match = opt;

var parser = {
commands : {},
commands : {},
specs: [],

@@ -34,3 +38,3 @@ command : function(name) {

name: name,
opts: {}
specs: {}
};

@@ -40,4 +44,4 @@

return new (function(){
this.opts = function(opts) {
command.opts = opts;
this.opts = function(specs) {
command.specs = specs;
return this;

@@ -55,18 +59,52 @@ };

},
opts : function(specs) {
parser.specs = specs;
return parser;
},
usage : function(usageString) {
parser.usageString = usageString;
return parser;
},
printFunc : function(print) {
parser.print = print;
return parser;
},
scriptName : function(script) {
parser.script = script;
return parser;
},
parseArgs : function(opts, parserOpts, argv) {
parserOpts = parserOpts || {};
var print = parserOpts.printFunc || function(str) {
help : function(helpString) {
parser.helpString = helpString;
return parser;
},
parseArgs : function(argv, parserOpts) {
var printHelp = true;
if(argv && (!argv.length || typeof argv[0] != "string")) {
// using old API
parser.specs = argv;
parserOpts = parserOpts || {};
parser.script = parserOpts.script;
parser.print = parserOpts.pringFunc;
printHelp = parserOpts.printHelp;
if(printHelp == undefined)
printHelp = true;
argv = parserOpts.argv;
}
var print = parser.print || function(str) {
require("sys").puts(str);
process.exit(0);
};
var printHelp = parserOpts.printHelp;
if(printHelp == undefined)
printHelp = true;
parser.help = parserOpts.help || ""; // usage
parser.script = parserOpts.script || process.argv[0] + " "
+ require('path').basename(process.argv[1]); // usage
parser.opts = opts || {};
parser.helpString = parser.helpString || "";
parser.script = parser.script || process.argv[0] + " "
+ require('path').basename(process.argv[1]);
parser.specs = parser.specs || {};
var argv = parserOpts.argv || process.argv.slice(2);
var argv = argv || process.argv.slice(2);

@@ -80,3 +118,3 @@ var commandName;

// no command but command expected e.g. 'git --version'
parser.opts.command = {
parser.specs.command = {
position: 0,

@@ -91,12 +129,12 @@ help: 'one of: ' + _(parser.commands).keys().join(", ")

print(parser.script + ": no such command '" + commandName + "'");
parser.opts = _(command.opts).extend(parser.opts);
parser.specs = _(command.specs).extend(parser.specs);
parser.script += " " + command.name;
if(command.help)
parser.help = command.help;
parser.helpString = command.help;
}
}
if(parser.opts.length == undefined) {
// opts is a hash not an array
parser.opts = _(parser.opts).map(function(opt, name) {
if(parser.specs.length == undefined) {
// specs is a hash not an array
parser.specs = _(parser.specs).map(function(opt, name) {
opt.name = name;

@@ -106,3 +144,3 @@ return opt;

}
parser.opts = parser.opts.map(function(opt) {
parser.specs = parser.specs.map(function(opt) {
return Opt(opt);

@@ -114,6 +152,6 @@ });

|| argv.indexOf("-h") != -1))
print(parser.usageString());
print(parser.getUsage());
var options = {};
parser.opts.forEach(function(opt) {
parser.specs.forEach(function(opt) {
options[opt.name] = opt.default;

@@ -164,3 +202,3 @@ }, parser);

// exit if required arg isn't present
parser.opts.forEach(function(opt) {
parser.specs.forEach(function(opt) {
if(opt.required && !options[opt.name])

@@ -175,6 +213,9 @@ print(opt.name + " argument is required");

usageString : function() {
getUsage : function() {
if(parser.usageString)
return parser.usageString;
var str = "Usage: " + parser.script;
// underscore
var positionals = parser.opts.filter(function(opt) {
var positionals = parser.specs.filter(function(opt) {
return opt.position != undefined;

@@ -184,2 +225,7 @@ }).sort(function(opt1, opt2) {

});
var options = parser.specs.filter(function(opt) {
return opt.position == undefined;
});
// assume there are no gaps in the specified pos. args

@@ -189,3 +235,4 @@ positionals.forEach(function(pos) {

});
str += " [options]\n\n";
if(options.length)
str += " [options]\n\n";

@@ -195,9 +242,9 @@ positionals.forEach(function(pos) {

});
str += "\noptions:\n"
// underscore
parser.opts.forEach(function(opt) {
if(opt.position == undefined)
str += opt.string + "\t\t" + (opt.help || "") + "\n";
if(options.length)
str += "\noptions:\n"
options.forEach(function(opt) {
str += opt.string + "\t\t" + (opt.help || "") + "\n";
});
return str + "\n" + parser.help;
return str + "\n" + (parser.helpString || "");
}

@@ -250,4 +297,2 @@ }

val = val && str;
var value = val || (lg && lgRegex.exec(str)[2]);

@@ -254,0 +299,0 @@ try { // try to infer type by JSON parsing the string

{
"name": "nomnom",
"description": "Limited option parser",
"version": "0.2.0",
"description": "Option parser with support for usage and commands",
"version": "0.3.0",
"author": "Heather Arthur <fayearthur@gmail.com>",

@@ -16,4 +16,4 @@ "repository": {

"dependencies": {
"underscore": "*"
"underscore": ">= 1.1.5"
}
}
# nomnom
nomnom is an option parser for node and CommonJS. It just noms your args and gives them back to you in a hash.
nomnom is an option parser for node and CommonJS. It noms your args and gives them back to you in a hash.
var nomnom = require("nomnom");
var opts = {
config: {
string: '-c PATH, --config=PATH',
default: 'config.json',
help: 'JSON file with tests to run'
},
debug: {
string: '-d',
help: 'Use debug mode'
}
};
var options = nomnom.parseArgs(opts);
var options = require("nomnom")
.opts({
config: {
string: '-c PATH, --config=PATH',
default: 'config.json',
help: 'JSON file with tests to run'
},
debug: {
string: '-d, --debug',
help: 'Print debugging info'
}
})
.parseArgs();

@@ -23,5 +21,5 @@ if(options.debug)

You don't even have to specify anything if you don't want to:
You don't have to specify anything if you don't want to:
var options = nomnom.parseArgs();
var options = require("nomnom").parseArgs();

@@ -40,3 +38,9 @@ var url = options[0]; // get the first positional arg

var parser = nomnom();
var parser = require("nomnom")
.opts({ // global opts
debug: {
string: '-d, --debug',
help: 'print debugging info'
}
});

@@ -64,3 +68,3 @@ parser.command('sanity')

parser.parseArgs(globalOpts);
parser.parseArgs();

@@ -70,3 +74,3 @@ # More Details

var options = nomnom.parseArgs(opts, { argv: ["-xvf", "--atomic=true"] })
var options = nomnom.parseArgs(["-xvf", "--atomic=true"])

@@ -83,20 +87,31 @@ Values are JSON parsed, so `--debug=true --count=3 --file=log.txt` would give you:

var opts = {
filename: {
position: 0,
help: 'file to edit'
}
};
var options = nomnom.parseArgs(opts);
var options = require("nomnom")
.opts({
filename: {
position: 0,
help: 'file to edit'
}
})
.parseArgs();
sys.puts(options.filename);
console.log(options.filename);
### printing usage
Nomnom prints out a usage message if `--help` or `-h` is an argument. You can disable this with the `printHelp` flag and specify the printing function with `printFunc`:
Nomnom prints out a usage message if `--help` or `-h` is an argument. You can override the usage string with `usage`:
nomnom.parseArgs(opts, { printHelp: false });
nomnom.usage("node test.js <filename> --debug");
override the printing function with `printFunc`:
nomnom.printFunc(function(usage) {
console.log(usage);
});
and add a line to the usage with `help`:
nomnom.help("runtests.js will run all the tests in the current directory");
Usage for these options in `test.js`:
var options = {
var options = nomnom.opts({
command: {

@@ -114,3 +129,3 @@ position: 0,

}
}
}).parseArgs();

@@ -127,4 +142,4 @@ ...would look like this:

Nomnom can't detect the alias used to run your script. You can use the `script` option to print the correct name instead of e.g. `node test.js`:
Nomnom can't detect the alias used to run your script. You can use the `scriptName` option to print the correct name instead of e.g. `node test.js`:
nomnom.parseArgs(opts, { script : "test" });
nomnom.scriptName("runtests");

@@ -1,4 +0,4 @@

Mac OS X  2��ATTR�����#�#com.macromates.caret{
Mac OS X  2��ATTR��,��#�#com.macromates.caret{
column = 75;
line = 15;
}

@@ -1,1 +0,1 @@

Mac OS X  2��ATTR����� � com.macromates.caretx���R������<[k0?'3/«��
Mac OS X  2��ATTR��6�� � com.macromates.caretx���R������<[k0?'3/«��

@@ -52,3 +52,3 @@ var nomnom = require("../lib/nomnom"),

var options = nomnom.parseArgs(opts, {argv: ["-c", "other.json", "--debug=false", "-v", "neuralnetwork",
var options = nomnom().parseArgs(opts, {argv: ["-c", "other.json", "--debug=false", "-v", "neuralnetwork",
"-d", "http://db", "--options={}"]});

@@ -55,0 +55,0 @@

@@ -21,3 +21,3 @@ var nomnom = require("../lib/nomnom"),

assert.equal(strip(parser.usageString()), strip("Usage:test.js[options]options:-c,--config=PATHJSONconfigwithtestinfo-lLOG"));
assert.equal(strip(parser.getUsage()), strip("Usage:test.js[options]options:-c,--config=PATHJSONconfigwithtestinfo-lLOG"));
var opts = [

@@ -40,2 +40,2 @@ { name: 'aname0',

assert.equal(strip(parser.usageString()), strip("Usage:test.js<aname0><aname1><aname2>[options]<aname0><aname1><aname2>options:-d"));
assert.equal(strip(parser.getUsage()), strip("Usage:test.js<aname0><aname1><aname2>[options]<aname0><aname1><aname2>options:-d"));

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc