Open
Description
inspired from #98 (comment) by @jgoux
With plugins, we can allow them to intercept to different hooks but also preserve their context. We can extend to more hooks if needed.
Example:
const telemetryPlugin = defineCittyPlugin(() => {
const telemetry = new TelemetryClient();
return {
name: 'telemetry',
async setup() {
telemetry.init();
await telemetry.captureEvent(`$command:${ctx.cmd.meta.name}:start`);
},
async cleanup() {
await telemetry.captureEvent(`$command:${ctx.cmd.meta.name}:end`);
telemetry.flush();
}
}
})
defineCommand({
meta: {
name: "hello",
version: "1.0.0",
description: "My Awesome CLI App",
},
plugins: [telemetryPlugin],
run({ args }) {
console.log(`${args.friendly ? "Hi" : "Greetings"} ${args.name}!`);
},
})