Navigation Menu

Skip to content

Commit

Permalink
Report error when invalid combination of options are specified to gcs…
Browse files Browse the repository at this point in the history
…-configure-text-options.
  • Loading branch information
piroor committed Aug 9, 2012
1 parent 60aa027 commit a6451af
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
23 changes: 23 additions & 0 deletions bin/gcs-configure-text-options
Expand Up @@ -47,6 +47,29 @@ function strip(string) {
return string.replace(/^\s+|\s+$/g, '');
}

var printOptions = ['printStems', 'printStopwords', 'printSynonyms'];
var loadOptions = ['stems', 'stopwords', 'synonyms'];

if (commandLine.hasTooManyExclusiveOptions(printOptions)) {
console.log('Too many options. ' +
'You must specify just one option from ' +
'--print-stems, --print-stopwords, or --print-synonyms.');
process.exit(1);
return;
}

if (printOptions.some(function(option) {
return commandLine.options[option];
}) &&
loadOptions.some(function(option) {
return commandLine.options[option];
})) {
console.log('Too many options. ' +
'You cannot do print and load on the same time.');
process.exit(1);
return;
}

if (commandLine.options.printStems) {
} else if (commandLine.options.printStopwords) {
} else if (commandLine.options.printSynonyms) {
Expand Down
7 changes: 7 additions & 0 deletions lib/command-line.js
Expand Up @@ -85,6 +85,13 @@ CommandLineInterface.prototype = {
}
return this;
},

hasTooManyExclusiveOptions: function(options) {
var havingOptions = options.map(function(option) {
return this.option[option] ? '*' : '' ;
}, this);
return havingOptions.join('').length > 1;
}
};
exports.CommandLineInterface = CommandLineInterface;

Expand Down

0 comments on commit a6451af

Please sign in to comment.