Hooks

What are Hooks?

Hooks are additional functions that you can instruct your OCLIF commands to execute at different parts of their lifecycle.
The OCLIF documentation provides a detailed explanation here.
We use an init hook to ensure the application is bootstrapped and injectable prior to each command.

Available Lifecycle Events

Event
Description
init
Runs when the CLI is initialized before a command is found to run.
prerun
Runs after init and after the command is found, but just before running the command itself.
postrun
Runs after the command only if the command finishes with no error.
command_not_found
Runs if a command is not found before the error is displayed.

Composing Hooks

Hooks should be added to your application's hooks directory under the correct lifecycle subfolder.
1
const hook: Hook<"init"> = async () => {
2
// Perform your hook logic...
3
}
4
5
export default hook
Copied!