core

package
v0.45.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package core exposes the CLI's injectable dependency container and root builder so a downstream package can compose its own binaries without editing the built-in command tree. Everything here is importable (unlike internal/).

Migration ordering is deliberately NOT modelled here: the Python runner (`python -m jentic_one.migrations.run`) owns the target set and its upgrade/rollback order via its DB_TARGETS registry. The CLI only invokes that runner (with a direction flag); it never maintains its own target list.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRootCmd

func NewRootCmd(deps *AppContainer, build TreeBuilder) *cobra.Command

NewRootCmd builds a root command tree using the injected container. `build` assembles the built-in command set (supplied by internal/cli/*); any ExtraCommands are appended last so they never shadow built-in commands. The container's streams are wired onto the root so both cobra's own output and core.Run's error output honor the injected Out/Err/In.

func Run

func Run(root *cobra.Command) (code int)

Run executes a root command with a signal-cancelled context and returns the process exit code. It is the shared entry point for the built-in binaries and any downstream binary composed via NewRootCmd, so exit-code / signal semantics stay identical. Callers typically do: os.Exit(core.Run(root)).

func RunTree added in v0.32.0

func RunTree(root *cobra.Command, mapErr func(*cobra.Command, error) error) (code int)

RunTree is Run with an optional error mapper applied to the error returned by Execute before exit-code/render handling. The mapper lets the internal layer convert cobra-native parse errors (unknown command/flag, bad arg count, missing required flag) — which cobra returns from Execute rather than through a command's RunE, so decorateCodedErrors can't see them — into a typed *ux.CodedError so an agent gets a closed error_code + envelope instead of raw "error: …" text (AGT-20). pkg/core stays free of internal/ux: the mapper both classifies AND renders (returning an already-reported ExitCoder), so Run only needs the ExitCoder it already understands. A nil mapper preserves the legacy behavior exactly.

Types

type AppContainer

type AppContainer struct {
	// In, Out, and Err are the standard streams (overridable in tests / by a
	// downstream). NewRootCmd wires them onto the root command, so command
	// bodies should read cmd.InOrStdin() / cmd.OutOrStdout() / cmd.ErrOrStderr().
	In  io.Reader
	Out io.Writer
	Err io.Writer

	// ExtraCommands are extra command groups appended after the built-in tree.
	// nil for the default binaries.
	ExtraCommands []CommandFactory
}

AppContainer is the injected dependency set for the CLI command tree. The default binaries build a plain container; a downstream package builds its own and adds commands via ExtraCommands.

It deliberately carries NO migration-target list (see the package doc).

type CommandFactory

type CommandFactory func(deps *AppContainer) *cobra.Command

CommandFactory builds a cobra command from the injected container. Extra command groups are supplied as factories so they are constructed against the same container (paths, streams) the built-in tree uses.

type ExitCoder

type ExitCoder interface {
	error
	ExitCode() int
}

ExitCoder is an error that carries a process exit code. A wrapped child command's non-zero exit is surfaced as one of these so Run can mirror it verbatim (rather than reporting it as a generic CLI error). internal/cli/cmdcore's exit-code error implements this; downstream errors may too.

type TreeBuilder

type TreeBuilder func(deps *AppContainer) *cobra.Command

TreeBuilder builds the fully-configured root command for a binary from the injected container. internal/cli/* supplies this so `core` never imports `internal/*` — which keeps the dependency edge one-directional (internal/cli/* → pkg/core) and avoids an import cycle.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL