Navigation Menu

Skip to content

Commit

Permalink
Prepare command in strict order
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Aug 6, 2012
1 parent d0d6988 commit 4b90120
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/command-line.js
Expand Up @@ -12,7 +12,8 @@ var defaultPrivilegedRanges =

function CommandLineInterface() {
this.program = program;
this.reservedOperations = [];
this.reservedUsage = null;
this.reservedOptions = [];
}
CommandLineInterface.prototype = {
get databasePath() {
Expand All @@ -32,25 +33,30 @@ CommandLineInterface.prototype = {

parse: function() {
this.program.version(version);
this.reservedOperations.forEach(function(operation) {
this.program[operation.method].apply(this.program, operation.arguments);

if (this.reservedUsage)
this.program.usage.apply(this.program, this.reservedUsage);

this.reservedOptions.forEach(function(optionArguments) {
this.program.option.apply(this.program, optionArguments);
}, this);

this.program
.option('--database-path <path>',
'database path [' + defaultDatabasePath + ']',
String,
defaultDatabasePath);

this.program.parse(process.argv);

return this;
},
usage: function() {
this.reservedOperations.push({ method: 'usage',
arguments: arguments });
this.reservedUsage = Array.prototype.slice.call(arguments, 0)
return this;
},
option: function() {
this.reservedOperations.push({ method: 'option',
arguments: arguments });
this.reservedOptions.push(Array.prototype.slice.call(arguments, 0));
return this;
},

Expand Down

0 comments on commit 4b90120

Please sign in to comment.