Help us shape the future of Go! Take the 2026 Go Developer Survey

cliengine

package
v0.60.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package cliengine is the shared execution engine behind hive's CLI-backed sources (GitHub via gh, Gitea/Forgejo via tea). A Driver supplies argv construction and JSON parsing; the engine handles execution, caching, and input validation, so adding a new CLI-backed source means writing a new Driver, not a new engine.

Index

Constants

This section is empty.

Variables

View Source
var TimeNow = time.Now

TimeNow is overridable in tests so age formatting is deterministic.

Functions

func DecodeJSON

func DecodeJSON(out []byte, dest any) error

DecodeJSON unmarshals a CLI's JSON object stdout into dest.

func DecodeList

func DecodeList[T any](out []byte) ([]T, error)

DecodeList unmarshals a CLI's JSON array stdout into T entries.

func ShortAge

func ShortAge(t time.Time) string

ShortAge renders a compact age like "3w", "5d", "2mo", or "1y" relative to TimeNow. It returns "" for a zero or future timestamp.

Types

type Config

type Config struct {
	ID          string // registry id and config key (e.g. "issues")
	DisplayName string // picker tab title
	Binary      string // CLI executable (e.g. "gh", "tea")
}

Config declares a driver's static identity and the CLI binary that services it.

type DetailDriver

type DetailDriver interface {
	Driver
	DetailArgs(scope, id string) []string
	ParseDetail(out []byte) (sources.Detail, error)
}

DetailDriver is implemented by drivers whose items have a detail view.

type Driver

type Driver interface {
	Config() Config
	// ListArgs builds the argv (without the leading binary) for a Search
	// against scope ("owner/name"), optionally filtered by query.
	ListArgs(scope, query string, limit int) []string
	// ParseList maps the CLI's JSON stdout into source items.
	ParseList(out []byte) ([]sources.Item, error)
}

Driver defines one CLI-backed source.

type Executor

type Executor interface {
	RunOutputDir(ctx context.Context, dir, cmd string, args ...string) (stdout, stderr []byte, err error)
}

Executor shells out to the CLI, returning stdout and stderr separately: stdout is parsed as JSON and stderr becomes the error message on failure. dir is the working directory (empty inherits the process cwd), letting CLIs resolve their target host/login from a checkout's git remote. *executil.RealExecutor satisfies it via RunOutputDir.

type Options

type Options struct {
	SearchLimit int           // max items per Search (default 30)
	CacheTTL    time.Duration // search cache TTL (default 30s)
}

Options tunes the engine. Zero values use package defaults.

type Source

type Source struct {
	// contains filtered or unexported fields
}

Source is the shared engine executing a Driver against its CLI binary. It implements sources.Source.

func New

func New(logger zerolog.Logger, driver Driver, exec Executor, store kv.KV, opts Options) (*Source, error)

New constructs a Source executing driver. store backs the search cache and is required.

func (*Source) Available

func (c *Source) Available(_ context.Context) bool

Available reports whether the driver's CLI binary is resolvable on PATH.

func (*Source) FetchDetail

func (c *Source) FetchDetail(ctx context.Context, params sources.FetchDetailParams) (sources.Detail, error)

FetchDetail returns the detail view for a single item. params.Scope ("owner/name") and params.ID (a bare item number) are required.

func (*Source) Initialize

func (c *Source) Initialize(_ context.Context) (sources.Manifest, error)

Initialize returns the source's picker manifest.

func (*Source) Name

func (c *Source) Name() string

Name returns the source's stable identifier.

func (*Source) Search

func (c *Source) Search(ctx context.Context, params sources.SearchParams) (sources.SearchResult, error)

Search returns items in the repository identified by params.Scope ("owner/name"), optionally filtered by params.Query. params.Scope is required; params.Dir is the working directory the CLI runs in.

Jump to

Keyboard shortcuts

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