cli

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 35 Imported by: 0

Documentation

Overview

Package cli is the cobra-based command surface for adept.

Composition root pattern: NewRoot wires every concrete implementation behind interfaces into a *Deps container, then attaches each subcommand constructed from that container. No package-level state. No init() side effects. Every command receives its dependencies explicitly so it can be tested with mocks.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSkillNotFound      = adept.ErrSkillNotFound
	ErrSkillInvalid       = adept.ErrSkillInvalid
	ErrLockSchemaMismatch = adept.ErrLockSchemaMismatch
	ErrBudgetOverflow     = adept.ErrBudgetOverflow
	ErrAdapterInvalid     = adept.ErrAdapterInvalid
	ErrHarnessUnknown     = adept.ErrHarnessUnknown
	ErrMergeConflict      = adept.ErrMergeConflict
	ErrMergeBaseMissing   = adept.ErrMergeBaseMissing
)

Surface for testing: re-export adept sentinels under the CLI package so command tests can `require.ErrorIs(err, cli.ErrSkillNotFound)` without an extra import.

View Source
var ErrDirty = errors.New("dirty state detected")

ErrDirty is the sentinel returned by commands that report drift but did not fail.

Functions

func Context

func Context() context.Context

Context returns a request context for the duration of one command run. Centralizing this lets future versions wire signal handling or tracing.

func ExitFromError

func ExitFromError(err error) int

ExitFromError maps an error to an exit code.

  • nil -> 0
  • ErrDirty -> 2 (drift / dirty state, used by doctor/status)
  • ErrMergeConflict -> 2 (resolve --strategy merge surfaced conflicts)
  • any other err -> 1

func NewRoot

func NewRoot(b BuildInfo) *cobra.Command

NewRoot builds the cobra root command with all subcommands attached.

func NewTabWriter

func NewTabWriter(w io.Writer) *tabwriter.Writer

NewTabWriter returns a tabwriter pre-configured for human plain output.

Types

type BuildInfo

type BuildInfo struct {
	Version string
	Commit  string
	Date    string
}

BuildInfo is populated by main from -ldflags.

type Deps

type Deps struct {
	Flags *GlobalFlags
	Build BuildInfo

	// Core
	Parser    canonical.Parser
	Validator canonical.Validator
	Loader    canonical.Loader
	Hasher    hash.Hasher
	Config    config.Store
	Status    status.Resolver
	Writer    fsutil.Writer
	Linker    fsutil.Linker
	Git       git.Client
	Log       log.Logger

	// Orchestration
	Registry      harness.Registry
	Orchestrator  harness.Orchestrator
	AdapterLoader adapter.Loader

	// Org + signing
	OrgParser   org.Parser
	Verifier    sign.Verifier
	Signer      sign.Signer
	SignBackend sign.Backend
}

Deps is the dependency container.

Pure constructor injection — every collaborator is an interface, every field is read-only after construction. Commands receive a *Deps and resolve project/library roots per invocation so a single Deps instance services the whole CLI run.

func NewDeps

func NewDeps(gf *GlobalFlags, b BuildInfo) (*Deps, error)

NewDeps wires concrete implementations. This is the only place where concrete types are mentioned — every downstream package consumes interfaces.

func (*Deps) Library

func (d *Deps) Library() (library.Library, error)

Library returns a Library bound to the resolved root.

func (*Deps) LoadUserAdapters

func (d *Deps) LoadUserAdapters() error

LoadUserAdapters reads adapter YAMLs from <library>/adapters/ and registers them. Best-effort: missing directory is not an error.

func (*Deps) Print

func (d *Deps) Print(w io.Writer, r Renderable) error

Print writes the renderable to w using the global --json flag.

func (*Deps) PrintError

func (d *Deps) PrintError(w io.Writer, err error)

PrintError emits an error in the configured format.

func (*Deps) Project

func (d *Deps) Project() (project.Project, error)

Project returns a Project bound to the resolved root.

func (*Deps) ResolveLibraryRoot

func (d *Deps) ResolveLibraryRoot() (string, error)

ResolveLibraryRoot returns --library, then $ADEPT_LIBRARY, then $HOME/.adeptability.

func (*Deps) ResolveProjectRoot

func (d *Deps) ResolveProjectRoot() (string, error)

ResolveProjectRoot returns --project or cwd.

type GlobalFlags

type GlobalFlags struct {
	JSON       bool
	LogLevel   string
	ProjectDir string
	LibraryDir string
}

GlobalFlags hold flags shared by every subcommand.

type Renderable

type Renderable interface {
	JSON() any
	Plain(w io.Writer) error
}

Renderable describes what every command output produces. The CLI picks the concrete renderer based on --json.

Jump to

Keyboard shortcuts

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