diff --git a/shell.js b/shell.js index 56c44f1..2bfe702 100644 --- a/shell.js +++ b/shell.js @@ -178,8 +178,10 @@ function _cp(options, sources, dest) { if (arguments.length < 3) { error('missing and/or '); } 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'); diff --git a/test/cp.js b/test/cp.js index a0a75af..6228074 100644 --- a/test/cp.js +++ b/test/cp.js @@ -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/*') diff --git a/test/ls.js b/test/ls.js index d28dbfa..b1f1bcd 100644 --- a/test/ls.js +++ b/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');