Documentation
¶
Overview ¶
Package ghcli implements hive's built-in sources backed by the gh CLI.
Each built-in source is a Driver: static identity/picker properties plus the gh argv construction and JSON parsing behind Search (and, for DetailDrivers, FetchDetail). The shared Source engine executes drivers — shelling out to gh, caching search output, and validating scope/ID inputs — so adding a new gh-backed source means writing a new driver (see issues.go and prs.go), not a new source implementation.
Index ¶
- 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 ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// ID is the source's registry id and config key (e.g. "issues").
ID string
// DisplayName is the picker's tab title.
DisplayName string
}
Config declares a driver's static identity.
type DetailDriver ¶
type DetailDriver interface {
Driver
// DetailArgs builds the gh argv for a FetchDetail call.
DetailArgs(scope, id string) []string
// ParseDetail maps gh's JSON stdout into a Detail.
ParseDetail(out []byte) (sources.Detail, error)
}
DetailDriver is implemented by drivers whose items have a detail view.
type Driver ¶
type Driver interface {
// Config returns the driver's static identity and picker layout.
Config() Config
// ListArgs builds the gh argv (without the leading "gh") for a
// Search against scope ("owner/name"), optionally filtered by query.
ListArgs(scope, query string, limit int) []string
// ParseList maps gh's JSON stdout into source items.
ParseList(out []byte) ([]sources.Item, error)
}
Driver defines one gh-CLI-backed source.
type Executor ¶
type Executor interface {
RunOutput(ctx context.Context, cmd string, args ...string) (stdout, stderr []byte, err error)
}
Executor shells out to gh, returning stdout and stderr separately: stdout is parsed as JSON and stderr becomes the error message on failure. *executil.RealExecutor satisfies it.
type Options ¶
type Options struct {
// SearchLimit caps items per Search call (default 30).
SearchLimit int
// CacheTTL bounds how long raw Search output is cached per
// (scope, query) key (default 30s).
CacheTTL time.Duration
}
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: it shells out to gh via an injected executor, caches raw Search output, and converts gh JSON into source domain types using the driver's parsers.
func New ¶
New constructs a Source executing driver. exec is used to shell out to gh; store backs the search cache and is required.
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, derived from the driver's Config. Every query re-invokes gh, so search is always remote.
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.