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

cli

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 55 Imported by: 0

Documentation

Overview

Package cli is the ghostbranch command line: it parses flags, builds an engine, and renders results as text or as one JSON envelope. It holds no product logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(args []string, env Env) int

Run executes one command and returns the process exit code.

Types

type AuthStatusResult

type AuthStatusResult struct {
	Source             string       `json:"source"` // GHOSTBRANCH_TOKEN | login | GH_TOKEN | GITHUB_TOKEN | gh auth token | ""
	Account            string       `json:"account"`
	TokenKind          string       `json:"token_kind"`           // auth.Kind; "" with no token
	Valid              string       `json:"valid"`                // "true" | "false" | "unknown" (offline or no token)
	CanPublish         string       `json:"can_publish"`          // push access to Pair: "true" | "false" | "unknown"
	Pair               string       `json:"pair"`                 // the public repo probed; "" when no pair
	Problem            string       `json:"problem"`              // the error code that stopped resolution; ""
	StoredLoginChecked bool         `json:"stored_login_checked"` // false when GHOSTBRANCH_TOKEN is set: the keychain is not touched
	StoredLogin        *StoredLogin `json:"stored_login"`
}

AuthStatusResult is auth status's data. An agent using a person's stored login is the AGENT_ON_PERSON_LOGIN warning, not a field.

type Env

type Env struct {
	Stdout io.Writer
	Stderr io.Writer
	Stdin  io.Reader
	Getenv func(string) string
	// UserHome is the home directory user-level skills go under, and the
	// state directory on macOS and Linux (when GHOSTBRANCH_HOME is unset).
	UserHome func() (string, error)
	// ConsoleUsable is console.Usable(os.Stdin, os.Stderr): stdin and stderr
	// are real terminals, so a person could be asked at the console.
	ConsoleUsable bool
	// OpenConsole opens the console device for the approval code.
	OpenConsole func() (io.ReadWriteCloser, error)
	// ReadSecret reads one line from the opened console device with echo
	// off (agents token's token); DefaultEnv's is console.ReadSecret.
	ReadSecret func(ctx context.Context, dev io.ReadWriteCloser) ([]byte, error)
	// Asker opens the console for guided init's questions: the console
	// device, never stdin. DefaultEnv's is prompt.OnConsole over
	// ConsoleUsable and OpenConsole.
	Asker    func() (prompt.Asker, error)
	Now      func() time.Time
	Sleep    func(context.Context, time.Duration) error
	Rand     io.Reader
	NewForge func(token string) (forge.Forge, error)
	GHToken  func() (string, error)
	// Keychain holds the stored login. nil means no login is consulted or
	// stored; tests use keychain.NewFake().
	Keychain keychain.Store
	// ClientID is the GitHub App's client ID (auth.ClientID). OAuthBaseURL
	// is GitHub's web origin for the device flow and refresh, and
	// HTTPClient the client those calls use.
	ClientID     string
	OAuthBaseURL string
	HTTPClient   *http.Client
	// AppSlug is the GitHub App's URL name (auth.AppSlug), for its install
	// page. OpenBrowser opens a URL in the person's browser, best effort.
	AppSlug      string
	OpenBrowser  func(url string) error
	CwdRemotes   func() []workspace.Remote
	NewScanner   func(leak.Rules) (leak.Scanner, error)
	PollInterval time.Duration
	SettleWindow time.Duration
	OnPush       func(op, remote string, refspecs []string)
	// CIAppearWindow is how long sync looks for the workflow runs its
	// pushes start in the shadow repo, and CIAppearPoll how often.
	CIAppearWindow time.Duration
	CIAppearPoll   time.Duration
	// Executable is this binary's path; the pre-push hook embeds it.
	Executable func() (string, error)
	// Getwd is the directory guard commands act on.
	Getwd func() (string, error)
	// GuardState reports whether the current directory is a checkout of the
	// public repo and whether the guard is installed there (for next).
	GuardState func(public string) (inCheckout, installed bool)
	// ShadowRemote names the remote of the current checkout that points at
	// the shadow repo ("" if none, or if its name is not safe to print into
	// a command), a remote name not yet in use for adding one, and whether
	// the current directory is a git checkout at all.
	ShadowRemote func(shadow string) (remote, free string, inCheckout bool)
	// GitVersion runs `git version` (doctor's tools check); nil means
	// gitx.Version. Build is this binary's version and commit; nil means
	// "(unknown)" for both.
	GitVersion func(context.Context) (string, error)
	Build      func() (version, commit string)
	// StdoutColor and StderrColor say each stream is a terminal that takes
	// ANSI colour and the environment allows it (NO_COLOR, TERM=dumb);
	// DefaultEnv sets them, tests leave them false. The app also drops
	// colour for --json and --no-color. TrueColor picks 24-bit colours.
	StdoutColor, StderrColor, TrueColor bool
	// StderrTerminal says stderr is a terminal (the update reminder).
	// StderrAnimate says it also takes ANSI control and TERM isn't dumb, so
	// progress may animate there (NO_COLOR doesn't matter). StderrWidth is
	// its width in columns, 0 when unknown. DefaultEnv sets them; tests
	// leave them false and nil.
	StderrTerminal, StderrAnimate bool
	StderrWidth                   func() int
	// UpdateWait is the most a command waits at its end for an update look
	// in flight; 0 means 500 ms.
	UpdateWait time.Duration
}

