cmdutil

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CancelError = errors.New("CancelError")

CancelError signals user-initiated cancellation

View Source
var PendingError = errors.New("PendingError")

PendingError signals nothing failed but something is pending

View Source
var SilentError = errors.New("SilentError")

SilentError is an error that triggers exit code 1 without any error messaging

Functions

func AddFormatFlags

func AddFormatFlags(cmd *cobra.Command, exportTarget *Exporter)

func AddGroup

func AddGroup(parent *cobra.Command, title string, cmds ...*cobra.Command)

func AddJSONFlags

func AddJSONFlags(cmd *cobra.Command, exportTarget *Exporter, fields []string)

func AddJSONFlagsWithoutShorthand

func AddJSONFlagsWithoutShorthand(cmd *cobra.Command, exportTarget *Exporter, fields []string)

func CheckAuth

func CheckAuth(cfg gh.Config) bool

func DetermineEditor

func DetermineEditor(cf func() (gh.Config, error)) (string, error)

TODO: consider passing via Factory TODO: support per-hostname settings

func DisableAuthCheck

func DisableAuthCheck(cmd *cobra.Command)

func DisableAuthCheckFlag

func DisableAuthCheckFlag(flag *pflag.Flag)

func EnableRepoOverride

func EnableRepoOverride(cmd *cobra.Command, f *Factory)

func ExactArgs

func ExactArgs(n int, msg string) cobra.PositionalArgs

func FlagErrorWrap

func FlagErrorWrap(err error) error

FlagErrorWrap returns a new FlagError that wraps the specified error.

func FlagErrorf

func FlagErrorf(format string, args ...interface{}) error

FlagErrorf returns a new FlagError that wraps an error produced by fmt.Errorf(format, args...).

func GlobPaths

func GlobPaths(patterns []string) ([]string, error)

GlobPaths expands a list of file patterns into a list of file paths. If no files match a pattern, that pattern will return an error. If no pattern is passed, this returns an empty list and no error.

For information on supported glob patterns, see https://pkg.go.dev/path/filepath#Match

func IsAuthCheckEnabled

func IsAuthCheckEnabled(cmd *cobra.Command) bool

func IsUserCancellation

func IsUserCancellation(err error) bool

func MinimumArgs

func MinimumArgs(n int, msg string) cobra.PositionalArgs

func MutuallyExclusive

func MutuallyExclusive(message string, conditions ...bool) error

func NewJSONExporter

func NewJSONExporter() *jsonExporter

NewJSONExporter returns an Exporter to emit JSON.

func NilBoolFlag

func NilBoolFlag(cmd *cobra.Command, p **bool, name string, shorthand string, usage string) *pflag.Flag

NilBoolFlag defines a new flag with a bool pointer receiver. This is useful for differentiating between the flag being explicitly set to a false value and the flag not being passed at all.

func NilStringFlag

func NilStringFlag(cmd *cobra.Command, p **string, name string, shorthand string, usage string) *pflag.Flag

NilStringFlag defines a new flag with a string pointer receiver. This is useful for differentiating between the flag being set to a blank value and the flag not being passed at all.

func NoArgsQuoteReminder

func NoArgsQuoteReminder(cmd *cobra.Command, args []string) error

func OverrideBaseRepoFunc

func OverrideBaseRepoFunc(f *Factory, override string) func() (bbrepo.Interface, error)

func Partition

func Partition[T any](slice []T, predicate func(T) bool) ([]T, []T)

Partition takes a slice of any type T and separates it into two slices of the same type based on the provided predicate function. Any item that returns true for the predicate will be included in the first slice returned, and any item that returns false for the predicate will be included in the second slice returned.

func ReadFile

func ReadFile(filename string, stdin io.ReadCloser) ([]byte, error)

func RegisterBranchCompletionFlags

func RegisterBranchCompletionFlags(gitc gitClient, cmd *cobra.Command, flags ...string) error

RegisterBranchCompletionFlags suggests and autocompletes known remote git branches for flags passed

func StringEnumFlag

func StringEnumFlag(cmd *cobra.Command, p *string, name, shorthand, defaultValue string, options []string, usage string) *pflag.Flag

StringEnumFlag defines a new string flag that only allows values listed in options.

func StringSliceEnumFlag

func StringSliceEnumFlag(cmd *cobra.Command, p *[]string, name, shorthand string, defaultValues, options []string, usage string) *pflag.Flag

func StructExportData

func StructExportData(s interface{}, fields []string) map[string]interface{}

Basic function that can be used with structs that need to implement the exportable interface. It has numerous limitations so verify that it works as expected with the struct and fields you want to export. If it does not, then implementing a custom ExportData method is necessary. Perhaps this should be moved up into exportData for the case when a struct does not implement the exportable interface, but for now it will need to be explicitly used.

Types

type Exporter

type Exporter interface {
	Fields() []string
	Write(io *iostreams.IOStreams, data interface{}) error
}

type Factory

type Factory struct {
	AppVersion     string
	ExecutableName string

	Browser   browser.Browser
	GitClient *git.Client
	IOStreams *iostreams.IOStreams
	Prompter  prompter.Prompter

	BaseRepo   func() (bbrepo.Interface, error)
	Branch     func() (string, error)
	Config     func() (gh.Config, error)
	HttpClient func() (*http.Client, error)
	// PlainHttpClient is a special HTTP client that does not automatically set
	// auth and other headers. This is meant to be used in situations where the
	// client needs to specify the headers itself (e.g. during login).
	PlainHttpClient func() (*http.Client, error)
	Remotes         func() (context.Remotes, error)
}

func (*Factory) Executable

func (f *Factory) Executable() string

Executable is the path to the currently invoked binary

type FlagError

type FlagError struct {
	// contains filtered or unexported fields
}

A *FlagError indicates an error processing command-line flags or other arguments. Such errors cause the application to display the usage message.

func (*FlagError) Error

func (fe *FlagError) Error() string

func (*FlagError) Unwrap

func (fe *FlagError) Unwrap() error

type JSONFlagError

type JSONFlagError struct {
	// contains filtered or unexported fields
}

type NoResultsError

type NoResultsError struct {
	// contains filtered or unexported fields
}

func NewNoResultsError

func NewNoResultsError(message string) NoResultsError

func (NoResultsError) Error

func (e NoResultsError) Error() string

Jump to

Keyboard shortcuts

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