Permalink
Browse files

add command.usage() for overriding a command's usage printout

  • Loading branch information...
1 parent b25fde2 commit 27687f0fab23b0bc22aa43daf452cbf7ad908cbc @harthur committed Jun 14, 2011
Showing with 18 additions and 2 deletions.
  1. +4 −0 README.md
  2. +8 −2 nomnom.js
  3. +6 −0 test/command.js
View
@@ -235,5 +235,9 @@ A callback that will be called with the parsed options when the command is used.
A help string describing the function of this command.
+#### usage
+
+Override the default generated usage string for this command.
+
View
@@ -63,6 +63,10 @@ function ArgParser() {
help : function(help) {
command.help = help;
return chain;
+ },
+ usage : function(usage) {
+ command.usageString = usage;
+ return chain;
}
};
return chain;
@@ -166,7 +170,7 @@ function ArgParser() {
/* parse the args */
if(printHelp && (argv.indexOf("--help") != -1
|| argv.indexOf("-h") != -1))
- parser.print(parser.getUsage());
+ parser.print(parser.getUsage(command));
var options = {};
args = argv.concat([""]).map(function(arg) {
@@ -233,7 +237,9 @@ function ArgParser() {
return options;
},
- getUsage : function() {
+ getUsage : function(command) {
+ if(command && command.usageString)
+ return command.usageString;
if(parser.usageString)
return parser.usageString;
View
@@ -43,10 +43,16 @@ parser.command('node')
})
.help("** Run all the node tests **");
+parser.command('usagetest')
+ .usage('testing command.usage()')
+
parser.parseArgs(["node", "test.js", "-c", "test.json", "-d"]);
assert.ok(called, "node command callback should be called");
+/*
+parser.parseArgs(["usagetest", "-h"]);
+*/
/* no command specified */
called = false;

0 comments on commit 27687f0

Please sign in to comment.