Env is everything the CLI takes from the outside world, so tests can replace any of it.

func DefaultEnv

func DefaultEnv() Env

DefaultEnv is the real process environment.

type ExplainResult

type ExplainResult struct {
	Entries []contract.Entry `json:"entries"`
}

ExplainResult is `ghostbranch explain` output.

type LoginResult

type LoginResult struct {
	Account    string     `json:"account"`     // GitHub login; "" when GitHub didn't say
	Kind       string     `json:"kind"`        // "app" (device flow) | "pat" (pasted)
	TokenKind  string     `json:"token_kind"`  // auth.Kind of the token
	Expires    *time.Time `json:"expires"`     // app tokens; null for a pasted token
	Replaced   bool       `json:"replaced"`    // a stored login was replaced
	InstallURL string     `json:"install_url"` // first app login: where to pick the repos; "" otherwise
	EnvToken   string     `json:"env_token"`   // "GHOSTBRANCH_TOKEN" when it is set and wins over this login
}

type LogoutResult

type LogoutResult struct {
	Removed   bool   `json:"removed"`
	Account   string `json:"account"`
	Kind      string `json:"kind"`       // "app" | "pat" | "" (nothing readable was stored)
	RevokeURL string `json:"revoke_url"` // app logins: where the person revokes the app's access at GitHub
	EnvToken  string `json:"env_token"`  // an env token commands still use: GHOSTBRANCH_TOKEN, GH_TOKEN or GITHUB_TOKEN; ""
}

type RefCommand

type RefCommand struct {
	Path     string    `json:"path"`
	Use      string    `json:"use"`
	Short    string    `json:"short"`
	Long     string    `json:"long"`
	ReadOnly bool      `json:"read_only"`
	Flags    []RefFlag `json:"flags"`
}

RefCommand is one runnable command.

type RefFlag

type RefFlag struct {
	Name      string `json:"name"`
	Shorthand string `json:"shorthand"`
	Type      string `json:"type"`
	Default   string `json:"default"`
	Usage     string `json:"usage"`
}

RefFlag is one flag.

type ReferenceResult

type ReferenceResult struct {
	Commands    []RefCommand `json:"commands"`
	GlobalFlags []RefFlag    `json:"global_flags"`
}

ReferenceResult is the hidden `ghostbranch reference` output: the visible command tree, for the product site's generated reference pages.

type StoredLogin

type StoredLogin struct {
	Account        string     `json:"account"`
	Kind           string     `json:"kind"` // "app" | "pat"
	Expires        *time.Time `json:"expires"`
	RefreshExpires *time.Time `json:"refresh_expires"`
}

type VersionResult

type VersionResult struct {
	Version       string `json:"version"`
	Commit        string `json:"commit"`
	SchemaVersion string `json:"schema_version"`
}

VersionResult is version's data.

Directories

Path Synopsis
Package style adds ANSI colour to human terminal output.
Package style adds ANSI colour to human terminal output.

Jump to

Keyboard shortcuts

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