cmdutil

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package cmdutil provides CLI command utilities for consistent behavior across all bc4 commands, including suggestions, argument validation, and exit code management.

Index

Constants

View Source
const (
	ExitSuccess    = 0   // Successful execution
	ExitError      = 1   // General error
	ExitUsageError = 2   // Invalid command usage
	ExitAuthError  = 4   // Authentication failure
	ExitNotFound   = 5   // Resource not found
	ExitCanceled   = 130 // User canceled (Ctrl+C)
)

Exit codes following GitHub CLI conventions

Variables

This section is empty.

Functions

func DisableAuthCheck

func DisableAuthCheck(cmd *cobra.Command)

DisableAuthCheck marks a command as not requiring authentication. It sets an annotation that can be checked with RequiresAuth.

func EnableSuggestions

func EnableSuggestions(cmd *cobra.Command)

EnableSuggestions configures a command to suggest similar commands on typos. This should be called on all parent commands that have subcommands.

func ExactArgs

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

ExactArgs returns an argument validator that requires exactly n arguments with a helpful error message including the command usage.

func IsSilentError

func IsSilentError(err error) bool

IsSilentError checks if an error is a silent error

func IsUsageError

func IsUsageError(err error) bool

IsUsageError checks if an error is a usage error

func MinArgs

func MinArgs(n int, argName string) cobra.PositionalArgs

MinArgs returns an argument validator that requires at least n arguments with a helpful error message.

func NewSilentError

func NewSilentError(err error) error

NewSilentError creates a silent error wrapper

func RangeArgs

func RangeArgs(min, max int, argName string) cobra.PositionalArgs

RangeArgs returns an argument validator that requires between min and max arguments.

func RequiresAuth

func RequiresAuth(cmd *cobra.Command) bool

RequiresAuth returns true if the command requires authentication

func UnwrapSilent

func UnwrapSilent(err error) error

UnwrapSilent returns the underlying error from a SilentError

Types

type SilentError

type SilentError struct {
	Err error
}

SilentError wraps an error that has already been displayed to the user. This allows returning a proper exit code without double-printing the error.

func (*SilentError) Error

func (e *SilentError) Error() string

func (*SilentError) Unwrap

func (e *SilentError) Unwrap() error

type UsageError

type UsageError struct {
	Message string
	Cmd     *cobra.Command
}

UsageError represents an error in command usage that should show help context

func (*UsageError) Error

func (e *UsageError) Error() string

Jump to

Keyboard shortcuts

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