The cmd/ package implements the kairo CLI command tree using
spf13/cobra. It is the only package
allowed to import cmd/'s siblings plus spf13/cobra; all business
logic lives in internal/.
| File | Concern |
|---|---|
root.go |
Root command, Execute(), verbose, runPiProvider / runStandardProvider |
interfaces.go |
Service interfaces (Process, Wrapper, Update, Crypto) |
deps.go |
Production adapters that satisfy the interfaces |
context.go |
CLIContext, CLIContextFromCmd, MustCLIContextFromCmd, WithCLIContext |
setup.go |
Interactive setup wizard entry point |
setup_config.go |
EnsureConfigDir, LoadConfig, AddAndSaveProvider |
setup_configdir_test.go |
Tests for config-dir resolution |
setup_provider.go |
ProviderDefinition, ResolveProviderName, BuildProviderConfig |
setup_prompts.go |
Interactive prompts (promptForAPIKey, promptForBaseURL, promptForModel, promptForEnvKey, promptForProvider) |
execution.go |
ExecutionConfig, WrapperCmd, buildWrapperCommand |
execution_harness.go |
executePi, runHarnessExec, executeWithAuth, executeWithoutAuth, lookUpHarnessBinary, reportHarnessError, handlePi |
execution_error.go |
handleConfigError, isBinaryOutdatedError, promptUpgrade, handleSecretsError |
execution_orchestrator.go |
OrchestrateExecution adapter, loadRootConfig, printResolveError |
run_provider.go |
runPiProvider, runStandardProvider, buildExecutionConfig |
util.go |
requireConfigDir, loadConfigOrExit, loadConfigOrEmpty |
default.go |
kairo default [provider] command |
list.go |
kairo list command |
delete.go |
kairo delete [provider] command, deleteProviderSecrets |
harness.go |
kairo harness get/set subcommands, resolveHarness |
version.go |
kairo version, checkForUpdates |
update.go |
kairo update command, cosign/checksum verification |
completion.go |
kairo completion command and shell scripts |
providers.go |
kairo providers list and kairo providers refresh commands |
test_helpers.go |
testCmd, testEchoCmd, mockProcess, mockWrapper, mockUpdate, testDeps |
deps_test.go |
NewDeps smoke test and interface conformance |
Execute() creates a new CLIContext and injects it into the root
cobra command via WithCLIContext. Every subcommand retrieves it with
CLIContextFromCmd. A CLIContext holds:
- The resolved config directory (lazily via
ConfigDirResolver). - The verbosity flag.
- A
*config.ConfigCachekeyed by config directory. - A
context.Contextfor the lifetime of the CLI. - A
*Depscontaining the four service interfaces.
PersistentPreRun acts as a safety net: if no CLIContext is found on
the command (e.g. a subcommand invoked outside Execute()), it creates
one. CLIContextFromCmd returns nil when no context is set; callers
should handle nil or use MustCLIContextFromCmd when the command is
guaranteed to be initialized.
Tests should not rely on a shared global; use NewCLIContext() to
construct isolated contexts and inject them with cliCtx.SetDeps(...).
External boundaries (process exec, wrapper script gen, self-update,
crypto) are behind four interfaces in interfaces.go. Production uses
NewDeps() to wire the real implementations. Tests use testDeps to
provide *mockProcess / *mockWrapper / *mockUpdate that record calls
or return canned values. The pattern lets us unit-test the full CLI
flow without spawning real processes.
- Run methods on Cobra commands
cmd *cobra.Commandand accept*cobra.Commandfor output. TheExecutionConfigstruct aggregates everything a downstreamexecute*function needs. - For test isolation, every test file uses
t.TempDir()and constructs a dedicated*CLIContextviaNewCLIContext()instead of sharing global state. - Doc comments on every exported identifier (Google Go Style Guide).
- The
cmd/package imports nointernal/cmd(there is none) and is the only placespf13/cobrais imported.