Documentation
¶
Index ¶
- Variables
- func FormatError(err error, verbose, color bool) string
- func NewLogger(level slog.Level, w io.Writer) *slog.Logger
- func NewLoggerWithFormat(level slog.Level, w io.Writer, format Format) *slog.Logger
- func ParseLogLevel(level string) (slog.Level, error)
- func Run(ctx context.Context, args []string) error
- type DefaultParser
- type Format
- type Option
- type OptionValue
- type ParseResult
- type Parser
- type StringSliceValue
- type StringValue
Constants ¶
This section is empty.
Variables ¶
var ErrHelpRequested = helpRequestedError{}
Functions ¶
func FormatError ¶ added in v2.4.0
FormatError renders err for human consumption on a terminal.
- verbose=true attaches the underlying goerr trace (%+v) for debugging.
- color=true emits ANSI escape sequences.
The returned string does not have a trailing newline; callers may append one when writing it out.
func NewLogger ¶
NewLogger creates a new slog.Logger with automatic format detection If output is a terminal, use clog for colored console output Otherwise, use JSON format for structured logging
func NewLoggerWithFormat ¶
NewLoggerWithFormat creates a new slog.Logger with specified format
func ParseLogLevel ¶
ParseLogLevel parses a string log level to slog.Level.
Unknown values (including the empty string) are reported as model.InvalidLogLevelError so the caller can surface a precise error to the user instead of silently falling back to a default. The CLI parser supplies "warn" as the default when --log-level is omitted, so empty input here means the user explicitly passed an empty value, which is also invalid.
Types ¶
type DefaultParser ¶
type DefaultParser struct {
// contains filtered or unexported fields
}
DefaultParser implements the Parser interface
func (*DefaultParser) Parse ¶
func (p *DefaultParser) Parse(ctx context.Context, args []string) (*ParseResult, error)
Parse parses command line arguments
type Option ¶
type Option struct {
Name string // Long name (e.g., "env")
Aliases []string // Short aliases (e.g., ["e"])
Usage string // Description for help
DefaultValue string // Default value
IsSlice bool // Whether this option accepts multiple values
IsBoolean bool // Whether this is a boolean flag (no value required)
}
Option defines an option that can be parsed
type OptionValue ¶
OptionValue represents a parsed option value
type ParseResult ¶
type ParseResult struct {
Options map[string]OptionValue // Parsed options
Args []string // Remaining arguments (command to execute)
}
ParseResult contains the result of parsing command line arguments
type Parser ¶
type Parser interface {
// Parse parses the given arguments and returns options and remaining args
Parse(ctx context.Context, args []string) (*ParseResult, error)
// Help returns help text for all registered options
Help() string
}
Parser defines the interface for command line parsing
type StringSliceValue ¶
type StringSliceValue struct {
// contains filtered or unexported fields
}
StringSliceValue holds a string slice option value
func (*StringSliceValue) IsSet ¶
func (s *StringSliceValue) IsSet() bool
func (*StringSliceValue) String ¶
func (s *StringSliceValue) String() string
func (*StringSliceValue) StringSlice ¶
func (s *StringSliceValue) StringSlice() []string
type StringValue ¶
type StringValue struct {
// contains filtered or unexported fields
}
StringValue holds a string option value
func (*StringValue) IsSet ¶
func (s *StringValue) IsSet() bool
func (*StringValue) String ¶
func (s *StringValue) String() string
func (*StringValue) StringSlice ¶
func (s *StringValue) StringSlice() []string