feat: refs #5483 Split logging from logic #3
|
@ -1,13 +1,11 @@
|
||||||
const EventEmitter = require('node:events');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for Myt commands.
|
* Base class for Myt commands.
|
||||||
*/
|
*/
|
||||||
module.exports = class MytCommand extends EventEmitter {
|
module.exports = class MytCommand{
|
||||||
constructor(myt, opts) {
|
constructor(myt, opts) {
|
||||||
super();
|
|
||||||
this.myt = myt;
|
this.myt = myt;
|
||||||
this.opts = opts;
|
this.opts = opts;
|
||||||
|
this.handlers = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
async cli(myt, opts) {
|
async cli(myt, opts) {
|
||||||
|
@ -27,4 +25,13 @@ module.exports = class MytCommand extends EventEmitter {
|
||||||
async run(myt, opts) {
|
async run(myt, opts) {
|
||||||
throw new Error('run command not defined');
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,7 @@ class Run extends Command {
|
||||||
this.emit('runningContainer');
|
this.emit('runningContainer');
|
||||||
|
|
||||||
const isRandom = opts.random;
|
const isRandom = opts.random;
|
||||||
const dbConfig = Object.assign({}, opts.dbConfig);
|
const dbConfig = opts.dbConfig;
|
||||||
|
|
||||||
let runOptions;
|
let runOptions;
|
||||||
|
|
||||||
|
@ -193,6 +193,7 @@ class Run extends Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await conn.end();
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
1
myt.js
1
myt.js
|
@ -165,6 +165,7 @@ class Myt {
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(Command, opts) {
|
async run(Command, opts) {
|
||||||
|
if (!opts) opts = this.opts;
|
||||||
const command = new Command(this, opts);
|
const command = new Command(this, opts);
|
||||||
if (this.cliMode)
|
if (this.cliMode)
|
||||||
return await command.cli(this, opts);
|
return await command.cli(this, opts);
|
||||||
|
|
Loading…
Reference in New Issue