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

config

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Terminal term.Term
	Out      *os.File
	Err      *os.File
	In       *os.File

	ColorSuccess func(string) string
	ColorError   func(string) string
	ColorWarning func(string) string
	ColorBold    func(string) string
	ColorBlue    func(string) string
	ColorMagenta func(string) string
	ColorCyan    func(string) string
	ColorGray    func(string) string

	// GitHubClientOverride, when non-nil, is returned by GitHubClient()
	// instead of creating a real client. Used in tests to inject a MockClient.
	GitHubClientOverride ghapi.ClientOps

	// ForceInteractive, when true, makes IsInteractive() return true
	// regardless of the terminal state. Used in tests.
	ForceInteractive bool

	// SelectFn, when non-nil, is called instead of prompting via the
	// terminal. Used in tests to simulate interactive selection.
	SelectFn func(prompt, defaultValue string, options []string) (int, error)

	// ConfirmFn, when non-nil, is called instead of prompting via the
	// terminal. Used in tests to simulate yes/no confirmation prompts.
	ConfirmFn func(prompt string, defaultValue bool) (bool, error)

	// InputFn, when non-nil, is called instead of prompting via the
	// terminal. Used in tests to simulate text input prompts.
	InputFn func(prompt, defaultValue string) (string, error)

	// TokenForHostFn, when non-nil, is called instead of auth.TokenForHost
	// to retrieve the auth token for a given GitHub host. Used in tests to
	// simulate different token types (OAuth vs PAT).
	TokenForHostFn func(host string) (string, string)

	// RepoOverride, when non-nil, is returned by Repo() instead of
	// calling repository.Current(). Used in tests to avoid depending on
	// the real git repo context.
	RepoOverride *repository.Repository
}

Config holds shared state for all commands.

func New

func New() *Config

New creates a new Config with terminal-aware output and color support.

func NewTestConfig

func NewTestConfig() (*Config, *os.File, *os.File)

NewTestConfig creates a Config suitable for testing with captured output buffers. Color functions are no-ops, and the config is non-interactive.

func (*Config) Errorf

func (c *Config) Errorf(format string, args ...any)

func (*Config) GitHubClient

func (c *Config) GitHubClient() (ghapi.ClientOps, error)

func (*Config) Infof

func (c *Config) Infof(format string, args ...any)

func (*Config) IsInteractive

func (c *Config) IsInteractive() bool

func (*Config) IsPersonalAccessToken added in v0.0.6

func (cfg *Config) IsPersonalAccessToken() bool

IsPersonalAccessToken reports whether the active token for the current repository's host is a personal access token (classic or fine-grained) rather than an OAuth token from `gh auth login`.

Token prefix conventions:

gho_        → OAuth token (supported)
ghs_        → GitHub App installation token (supported)
ghp_        → Classic personal access token (NOT supported)
github_pat_ → Fine-grained personal access token (NOT supported)

func (*Config) Outf

func (c *Config) Outf(format string, args ...any)
func (c *Config) PRLink(number int, url string) string

PRLink formats a PR number as a clickable, underlined terminal hyperlink. Falls back to plain "#N" when color is disabled.

func (*Config) Printf

func (c *Config) Printf(format string, args ...any)

func (*Config) Repo

func (c *Config) Repo() (repository.Repository, error)

func (*Config) RepoHost added in v0.0.6

func (cfg *Config) RepoHost() string

RepoHost returns the GitHub host for the current repository, or an empty string if it cannot be determined (e.g. not inside a git repo).

func (*Config) Successf

func (c *Config) Successf(format string, args ...any)

func (*Config) WarnIfPAT added in v0.0.6

func (cfg *Config) WarnIfPAT() bool

WarnIfPAT checks whether the active token is a personal access token and, if so, prints a warning explaining that PATs are not supported by gh stack. Returns true when a PAT is detected.

func (*Config) Warningf

func (c *Config) Warningf(format string, args ...any)

Jump to

Keyboard shortcuts

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