myt/lib/command.js

31 lines
771 B
JavaScript
Raw Normal View History

const EventEmitter = require('node:events');
/**
2022-12-21 13:17:50 +00:00
* Base class for Myt commands.
*/
module.exports = class MytCommand extends EventEmitter {
constructor(myt, opts) {
super();
this.myt = myt;
this.opts = opts;
}
async cli(myt, opts) {
const reporter = this.constructor.reporter;
if (reporter)
for (const event in reporter) {
const handler = reporter[event];
if (typeof handler == 'string') {
this.on(event, () => console.log(handler));
} else if (handler instanceof Function)
this.on(event, handler);
}
await this.run(myt, opts);
}
async run(myt, opts) {
throw new Error('run command not defined');
}
}