cli

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrHelpRequested = helpRequestedError{}

Functions

func NewLogger

func NewLogger(level slog.Level, w io.Writer) *slog.Logger

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

func NewLoggerWithFormat(level slog.Level, w io.Writer, format Format) *slog.Logger

NewLoggerWithFormat creates a new slog.Logger with specified format

func ParseLogLevel

func ParseLogLevel(level string) slog.Level

ParseLogLevel parses a string log level to slog.Level

func Run

func Run(ctx context.Context, args []string) error

Types

type DefaultParser

type DefaultParser struct {
	// contains filtered or unexported fields
}

DefaultParser implements the Parser interface

func (*DefaultParser) Help

func (p *DefaultParser) Help() string

Help returns help text

func (*DefaultParser) Parse

func (p *DefaultParser) Parse(ctx context.Context, args []string) (*ParseResult, error)

Parse parses command line arguments

type Format

type Format int

Format represents the log output format

const (
	FormatAuto Format = iota
	FormatConsole
	FormatJSON
)

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

type OptionValue interface {
	String() string
	StringSlice() []string
	IsSet() bool
}

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

func NewParser

func NewParser(opts []Option) (Parser, error)

NewParser creates a new default parser with the given options

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

Jump to

Keyboard shortcuts

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