ghcli

package
v0.55.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 9 Imported by: 0

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

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.

func Issues

func Issues() DetailDriver

Issues returns the built-in GitHub issues driver.

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.

func PRs

func PRs() Driver

PRs returns the built-in GitHub pull requests driver.

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

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

New constructs a Source executing driver. exec is used to shell out to gh; store backs the search cache and is required.

func (*Source) Available

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

Available reports whether the gh CLI 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, derived from the driver's Config. Every query re-invokes gh, so search is always remote.

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.

Jump to

Keyboard shortcuts

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