Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: substack/node-optimist
base: 3a0f014c14
...
head fork: substack/node-optimist
compare: a0750781b8
  • 3 commits
  • 17 files changed
  • 0 commit comments
  • 2 contributors
Commits on Apr 26, 2012
Aaron Forsander Fixes #37. 541bac8
Aaron Forsander Test for #37. 90ff6a1
Commits on Apr 30, 2012
@substack bump for fixes, s/examples/example/ a075078
View
0  examples/bool.js → example/bool.js
File renamed without changes
View
0  examples/boolean_double.js → example/boolean_double.js
File renamed without changes
View
0  examples/boolean_single.js → example/boolean_single.js
File renamed without changes
View
0  examples/default_hash.js → example/default_hash.js
File renamed without changes
View
0  examples/default_singles.js → example/default_singles.js
File renamed without changes
View
0  examples/divide.js → example/divide.js
File renamed without changes
View
0  examples/line_count.js → example/line_count.js
File renamed without changes
View
0  examples/line_count_options.js → example/line_count_options.js
File renamed without changes
View
0  examples/line_count_wrap.js → example/line_count_wrap.js
File renamed without changes
View
0  examples/nonopt.js → example/nonopt.js
File renamed without changes
View
0  examples/short.js → example/short.js
File renamed without changes
View
0  examples/string.js → example/string.js
File renamed without changes
View
0  examples/usage-options.js → example/usage-options.js
File renamed without changes
View
0  examples/xup.js → example/xup.js
File renamed without changes
View
3  index.js
@@ -393,6 +393,9 @@ function Argv (args, cwd) {
Object.keys(defaults).forEach(function (key) {
if (!(key in argv)) {
argv[key] = defaults[key];
+ if (key in aliases) {
+ argv[aliases[key]] = defaults[key];
+ }
}
});
View
10 package.json
@@ -1,19 +1,19 @@
{
"name" : "optimist",
- "version" : "0.3.2",
+ "version" : "0.3.3",
"description" : "Light-weight option parsing with an argv hash. No optstrings attached.",
"main" : "./index.js",
"directories" : {
"lib" : ".",
"test" : "test",
- "example" : "examples"
+ "example" : "example"
},
"dependencies" : {
- "wordwrap" : ">=0.0.1 <0.1.0"
+ "wordwrap" : "~0.0.2"
},
"devDependencies" : {
- "hashish": "0.0.x",
- "tap" : "0.2.x"
+ "hashish": "~0.0.4",
+ "tap" : "~0.2.4"
},
"scripts" : {
"test" : "tap ./test/*.js"
View
49 test/usage.js
@@ -13,7 +13,7 @@ test('usageFail', function (t) {
r.result,
{ x : 10, z : 20, _ : [], $0 : './usage' }
);
-
+
t.same(
r.errors.join('\n').split(/\n+/),
[
@@ -75,12 +75,12 @@ test('checkFail', function (t) {
})
.argv;
});
-
+
t.same(
r.result,
{ x : 10, z : 20, _ : [], $0 : './usage' }
);
-
+
t.same(
r.errors.join('\n').split(/\n+/),
[
@@ -88,7 +88,7 @@ test('checkFail', function (t) {
'You forgot about -y'
]
);
-
+
t.same(r.logs, []);
t.ok(r.exit);
t.end();
@@ -98,7 +98,7 @@ test('checkCondPass', function (t) {
function checker (argv) {
return 'x' in argv && 'y' in argv;
}
-
+
var r = checkUsage(function () {
return optimist('-x 10 -y 20'.split(' '))
.usage('Usage: $0 -x NUM -y NUM')
@@ -118,25 +118,25 @@ test('checkCondFail', function (t) {
function checker (argv) {
return 'x' in argv && 'y' in argv;
}
-
+
var r = checkUsage(function () {
return optimist('-x 10 -z 20'.split(' '))
.usage('Usage: $0 -x NUM -y NUM')
.check(checker)
.argv;
});
-
+
t.same(
r.result,
{ x : 10, z : 20, _ : [], $0 : './usage' }
);
-
+
t.same(
r.errors.join('\n').split(/\n+/).join('\n'),
'Usage: ./usage -x NUM -y NUM\n'
+ 'Argument check failed: ' + checker.toString()
);
-
+
t.same(r.logs, []);
t.ok(r.exit);
t.end();
@@ -169,7 +169,7 @@ test('countFail', function (t) {
r.result,
{ _ : [ '1', '2' ], moo : true, $0 : './usage' }
);
-
+
t.same(
r.errors.join('\n').split(/\n+/),
[
@@ -177,7 +177,7 @@ test('countFail', function (t) {
'Not enough non-option arguments: got 2, need at least 3',
]
);
-
+
t.same(r.logs, []);
t.ok(r.exit);
t.end();
@@ -203,6 +203,23 @@ test('defaultSingles', function (t) {
t.end();
});
+test('defaultAliases', function (t) {
+ var r = checkUsage(function () {
+ return optimist('')
+ .alias('f', 'foo')
+ .default('f', 5)
+ .argv
+ ;
+ });
+ t.same(r.result, {
+ f : '5',
+ foo : '5',
+ _ : [],
+ $0 : './usage',
+ });
+ t.end();
+});
+
test('defaultHash', function (t) {
var r = checkUsage(function () {
return optimist('--foo 50 --baz 70'.split(' '))
@@ -248,24 +265,24 @@ function checkUsage (f) {
process.exit = function (t) { exit = true };
process.env = Hash.merge(process.env, { _ : 'node' });
process.argv = [ './usage' ];
-
+
var errors = [];
var logs = [];
-
+
console._error = console.error;
console.error = function (msg) { errors.push(msg) };
console._log = console.log;
console.log = function (msg) { logs.push(msg) };
-
+
var result = f();
-
+
process.exit = process._exit;
process.env = process._env;
process.argv = process._argv;
console.error = console._error;
console.log = console._log;
-
+
return {
errors : errors,
logs : logs,

No commit comments for this range

Something went wrong with that request. Please try again.