Permalink
Browse files

Capitalize and highlight optional args.

- "usage" and "options" are now capitalized to provide better english
  and set them off from the actual options and arguments etc.
- Optional arguments are indicated with [] as is common, instead of <>
  that is now used only for required arguments.
- Add a newline before the "... argument required" and remove one after,
  to make it better match how the help text is usually presented.
  • Loading branch information...
1 parent 15078d9 commit 20eabccc8db4ae7828b47bc62e6cf368bdf2df5a @calmh calmh committed Jun 14, 2012
Showing with 17 additions and 12 deletions.
  1. +10 −5 nomnom.js
  2. +3 −3 test/commands.js
  3. +1 −1 test/expected.js
  4. +3 −3 test/usage.js
View
@@ -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
@@ -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
@@ -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
@@ -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,7 @@ 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"]);

0 comments on commit 20eabcc

Please sign in to comment.