Skip to content

Commit

Permalink
Exception handling for files argument
Browse files Browse the repository at this point in the history
  • Loading branch information
kyungilpark committed Jun 28, 2019
1 parent 2a06276 commit e103408
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,10 @@ function parseArgs(options) {// \/\\*(?:(?!\\*\/)|.|\\n)*?\\*\/

// what's left in argv
args.files = process.argv.slice(parser.optind());
if (args.files.length < 1) {
console.log("One or more files ​​are required.");
info.help();
process.exit(1);
}
return args;
}
2 changes: 1 addition & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var log = new Logger(Logger.WARNING);
var path = require('path');

exports.findCommonBase = function(files) {
if (!files || files.length === 1) return '';
if (!files || files.length < 2) return '';
var lastSlash = files[0].lastIndexOf(path.sep);
if (!lastSlash) return '';
var first = files[0].substr(0, lastSlash + 1);
Expand Down
6 changes: 5 additions & 1 deletion test/util_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ exports['util'] = {
// Store value of current path separator (environment-specific)
var sep = path.sep;

test.expect(6);
test.expect(7);

// Explicitly set path for OSX/*nix environment path prefixing
path.sep = '/';
Expand Down Expand Up @@ -71,6 +71,10 @@ exports['util'] = {
];
test.equal(util.findCommonBase(files), '', 'should not find a prefix for files in the current directory');

files = [];
test.equal(util.findCommonBase(files), '', 'should not cause an error for no files');


// Explicitly set path for Windows environment path prefixing
path.sep = '\\';

Expand Down

0 comments on commit e103408

Please sign in to comment.