pub fn dispatch(cli: &Cli) -> Result<()>Expand description
Dispatches a parsed Cli to the matching subcommand handler.
Ported from cmd/factory.go’s Before hook running ahead of every
subcommand’s Action: installs a logger and resolves the config file
path before matching on the subcommand, mirroring createBeforeHook.
The resolved GlobalConfig
is threaded into a single Context built once here and passed down
to every subcommand handler that needs it (commands that don’t load
configuration, like version/registry, ignore it). This used to be
rebuilt from Context::default inside each handler, which silently
discarded before_hook’s resolved config path – every config-reading
real binary invocation failed with “no global config in context”
despite each handler’s own unit tests passing (they call the inner
run_* functions directly with a manually-built Context, bypassing
this wrapper). Caught by the nix flake check NixOS VM test added in
nix/tests/e2e-mock.nix; see book/src/project/testing.md.