feat: refs #5483 Split logging from logic #3

Merged
juan merged 4 commits from 5483-unifyDb into master 2024-01-19 10:54:27 +00:00
3 changed files with 14 additions and 5 deletions
Showing only changes of commit d23a5bee05 - Show all commits

View File

@ -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);
}
}

View File

@ -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;
}
}

1
myt.js
View File

@ -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);