Skip to content

Commit

Permalink
unify codestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiyelee committed Dec 23, 2014
1 parent 992bcc5 commit faa6413
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 30 deletions.
8 changes: 4 additions & 4 deletions test/test.command.action.js
Expand Up @@ -4,10 +4,10 @@ var program = require('../')
var val = false;
program
.command('info [options]')
.option('-C, --no-color', 'turn off color output')
.action(function (){
val = this.color;
});
.option('-C, --no-color', 'turn off color output')
.action(function () {
val = this.color;
});

program.parse(['node', 'test', 'info']);

Expand Down
18 changes: 10 additions & 8 deletions test/test.options.allowUnknown.js
@@ -1,4 +1,3 @@

/**
* Module dependencies.
*/
Expand All @@ -15,8 +14,9 @@ program
.option('-p, --pepper', 'add pepper');

var consoleErrors = [];
process.exit = function() {};
console.error = function() {
process.exit = function () {
};
console.error = function () {
consoleErrors.push(util.format.apply(util, arguments));
};

Expand All @@ -26,8 +26,9 @@ consoleErrors.length.should.equal(3);
// test subcommand
var consoleErrors = [];
program
.command('sub')
.action(function () { });
.command('sub')
.action(function () {
});
program.parse('node test sub -m'.split(' '));
consoleErrors.length.should.equal(3);

Expand All @@ -44,9 +45,10 @@ consoleErrors.length.should.equal(0);
// test subcommand
var consoleErrors = [];
program
.command('sub')
.allowUnknown()
.action(function () { });
.command('sub')
.allowUnknown()
.action(function () {
});
program.parse('node test sub -m'.split(' '));
consoleErrors.length.should.equal(3);

Expand Down
1 change: 0 additions & 1 deletion test/test.options.bool.js
@@ -1,4 +1,3 @@

/**
* Module dependencies.
*/
Expand Down
2 changes: 1 addition & 1 deletion test/test.options.camelcase.js
Expand Up @@ -24,4 +24,4 @@ program.myNum.should.equal(15.99);
program.myFLOAT.should.equal(5.5);
program.myVeryLongFloat.should.equal(6.5);
program.myURLCount.should.equal(7.5);
program.myLongRange.should.eql([1,5]);
program.myLongRange.should.eql([1, 5]);
4 changes: 2 additions & 2 deletions test/test.options.coercion.js
Expand Up @@ -31,6 +31,6 @@ program.parse('node test -i 5.5 -f 5.5 -n 15.99 -r 1..5 -c foo -c bar -c baz -vv
program.int.should.equal(5);
program.num.should.equal(15.99);
program.float.should.equal(5.5);
program.range.should.eql([1,5]);
program.collect.should.eql([ 'foo', 'bar', 'baz' ]);
program.range.should.eql([1, 5]);
program.collect.should.eql(['foo', 'bar', 'baz']);
program.verbose.should.equal(5);
29 changes: 17 additions & 12 deletions test/test.options.commands.js
Expand Up @@ -20,10 +20,10 @@ program
.description('run setup commands for all envs')
.option("-s, --setup_mode [mode]", "Which setup mode to use")
.option("-o, --host [host]", "Host to use")
.action(function(env, options){
.action(function (env, options) {
var mode = options.setup_mode || "normal";
env = env || 'all';

envValue = env;
});

Expand All @@ -33,18 +33,18 @@ program
.description('execute the given remote cmd')
.option("-e, --exec_mode <mode>", "Which exec mode to use")
.option("-t, --target [target]", "Target to use")
.action(function(cmd, options){
.action(function (cmd, options) {
cmdValue = cmd;
}).on("--help", function(){
}).on("--help", function () {
customHelp = true;
});

program
.command('*')
.action(function(env){
.action(function (env) {
console.log('deploying "%s"', env);
});

program.parse(['node', 'test', '--config', 'conf']);
program.config.should.equal("conf");
program.commands[0].should.not.have.property.setup_mode;
Expand Down Expand Up @@ -96,22 +96,27 @@ cmdValue.should.equal("exec4");
var exceptionOccurred = false;
var oldProcessExit = process.exit;
var oldConsoleError = console.error;
process.exit = function() { exceptionOccurred = true; throw new Error(); };
console.error = function() {};
process.exit = function () {
exceptionOccurred = true;
throw new Error();
};
console.error = function () {
};

var oldProcessStdoutWrite = process.stdout.write;
process.stdout.write = function () {};
process.stdout.write = function () {
};
try {
program.parse(['node', 'test', '--config', 'conf6', 'exec', '--help']);
} catch(ex) {
} catch (ex) {
program.config.should.equal("conf6");
}
process.stdout.write = oldProcessStdoutWrite;

try {
program.parse(['node', 'test', '--config', 'conf', 'exec', '-t', 'target1', 'exec1', '-e']);
program.parse(['node', 'test', '--config', 'conf', 'exec', '-t', 'target1', 'exec1', '-e']);
}
catch(ex) {
catch (ex) {
}

process.exit = oldProcessExit;
Expand Down
6 changes: 4 additions & 2 deletions test/test.variadic.args.js
Expand Up @@ -39,8 +39,10 @@ var oldProcessExit = process.exit;
var oldConsoleError = console.error;
var errorMessage;

process.exit = function() { throw new Error(consoleErrors.join('\n')); };
console.error = function() {
process.exit = function () {
throw new Error(consoleErrors.join('\n'));
};
console.error = function () {
consoleErrors.push(util.format.apply(util, arguments));
};

Expand Down

0 comments on commit faa6413

Please sign in to comment.