Permalink
Browse files

'scriptName' -> 'script'

  • Loading branch information...
1 parent c6f39f1 commit 1b4585c9390c298b2e52eb5544e8f7e4b92bf2c2 @harthur committed Nov 2, 2011
Showing with 14 additions and 10 deletions.
  1. +3 −3 README.md
  2. +10 −6 nomnom.js
  3. +1 −1 test/usage.js
View
@@ -94,7 +94,7 @@ Nomnom prints out a usage message if `--help` or `-h` is an argument. Usage for
```javascript
var options = require("nomnom")
- .scriptName("runtests")
+ .script("runtests")
.opts({
path: {
position: 0,
@@ -233,9 +233,9 @@ The string that will override the default generated usage message.
A string that is appended to the usage.
-#### scriptName
+#### script
-Nomnom can't detect the alias used to run your script. You can use `scriptName` to provide the correct name for the usage printout instead of e.g. `node test.js`.
+Nomnom can't detect the alias used to run your script. You can use `script` to provide the correct name for the usage printout instead of e.g. `node test.js`.
#### printer
View
@@ -63,10 +63,14 @@ ArgParser.prototype = {
return this;
},
- scriptName : function(script) {
- this.script = script;
+ script : function(script) {
+ this._script = script;
return this;
},
+
+ scriptName : function(script) {
+ return this.script(script);
+ },
help : function(help) {
this._help = help;
@@ -79,7 +83,7 @@ ArgParser.prototype = {
process.exit(0);
};
this._help = this._help || "";
- this.script = this.script || process.argv[0] + " "
+ this._script = this._script || process.argv[0] + " "
+ require('path').basename(process.argv[1]);
this.specs = this.specs || {};
@@ -92,14 +96,14 @@ ArgParser.prototype = {
if (commandExpected) {
if (command) {
_(this.specs).extend(command.specs);
- this.script += " " + command.name;
+ this._script += " " + command.name;
if (command.help) {
this._help = command.help;
}
this.command = command;
}
else if (arg) {
- return this.print(this.script + ": no such command '" + arg + "'");
+ return this.print(this._script + ": no such command '" + arg + "'");
}
else {
// no command but command expected e.g. 'git -v'
@@ -236,7 +240,7 @@ ArgParser.prototype = {
}
// todo: use a template
- var str = "usage: " + this.script;
+ var str = "usage: " + this._script;
var positionals = _(this.specs).select(function(opt) {
return opt.position != undefined;
View
@@ -56,7 +56,7 @@ exports.testScriptName = function(test) {
test.expect(1);
nomnom()
- .scriptName("test")
+ .script("test")
.printer(function(string) {
test.equal(strip(string),"usage:test")
test.done();

0 comments on commit 1b4585c

Please sign in to comment.