@buddy-js/cli
Version:
A IaC tool to create your [Buddy CI] pipelines programmatically via JS/TS.
52 lines (51 loc) • 1.56 kB
JavaScript
import { Command } from '@oclif/core';
import chalk from 'chalk';
import { render } from 'ink';
import React from 'react';
import { create } from 'zustand';
export class BaseCommand extends Command {
flags;
args;
viewInstance;
async init() {
await super.init();
const { args, flags } = await this.parse({
baseFlags: this.ctor.baseFlags,
flags: this.ctor.flags,
args: this.ctor.args,
enableJsonFlag: this.ctor.enableJsonFlag,
strict: this.ctor.strict
});
this.args = args;
this.flags = flags;
}
// biome-ignore lint/suspicious/useAwait: required by interface
async catch(err) {
process.exitCode = process.exitCode ?? err.exitCode ?? 1;
if (this.jsonEnabled()) {
this.logJson(this.toErrorJson(err));
}
else {
this.logToStderr(chalk.red `❌ ${err.message}`);
}
}
async run() {
const useStore = create(() => this.initialState);
this.viewInstance = this.jsonEnabled()
? undefined
: render(React.createElement(() => {
const store = useStore();
return React.createElement(this.view, store);
}));
const iter = this.handle();
while (true) {
const result = await iter.next();
if (!result.done) {
useStore.setState(result.value);
}
else {
return result.value;
}
}
}
}