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 ¶
- Variables
- func DecodeJSON(out []byte, dest any) error
- func DecodeList[T any](out []byte) ([]T, error)
- func ShortAge(t time.Time) string
- type Config
- type DetailDriver
- type Driver
- type Executor
- type Options
- type Source
- func (c *Source) Available(_ context.Context) bool
- func (c *Source) FetchDetail(ctx context.Context, params sources.FetchDetailParams) (sources.Detail, error)
- func (c *Source) Initialize(_ context.Context) (sources.Manifest, error)
- func (c *Source) Name() string
- func (c *Source) Search(ctx context.Context, params sources.SearchParams) (sources.SearchResult, error)
Constants ¶
This section is empty.
Variables ¶
var TimeNow = time.Now
TimeNow is overridable in tests so age formatting is deterministic.
Functions ¶
func DecodeJSON ¶
DecodeJSON unmarshals a CLI's JSON object stdout into dest.
func DecodeList ¶
DecodeList unmarshals a CLI's JSON array stdout into T entries.
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 (*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 ¶
Initialize returns the source's picker manifest.
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.