Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
Capitalize and highlight optional args.
Browse files Browse the repository at this point in the history
- "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
calmh committed Jun 14, 2012
1 parent 15078d9 commit 20eabcc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
15 changes: 10 additions & 5 deletions nomnom.js
Expand Up @@ -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;

Expand All @@ -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 += "...";
}
Expand Down Expand Up @@ -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"

Expand Down
6 changes: 3 additions & 3 deletions test/commands.js
Expand Up @@ -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"]);

Expand All @@ -117,4 +117,4 @@ exports.testUsage = function(test) {
parser.parse(["-h"]);

test.done();
}
}
2 changes: 1 addition & 1 deletion test/expected.js
Expand Up @@ -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([]);
Expand Down
6 changes: 3 additions & 3 deletions test/usage.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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"]);
Expand Down Expand Up @@ -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"]);
Expand Down

0 comments on commit 20eabcc

Please sign in to comment.