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
- func DisableAuthCheck(cmd *cobra.Command)
- func EnableSuggestions(cmd *cobra.Command)
- func ExactArgs(n int, argName string) cobra.PositionalArgs
- func IsSilentError(err error) bool
- func IsUsageError(err error) bool
- func MinArgs(n int, argName string) cobra.PositionalArgs
- func NewSilentError(err error) error
- func RangeArgs(min, max int, argName string) cobra.PositionalArgs
- func RequiresAuth(cmd *cobra.Command) bool
- func UnwrapSilent(err error) error
- type SilentError
- type UsageError
Constants ¶
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 ¶
DisableAuthCheck marks a command as not requiring authentication. It sets an annotation that can be checked with RequiresAuth.
func EnableSuggestions ¶
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 ¶
IsSilentError checks if an error is a silent error
func IsUsageError ¶
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 ¶
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 ¶
RequiresAuth returns true if the command requires authentication
func UnwrapSilent ¶
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 ¶
UsageError represents an error in command usage that should show help context
func (*UsageError) Error ¶
func (e *UsageError) Error() string