chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 13:34:48 +08:00
commit 77bb5bf71f
3762 changed files with 353249 additions and 0 deletions
@@ -0,0 +1,41 @@
import * as errors from '../errors'
import type { Logger } from '../logger'
import type { CommandArgv, CommandDefinition } from '../typings'
export abstract class BaseCommand<C extends CommandDefinition> {
public constructor(
protected readonly logger: Logger,
protected readonly argv: CommandArgv<C>
) {}
protected abstract run(): Promise<void>
protected bootstrap?(): Promise<void>
protected teardown?(): Promise<void>
private get _cmdName(): string {
return this.constructor.name
}
public async handler(): Promise<{ exitCode: number }> {
let exitCode = 0
try {
if (this.bootstrap) {
await this.bootstrap()
}
await this.run()
} catch (thrown) {
const error = errors.BotpressCLIError.map(thrown)
this.logger.error(error.message)
this.logger.debug(`[${this._cmdName}] ${errors.BotpressCLIError.fullStack(error)}`)
exitCode = 1
} finally {
if (this.teardown) {
await this.teardown()
}
}
return { exitCode }
}
}