Skip to content

Commit 3a121e2

Browse files
committed
Instantiate Commander in Application after every parse()
@see tj/commander.js#499
1 parent 2e4367f commit 3a121e2

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/console/application.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ const { Command } = require('commander');
2323

2424
// Constructor
2525
function Application() {
26+
this.program = null;
27+
this.controllers = [];
28+
}
29+
30+
Application.prototype.setupCommander = function() {
31+
// Commander kann nicht mehrfach verwendet werden, sondern muss immer wieder
32+
// neu geladen werden, siehe https://github.com/tj/commander.js/pull/499
2633
this.program = new Command();
2734
this.program
2835
.version('unknown', '-OV, --original-version');
@@ -33,16 +40,27 @@ function Application() {
3340
.action(() => {
3441
this.program.output.destroy('Unerwartete Eingabe');
3542
});
43+
44+
for (var i = 0; i < this.controllers.length; i++) {
45+
var controller = this.controllers[i];
46+
47+
controller.register(this.program);
48+
}
3649
}
3750

3851
// class methods
3952
Application.prototype.addController = function(controller) {
40-
controller.register(this.program);
53+
this.controllers.push(controller);
4154
};
4255

4356
Application.prototype.run = function(input, output) {
57+
// Setup commander
58+
this.setupCommander();
59+
4460
this.program.output = output;
4561
this.program.parse(input.getArgv());
62+
63+
this.program = null;
4664
};
4765

4866
// Factory method

0 commit comments

Comments
 (0)