Skip to content

Commit

Permalink
Instantiate Commander in Application after every parse()
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Jul 31, 2018
1 parent 2e4367f commit 3a121e2
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/console/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ const { Command } = require('commander');

// Constructor
function Application() {
this.program = null;
this.controllers = [];
}

Application.prototype.setupCommander = function() {
// Commander kann nicht mehrfach verwendet werden, sondern muss immer wieder
// neu geladen werden, siehe https://github.com/tj/commander.js/pull/499
this.program = new Command();
this.program
.version('unknown', '-OV, --original-version');
Expand All @@ -33,16 +40,27 @@ function Application() {
.action(() => {
this.program.output.destroy('Unerwartete Eingabe');
});

for (var i = 0; i < this.controllers.length; i++) {
var controller = this.controllers[i];

controller.register(this.program);
}
}

// class methods
Application.prototype.addController = function(controller) {
controller.register(this.program);
this.controllers.push(controller);
};

Application.prototype.run = function(input, output) {
// Setup commander
this.setupCommander();

this.program.output = output;
this.program.parse(input.getArgv());

this.program = null;
};

// Factory method
Expand Down

0 comments on commit 3a121e2

Please sign in to comment.