-
Notifications
You must be signed in to change notification settings - Fork 733
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new set() command as a wrapper for `config` variables. This takes the `-e`, `-v`, `+e`, and `+v` flags.
- Loading branch information
Showing
6 changed files
with
163 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
var common = require('./common'); | ||
|
||
//@ | ||
//@ ### set(options) | ||
//@ Available options: | ||
//@ | ||
//@ + `+/-e`: exit upon error (`config.fatal`) | ||
//@ + `+/-v`: verbose: show all commands (`config.verbose`) | ||
//@ | ||
//@ Examples: | ||
//@ | ||
//@ ```javascript | ||
//@ set('-e'); // exit upon first error | ||
//@ set('+e'); // this undoes a "set('-e')" | ||
//@ ``` | ||
//@ | ||
//@ Sets global configuration variables | ||
function _set(options) { | ||
if (!options) { | ||
var args = [].slice.call(arguments, 0); | ||
if (args.length < 2) | ||
common.error('must provide an argument'); | ||
options = args[1]; | ||
} | ||
var negate = (options[0] === '+'); | ||
if (negate) { | ||
options = '-' + options.slice(1); // parseOptions needs a '-' prefix | ||
} | ||
options = common.parseOptions(options, { | ||
'e': 'fatal', | ||
'v': 'verbose' | ||
}); | ||
|
||
var key; | ||
if (negate) { | ||
for (key in options) | ||
options[key] = !options[key]; | ||
} | ||
|
||
for (key in options) { | ||
// Only change the global config if `negate` is false and the option is true | ||
// or if `negate` is true and the option is false (aka negate !== option) | ||
if (negate !== options[key]) { | ||
common.config[key] = options[key]; | ||
} | ||
} | ||
return; | ||
} | ||
module.exports = _set; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
var shell = require('..'); | ||
|
||
var assert = require('assert'); | ||
|
||
var oldConfigSilent = shell.config.silent; | ||
shell.config.silent = true; | ||
|
||
shell.rm('-rf', 'tmp'); | ||
shell.mkdir('tmp'); | ||
|
||
// | ||
// Valids | ||
// | ||
|
||
// initial values | ||
assert.strictEqual(oldConfigSilent, false); | ||
assert.strictEqual(shell.config.verbose, false); | ||
assert.strictEqual(shell.config.fatal, false); | ||
|
||
// default behavior | ||
var result = shell.exec('node -e \"require(\'../global\'); ls(\'file_doesnt_exist\'); echo(1234);\"'); | ||
assert.equal(result.code, 0); | ||
assert.equal(result.stdout, '1234\n'); | ||
assert.equal(result.stderr, 'ls: no such file or directory: file_doesnt_exist\n'); | ||
|
||
// set -e | ||
var result = shell.exec('node -e \"require(\'../global\'); set(\'-e\'); ls(\'file_doesnt_exist\'); echo(1234);\"'); | ||
assert.equal(result.code, 1); | ||
assert.equal(result.stdout, ''); | ||
assert.equal(result.stderr, 'ls: no such file or directory: file_doesnt_exist\n'); | ||
|
||
// set -v | ||
var result = shell.exec('node -e \"require(\'../global\'); set(\'-v\'); ls(\'file_doesnt_exist\'); echo(1234);\"'); | ||
assert.equal(result.code, 0); | ||
assert.equal(result.stdout, 'ls file_doesnt_exist\n1234\n'); | ||
assert.equal(result.stderr, 'ls: no such file or directory: file_doesnt_exist\n'); | ||
|
||
// set -ev | ||
var result = shell.exec('node -e \"require(\'../global\'); set(\'-ev\'); ls(\'file_doesnt_exist\'); echo(1234);\"'); | ||
assert.equal(result.code, 1); | ||
assert.equal(result.stdout, 'ls file_doesnt_exist\n'); | ||
assert.equal(result.stderr, 'ls: no such file or directory: file_doesnt_exist\n'); | ||
|
||
// set -e, set +e | ||
var result = shell.exec('node -e \"require(\'../global\'); set(\'-e\'); set(\'+e\'); ls(\'file_doesnt_exist\'); echo(1234);\"'); | ||
assert.equal(result.code, 0); | ||
assert.equal(result.stdout, '1234\n'); | ||
assert.equal(result.stderr, 'ls: no such file or directory: file_doesnt_exist\n'); | ||
|
||
shell.exit(123); | ||
|
||
|