cmdutil

package
v0.3.11 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package cmdutil provides utilities for command implementation

Index

Constants

View Source
const (
	ExitSuccess  = 0
	ExitError    = 1
	ExitUsage    = 2
	ExitNotFound = 3
	ExitAuth     = 4
	ExitConflict = 5
)

Variables

This section is empty.

Functions

func AddFormatFlag added in v0.3.10

func AddFormatFlag(cmd *cobra.Command, target *string)

AddFormatFlag adds a consistent format flag to a command.

func AddJSONFlag added in v0.3.7

func AddJSONFlag(cmd *cobra.Command, target *bool)

AddJSONFlag adds a consistent JSON output flag to a command.

func AddTemplateFlag added in v0.3.10

func AddTemplateFlag(cmd *cobra.Command, target *string)

AddTemplateFlag adds a consistent template flag to a command.

func AddTimeFormatFlag added in v0.3.10

func AddTimeFormatFlag(cmd *cobra.Command, target *string)

AddTimeFormatFlag adds a consistent time-format flag to a command.

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

func ExitCode(err error) int

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 NewAuthError added in v0.3.7

func NewAuthError(message string) error

func NewCLIError added in v0.3.7

func NewCLIError(code int, message string, cause error) error

NewCLIError creates a CLIError with a stable exit code.

func NewNotFoundError added in v0.3.7

func NewNotFoundError(message string, cause error) error

func NewUsageError added in v0.3.7

func NewUsageError(message string) error

func ParseRepo added in v0.3.7

func ParseRepo(repo string) (string, string, error)

ParseRepo parses a repository reference and returns the owner and repository name. It supports owner/repo, HTTPS URLs, and SSH URLs.

func ResolveRepo added in v0.3.7

func ResolveRepo(repo string, baseRepo func() (string, error)) (string, error)

ResolveRepo returns the explicit repository when provided, otherwise tries to infer it from the current git repository.

func WriteJSON added in v0.3.7

func WriteJSON(w io.Writer, value interface{}) error

WriteJSON writes indented JSON to the target writer.

Types

type CLIError added in v0.3.7

type CLIError struct {
	Code    int
	Message string
	Cause   error
}

CLIError represents a stable CLI-facing error with an exit code.

func (*CLIError) Error added in v0.3.7

func (e *CLIError) Error() string

func (*CLIError) Unwrap added in v0.3.7

func (e *CLIError) Unwrap() error

type ConfirmOptions added in v0.3.7

type ConfirmOptions struct {
	IO       *iostreams.IOStreams
	Yes      bool
	Expected string
	Prompt   string
}

ConfirmOptions controls destructive-action confirmation prompts.

type Factory

type Factory struct {
	IOStreams  *iostreams.IOStreams
	HttpClient func() (*http.Client, error)
	Config     func() (config.Config, error)
	BaseRepo   func() (string, error)
	Branch     func() (string, error)
}

Factory provides dependencies for commands

func NewFactory

func NewFactory() *Factory

NewFactory creates a new Factory with default settings

func TestFactory

func TestFactory() *Factory

TestFactory creates a Factory for testing

Source Files

  • auth.go
  • confirm.go
  • errors.go
  • factory.go
  • format.go
  • output.go
  • repo.go

Jump to

Keyboard shortcuts

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