cli

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package cli is lore's driving adapter: it translates cobra commands into use case calls and renders results. stdout carries data (human text, or JSON with --json); logs and errors go to stderr. It holds no business logic and imports no storage/provider adapters — the composition root wires those into Deps.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExitCode

func ExitCode(err error) int

ExitCode maps a command error to a lore exit code: 0 ok, 1 runtime, 2 usage, 3 not found, 4 invariant violation.

func NewRootCommand

func NewRootCommand(build Builder, version string, out, errOut io.Writer) *cobra.Command

NewRootCommand builds the lore command tree, writing data to out and errors to errOut. The build function is invoked once before any subcommand runs to produce the dependencies the commands share. Errors returned from Execute map to process exit codes via ExitCode.

Types

type Builder

type Builder func(context.Context, GlobalOptions) (Deps, error)

Builder constructs the runtime dependencies from the resolved global options. The composition root provides it; the root command invokes it once, in PersistentPreRunE — after global flags are parsed — so --config can redirect configuration loading before anything is wired.

type Deps

type Deps struct {
	Catalog *app.Catalog
	Ingest  *app.Ingestor
	Sync    *app.Syncer
	Query   *app.Querier
	Ask     *app.Asker
	// Rerank is nil when no rerank provider is configured; commands that need it
	// (rerank, query/ask --rerank) report a usage error in that case.
	Rerank *app.Reranker
	Remove *app.Remover
	// Tokens counts tokens for --budget token-bounded retrieval (query/ask).
	Tokens app.TokenCounter
	// Export and Import move a collection to/from a single portable artifact file.
	Export *app.Exporter
	Import *app.Importer
	// Index is the vector index, exposed read-only for the mcp server's
	// collection_status chunk count. Other commands reach vectors via use cases.
	Index app.VectorIndex
	// Log is lore's configured logger (stderr), handed to the long-running mcp
	// server so it honors --log-level/--log-format; nil is tolerated.
	Log *slog.Logger
}

Deps are the use cases the commands invoke, wired by the composition root.

type GlobalOptions

type GlobalOptions struct {
	ConfigPath string // --config; empty means the default location
	LogLevel   string // --log-level; empty means unset
	LogFormat  string // --log-format; empty means unset
	Verbose    bool   // -v/--verbose
	NoCache    bool   // --no-cache; bypass the answer cache for this run
}

GlobalOptions are the resolved global flags the composition root needs to build the runtime: which config file to read and how to log. The Builder turns these into Deps.

Jump to

Keyboard shortcuts

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