mirror of
https://github.com/shelljs/shelljs.git
synced 2026-01-18 16:03:37 +00:00
feat(set): add -f option to disable shell globbing
This commit is contained in:
parent
3ebfe1a070
commit
e2f980e29d
@ -581,6 +581,7 @@ Available options:
|
||||
|
||||
+ `+/-e`: exit upon error (`config.fatal`)
|
||||
+ `+/-v`: verbose: show all commands (`config.verbose`)
|
||||
+ `+/-f`: disable filename expansion (globbing)
|
||||
|
||||
Examples:
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@ var config = {
|
||||
silent: false,
|
||||
fatal: false,
|
||||
verbose: false,
|
||||
noglob: false
|
||||
};
|
||||
exports.config = config;
|
||||
|
||||
@ -258,7 +259,7 @@ function wrap(cmd, fn, options) {
|
||||
else
|
||||
return arg;
|
||||
});
|
||||
if (options && typeof options.idx === 'number')
|
||||
if (!config.noglob && options && typeof options.idx === 'number')
|
||||
args = args.slice(0, options.idx).concat(expand(args.slice(options.idx)));
|
||||
retValue = fn.apply(this, args);
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ var common = require('./common');
|
||||
//@
|
||||
//@ + `+/-e`: exit upon error (`config.fatal`)
|
||||
//@ + `+/-v`: verbose: show all commands (`config.verbose`)
|
||||
//@ + `+/-f`: disable filename expansion (globbing)
|
||||
//@
|
||||
//@ Examples:
|
||||
//@
|
||||
@ -28,7 +29,8 @@ function _set(options) {
|
||||
}
|
||||
options = common.parseOptions(options, {
|
||||
'e': 'fatal',
|
||||
'v': 'verbose'
|
||||
'v': 'verbose',
|
||||
'f': 'noglob'
|
||||
});
|
||||
|
||||
var key;
|
||||
|
||||
11
test/set.js
11
test/set.js
@ -16,6 +16,9 @@ shell.mkdir('tmp');
|
||||
assert.strictEqual(oldConfigSilent, false);
|
||||
assert.strictEqual(shell.config.verbose, false);
|
||||
assert.strictEqual(shell.config.fatal, false);
|
||||
assert.strictEqual(shell.config.noglob, false);
|
||||
|
||||
shell.cp('-R', 'resources/', 'tmp');
|
||||
|
||||
// default behavior
|
||||
var result = shell.exec('node -e \"require(\'../global\'); ls(\'file_doesnt_exist\'); echo(1234);\"');
|
||||
@ -47,6 +50,14 @@ 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 -f
|
||||
shell.set('-f'); // disable globbing
|
||||
shell.rm('tmp/*.txt');
|
||||
assert.ok(shell.error()); // file '*.txt' doesn't exist, so rm() fails
|
||||
shell.set('+f');
|
||||
shell.rm('tmp/*.txt');
|
||||
assert.ok(!shell.error()); // globbing works, so rm succeeds
|
||||
|
||||
shell.exit(123);
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user