Documentation
¶
Overview ¶
Package cmdutil provides utilities for command implementation
Index ¶
- Constants
- Variables
- func AddFormatFlag(cmd *cobra.Command, target *string)
- func AddJSONFlag(cmd *cobra.Command, target *bool)
- func AddTemplateFlag(cmd *cobra.Command, target *string)
- func AddTimeFormatFlag(cmd *cobra.Command, target *string)
- func AuthenticatedClient(httpClient *http.Client) (*api.Client, error)
- func AuthenticatedClientFromFactory(httpClient func() (*http.Client, error)) (*api.Client, error)
- func ConfirmOrAbort(opts ConfirmOptions) error
- func EnvToken() string
- func ExitCode(err error) int
- func FormatAPIID(id interface{}) string
- func NewAuthError(message string) error
- func NewCLIError(code int, message string, cause error) error
- func NewConflictError(message string) error
- func NewNotFoundError(message string, cause error) error
- func NewUsageError(message string) error
- func ParseRepo(repo string) (string, string, error)
- func ResolvePRURL(htmlURL, owner, repo string, number int) string
- func ResolveRepo(repo string, baseRepo func() (string, error)) (string, error)
- func SetFlagEnum(cmd *cobra.Command, name string, values ...string)
- func SetTopicAnnotation(cmd *cobra.Command, topic string)
- func WrapNotFound(err error, format string, args ...interface{}) error
- func WriteJSON(w io.Writer, value interface{}) error
- type CLIError
- type ConfirmOptions
- type Factory
Constants ¶
const ( ExitSuccess = 0 ExitError = 1 ExitUsage = 2 ExitNotFound = 3 ExitAuth = 4 ExitConflict = 5 )
const FlagEnumAnnotation = "gc.enum"
const TopicAnnotation = "gc.topic"
Variables ¶
var StandardTopics = []string{
"auth",
"issues",
"pull-requests",
"releases",
"milestones",
"repo",
"commits",
"labels",
}
StandardTopics is the list of standard topic categories.
Functions ¶
func AddFormatFlag ¶ added in v0.3.11
AddFormatFlag adds a consistent format flag to a command.
func AddJSONFlag ¶ added in v0.3.7
AddJSONFlag adds a consistent JSON output flag to a command.
func AddTemplateFlag ¶ added in v0.3.11
AddTemplateFlag adds a consistent template flag to a command.
func AddTimeFormatFlag ¶ added in v0.3.11
AddTimeFormatFlag adds a consistent time-format flag to a command.
func AuthenticatedClient ¶ added in v0.4.0
AuthenticatedClient creates an API client using the configured default host and active token. Environment tokens keep their existing priority.
func AuthenticatedClientFromFactory ¶ added in v0.4.0
AuthenticatedClientFromFactory creates an authenticated API client from the command factory dependencies.
func ConfirmOrAbort ¶ added in v0.3.7
func ConfirmOrAbort(opts ConfirmOptions) error
ConfirmOrAbort enforces a shared confirmation flow.
func EnvToken ¶ added in v0.3.7
func EnvToken() string
EnvToken returns the active token from supported environment variables.
func ExitCode ¶ added in v0.3.7
ExitCode maps a command error to a stable process exit code.
func FormatAPIID ¶ added in v0.3.7
func FormatAPIID(id interface{}) string
FormatAPIID normalizes API IDs that may arrive as strings or JSON numbers.
func NewCLIError ¶ added in v0.3.7
NewCLIError creates a CLIError with a stable exit code.
func ParseRepo ¶ added in v0.3.7
ParseRepo parses a repository reference and returns the owner and repository name. It supports owner/repo, HTTPS URLs, and SSH URLs.
func ResolvePRURL ¶ added in v0.5.0
ResolvePRURL returns the PR URL with fallback logic. If the API-provided URL is empty, it constructs one from owner/repo/number.
func ResolveRepo ¶ added in v0.3.7
ResolveRepo returns the explicit repository when provided, otherwise tries to infer it from the current git repository.
func SetFlagEnum ¶ added in v0.4.0
SetFlagEnum records a stable enum set for schema/export consumers.
func SetTopicAnnotation ¶ added in v0.4.0
SetTopicAnnotation adds a topic annotation to a command.
func WrapNotFound ¶ added in v0.5.0
WrapNotFound wraps an error as NotFoundError if it's a 404 API error. Returns the original error if it's not a 404. Usage: return cmdutil.WrapNotFound(err, "issue #%d not found in %s/%s", number, owner, repo)
Types ¶
type CLIError ¶ added in v0.3.7
CLIError represents a stable CLI-facing error with an exit code.
type ConfirmOptions ¶ added in v0.3.7
ConfirmOptions controls destructive-action confirmation prompts.
Source Files
¶
- auth.go
- confirm.go
- errors.go
- factory.go
- flag_annotations.go
- format.go
- output.go
- repo.go