mirror of
https://github.com/shelljs/shelljs.git
synced 2026-01-18 16:03:37 +00:00
ls, cp pass
This commit is contained in:
parent
34bfe3ba1f
commit
ca71bb8380
13
shell.js
13
shell.js
@ -178,8 +178,10 @@ function _cp(options, sources, dest) {
|
||||
if (arguments.length < 3) {
|
||||
error('missing <source> and/or <dest>');
|
||||
} else if (arguments.length > 3) {
|
||||
sources = [].slice.call(arguments, 1, arguments.length - 2);
|
||||
sources = [].slice.call(arguments, 1, arguments.length - 1);
|
||||
dest = arguments[arguments.length - 1];
|
||||
} else {
|
||||
sources = [sources];
|
||||
}
|
||||
|
||||
// Dest is not existing dir, but multiple sources given
|
||||
@ -393,15 +395,16 @@ function _mkdir(options, str) {
|
||||
exports.mkdir = wrap('mkdir', _mkdir);
|
||||
|
||||
//@
|
||||
//@ #### cat('file [file ...]')
|
||||
//@ #### cat(file [, file ...]')
|
||||
//@ Returns a string containing the given file, or a concatenated string
|
||||
//@ containing the files if more than one file is given (a new line character is
|
||||
//@ introduced between each file). Wildcards are accepted.
|
||||
function _cat(options, str) {
|
||||
var files = parsePaths(str),
|
||||
//@ introduced between each file). Wildcard `*` accepted.
|
||||
function _cat(options, files) {
|
||||
var files = [].slice.call(arguments, 1),
|
||||
cat = '';
|
||||
|
||||
files = expand(files);
|
||||
|
||||
if (files.length === 0)
|
||||
error('no files given');
|
||||
|
||||
|
||||
@ -84,7 +84,7 @@ assert.equal(fs.existsSync('tmp/file2'), true);
|
||||
shell.rm('-rf', 'tmp/*');
|
||||
shell.cp('-R', 'resources/cp', 'tmp');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.deepEqual(shell.ls('-R', 'resources/cp'), ls('-R', 'tmp/cp'));
|
||||
assert.deepEqual(shell.ls('-R', 'resources/cp'), shell.ls('-R', 'tmp/cp'));
|
||||
|
||||
//recursive, everything exists, no force flag
|
||||
shell.rm('-rf', 'tmp/*')
|
||||
|
||||
13
test/ls.js
13
test/ls.js
@ -34,7 +34,7 @@ assert.equal(shell.error(), null);
|
||||
|
||||
// no args
|
||||
shell.cd('resources/ls');
|
||||
var result = shell.ls().hash;
|
||||
var result = shell.ls();
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal('file1' in result, true);
|
||||
assert.equal('file2' in result, true);
|
||||
@ -46,7 +46,7 @@ assert.equal(Object.keys(result).length, 6);
|
||||
shell.cd('../..');
|
||||
|
||||
// simple arg
|
||||
var result = shell.ls('resources/ls').hash;
|
||||
var result = shell.ls('resources/ls');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal('file1' in result, true);
|
||||
assert.equal('file2' in result, true);
|
||||
@ -124,6 +124,15 @@ assert.equal('resources/ls/file2.js' in result, true);
|
||||
assert.equal('resources/ls/a_dir/b_dir' in result, true);
|
||||
assert.equal('resources/ls/a_dir/nada' in result, true);
|
||||
|
||||
// wildcard for both paths, array
|
||||
var result = shell.ls(['resources/ls/f*le*.js', 'resources/ls/a_dir/*']);
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(Object.keys(result).length, 4);
|
||||
assert.equal('resources/ls/file1.js' in result, true);
|
||||
assert.equal('resources/ls/file2.js' in result, true);
|
||||
assert.equal('resources/ls/a_dir/b_dir' in result, true);
|
||||
assert.equal('resources/ls/a_dir/nada' in result, true);
|
||||
|
||||
// recursive, no path
|
||||
shell.cd('resources/ls');
|
||||
var result = shell.ls('-R');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user