Skip to content

Commit

Permalink
Fixed log, added global hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Sukairo-02 committed Jul 9, 2024
1 parent 92bc449 commit 3449512
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@drizzle-team/brocli",
"type": "module",
"author": "Drizzle Team",
"version": "0.6.0",
"version": "0.7.0",
"description": "Typed CLI command runner",
"license": "Apache-2.0",
"sideEffects": false,
Expand Down
8 changes: 5 additions & 3 deletions src/command-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ export type CommandHandler<
options: TOpts extends Record<string, GenericBuilderInternals> ? TypeOf<TOpts> : undefined,
) => any;

export type EventType = 'pre' | 'post';

export type BroCliConfig = {
argSource?: string[];
help?: HelpHandler;
version?: string | Function;
omitKeysOfUndefinedOptions?: boolean;
hook?: (event: EventType, command: Command) => any;
};

export type GenericCommandHandler = (options?: Record<string, OutputType> | undefined) => any;
Expand Down Expand Up @@ -773,7 +776,9 @@ export const rawCli = async (commands: Command[], config?: BroCliConfig) => {
if (optionResult === 'version') return await executeOrLog(version);

if (optionResult) {
if (config?.hook) await config.hook('pre', command);
await command.handler(command.transform ? await command.transform(optionResult) : optionResult);
if (config?.hook) await config.hook('post', command);
}
return undefined;
};
Expand Down Expand Up @@ -812,9 +817,6 @@ export const test = async <TOpts, THandlerInput>(
): Promise<TestResult<THandlerInput>> => {
try {
const cliParsedArgs: string[] = shellArgs(args);

console.log(cliParsedArgs);

const options = parseOptions(command, cliParsedArgs);

if (options === 'help' || options === 'version') {
Expand Down

0 comments on commit 3449512

Please sign in to comment.