Documentation
¶
Index ¶
- Variables
- 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
- 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 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
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