Skip to content

Capitalize and highlight optional args. #19

Merged
merged 3 commits into from Jun 23, 2012
View
17 nomnom.js
@@ -253,7 +253,7 @@ ArgParser.prototype = {
// exit if required arg isn't present
this.specs.forEach(function(opt) {
if (opt.required && options[opt.name] === undefined) {
- this.print(opt.name + " argument is required\n\n" + this.getUsage(), 1);
+ this.print("\n" + opt.name + " argument is required\n" + this.getUsage(), 1);
}
}, this);
@@ -281,10 +281,10 @@ ArgParser.prototype = {
// todo: use a template
var str = "\n"
if (this._colors) {
- str += "usage:".bold;
+ str += "Usage:".bold;
}
else {
- str += "usage:";
+ str += "Usage:";
}
str += " " + this._script;
@@ -303,7 +303,12 @@ ArgParser.prototype = {
str += " ";
var posStr = pos.string;
if (!posStr) {
- posStr = "<" + (pos.name || "arg" + pos.position) + ">";
+ posStr = pos.name || "arg" + pos.position;
+ if (pos.required) {
+ posStr = "<" + posStr + ">";
+ } else {
+ posStr = "[" + posStr + "]";
+ }
if (pos.list) {
posStr += "...";
}
@@ -353,10 +358,10 @@ ArgParser.prototype = {
if (options.length) {
if (this._colors) {
- str += "options:".blue;
+ str += "Options:".blue;
}
else {
- str += "options:";
+ str += "Options:";
}
str += "\n"
View
6 test/commands.js
@@ -98,13 +98,13 @@ exports.testUsage = function(test) {
parser = createParser();
parser.printer(function(string) {
- test.equal(strip(string), "usage:testrun[options]options:--debug--filefiletorunrunall");
+ test.equal(strip(string), "Usage:testrun[options]Options:--debug--filefiletorunrunall");
});
parser.parse(["run", "-h"]);
parser = createParser();
parser.printer(function(string) {
- test.equal(strip(string), "usage:test<command>[options]commandoneof:run,testoptions:--debug--verbosenocommand");
+ test.equal(strip(string), "Usage:test[command][options]commandoneof:run,testOptions:--debug--verbosenocommand");
});
parser.parse(["-h"]);
@@ -117,4 +117,4 @@ exports.testUsage = function(test) {
parser.parse(["-h"]);
test.done();
-}
+}
View
2 test/expected.js
@@ -33,7 +33,7 @@ exports.testRequired = function(test) {
}
})
.printer(function(string) {
- test.equal(0, string.indexOf("file argument is required"))
+ test.equal(0, string.trim().indexOf("file argument is required"))
test.done();
})
.parse([]);
View
28 test/usage.js
@@ -30,7 +30,7 @@ var opts = {
var parser = nomnom().options(opts).help("all the best foods").scriptName("test");
-var expected = "usage:test<egg>[options]eggrobinoptions:-a,--applehowmanyapples--b-nana-cNUM,--carrots=NUM--dillPICKLEallthebestfoods"
+var expected = "Usage:test[egg][options]eggrobinOptions:-a,--applehowmanyapples--b-nana-cNUM,--carrots=NUM--dillPICKLEallthebestfoods"
exports.testH = function(test) {
test.expect(1);
@@ -58,7 +58,7 @@ exports.testScriptName = function(test) {
nomnom()
.script("test")
.printer(function(string) {
- test.equal(strip(string),"usage:test")
+ test.equal(strip(string),"Usage:test")
test.done();
})
.parse(["-h"]);
@@ -86,7 +86,29 @@ exports.testHidden = function(test) {
})
.scriptName("test")
.printer(function(string) {
- test.equal(strip("usage:test[options]options:"), strip(string))
+ test.equal(strip("Usage:test[options]Options:"), strip(string))
+ test.done();
+ })
+ .parse(["-h"]);
+}
+
+exports.testRequiredOptional = function(test) {
+ test.expect(1);
+
+ nomnom().options({
+ foo: {
+ position: 0,
+ required: true,
+ help: 'The foo'
+ },
+ bar: {
+ position: 1,
+ help: 'The bar'
+ }
+ })
+ .scriptName("test")
+ .printer(function(string) {
+ test.equal(strip("Usage:test<foo>[bar]fooThefoobarThebar"), strip(string))
test.done();
})
.parse(["-h"]);
Something went wrong with that request. Please try again.