From 43cd1c7e529c73180c703d07b60ffa3b628a69ed Mon Sep 17 00:00:00 2001 From: hacksalot Date: Sun, 20 Dec 2015 20:53:21 -0500 Subject: [PATCH] Allow TO keyword to be omitted. If the TO keyword is missing, assume the last file passed in is the destination file. --- src/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 233b43c..68d5c94 100644 --- a/src/index.js +++ b/src/index.js @@ -47,7 +47,6 @@ function main() { opts = getOpts( a ); logMsg( title ); - // Get the action to be performed var params = a._.map( function(p){ return p.toLowerCase().trim(); }); var verb = params[0]; @@ -56,7 +55,7 @@ function main() { return; } - // Get source and dest params + // Find the TO keyword, if any var splitAt = _.indexOf( params, 'to' ); if( splitAt === a._.length - 1 ) { // 'TO' cannot be the last argument @@ -66,8 +65,10 @@ function main() { return; } + // Massage inputs and outputs var src = a._.slice(1, splitAt === -1 ? undefined : splitAt ); var dst = splitAt === -1 ? [] : a._.slice( splitAt + 1 ); + ( splitAt === -1 ) && dst.push( src.pop() ); // Allow omitting TO keyword var parms = [ src, dst, opts, logMsg ]; // Invoke the action