Skip to main content

Module hooks

Module hooks 

Source
Expand description

The caproni root command’s Before/After hook equivalents.

Ported from cmd/factory.go’s createBeforeHook/createAfterHook. urfave/cli/v3’s Before hook runs once before any subcommand’s Action, resolving the effective config file path and installing a logger; clap has no direct equivalent (there is no single “before dispatch” callback slot on a derived Parser), so this module exposes the same two concerns as plain functions that super::commands::dispatch calls explicitly before matching on the subcommand.

Deviation from Go: before_hook covers only config-file resolution (exactly what TestBeforeHook asserts on), not logger setup. Go’s createBeforeHook closure does both in one step, but that closure is only ever invoked once per real process. This port’s before_hook is unit-tested directly (see tests/factory.rs), and xianyun_executor::logging’s tracing::Dispatch can only be installed as the process-wide default once – calling it from before_hook would make the second in-process test call fail. Logger initialization is therefore split out into init_logging, which dispatch() calls once per real invocation and which tolerates being called more than once (by ignoring the “already set” error) rather than panicking, so it stays safe to call from tests too.

Functions§

before_hook
Ported from createBeforeHook’s config-resolution half: if no --config-file was given explicitly and the resolved subcommand needs one, searches parent directories for caproni.yaml (find_config_file).
init_logging
Ported from createBeforeHook’s logger-setup half. Installs a tracing dispatcher built from Cli’s logging flags as the process-wide default.
should_load_config
Ported from shouldLoadConfig.