diff --git a/lib/command.js b/lib/command.js index 46fbbc3..65b96e6 100644 --- a/lib/command.js +++ b/lib/command.js @@ -1,13 +1,11 @@ -const EventEmitter = require('node:events'); - /** * Base class for Myt commands. */ -module.exports = class MytCommand extends EventEmitter { +module.exports = class MytCommand{ constructor(myt, opts) { - super(); this.myt = myt; this.opts = opts; + this.handlers = {}; } async cli(myt, opts) { @@ -27,4 +25,13 @@ module.exports = class MytCommand extends EventEmitter { async run(myt, opts) { throw new Error('run command not defined'); } + + on(event, handler) { + this.handlers[event] = handler; + } + + emit(event, ...args) { + const handler = this.handlers[event]; + if (handler) handler (...args); + } } diff --git a/myt-run.js b/myt-run.js index 4a4bf82..3b6591e 100644 --- a/myt-run.js +++ b/myt-run.js @@ -87,7 +87,7 @@ class Run extends Command { this.emit('runningContainer'); const isRandom = opts.random; - const dbConfig = Object.assign({}, opts.dbConfig); + const dbConfig = opts.dbConfig; let runOptions; @@ -193,6 +193,7 @@ class Run extends Command { } } + await conn.end(); return server; } } diff --git a/myt.js b/myt.js index 0f425b8..8bf24f5 100755 --- a/myt.js +++ b/myt.js @@ -165,6 +165,7 @@ class Myt { } async run(Command, opts) { + if (!opts) opts = this.opts; const command = new Command(this, opts); if (this.cliMode) return await command.cli(this, opts);