cli

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Args

func Args(ctx context.Context) []string

func Flags

func Flags(ctx context.Context) map[string]any

Types

type App

type App struct {
	Logger *log.Logger
	Data   map[string]any
}

func AppFromContext

func AppFromContext(ctx context.Context) *App

type Arg

type Arg struct {
	Name        string
	Description string
	Optional    bool
	Variadic    bool
}

type CLI

type CLI struct {
	Root *Command

	Middleware      []Middleware
	HelpCommandName string
	// contains filtered or unexported fields
}

func New

func New(root *Command, opts ...Option) *CLI

func (*CLI) App

func (c *CLI) App() *App

func (*CLI) Context

func (c *CLI) Context() context.Context

func (*CLI) FindCommand

func (c *CLI) FindCommand(path ...string) (*Command, bool)

func (*CLI) Hook

func (c *CLI) Hook(phase HookPhase, h Hook)

func (*CLI) RegisterCommand

func (c *CLI) RegisterCommand(parentPath []string, cmd *Command) error

func (*CLI) Run

func (c *CLI) Run(args []string) error

func (*CLI) Use

func (c *CLI) Use(m Middleware)

type Command

type Command struct {
	Name        string
	Description string
	Summary     string
	Hidden      bool

	Aliases []string
	Args    []Arg
	Flags   func(fs *flag.FlagSet)

	Handler  Handler
	Commands []*Command

	Before []Hook
	After  []Hook

	Middleware []Middleware
}

func CurrentCommand

func CurrentCommand(ctx context.Context) *Command

type Handler

type Handler func(ctx context.Context) error

type Hook

type Hook func(ctx context.Context) error

type HookPhase

type HookPhase int
const (
	BeforeRun HookPhase = iota
	AfterRun
	BeforeCommand
	AfterCommand
)

type Middleware

type Middleware func(next Handler) Handler

type Option

type Option func(*CLI)

func WithAppData

func WithAppData(m map[string]any) Option

func WithHelpCommandName

func WithHelpCommandName(name string) Option

func WithLogger

func WithLogger(l *log.Logger) Option

func WithWriters

func WithWriters(out, err io.Writer) Option

type PluginRegistrar

type PluginRegistrar interface {
	RegisterCommand(parentPath []string, cmd *Command) error
	Use(m Middleware)
	Hook(phase HookPhase, h Hook)
	FindCommand(path ...string) (*Command, bool)
}

Jump to

Keyboard shortcuts

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