2024-01-04 12:02:40 +00:00
|
|
|
const EventEmitter = require('node:events');
|
|
|
|
|
2022-12-21 12:34:17 +00:00
|
|
|
/**
|
2022-12-21 13:17:50 +00:00
|
|
|
* Base class for Myt commands.
|
2022-12-21 12:34:17 +00:00
|
|
|
*/
|
2024-01-04 12:02:40 +00:00
|
|
|
module.exports = class MytCommand extends EventEmitter {
|
2022-12-29 09:15:02 +00:00
|
|
|
constructor(myt, opts) {
|
2024-01-04 12:02:40 +00:00
|
|
|
super();
|
2022-12-29 09:15:02 +00:00
|
|
|
this.myt = myt;
|
|
|
|
this.opts = opts;
|
2022-12-21 12:34:17 +00:00
|
|
|
}
|
|
|
|
|
2024-01-04 12:02:40 +00:00
|
|
|
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);
|
2022-12-21 12:34:17 +00:00
|
|
|
}
|
2023-08-11 13:41:03 +00:00
|
|
|
|
2024-01-04 12:02:40 +00:00
|
|
|
async run(myt, opts) {
|
|
|
|
throw new Error('run command not defined');
|
2023-08-11 13:41:03 +00:00
|
|
|
}
|
2022-12-21 12:34:17 +00:00
|
|
|
}
|