cli

package
v0.0.0-...-a4ecd53 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2025 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	WithLogger  = fopt.Setter(func(c *Command) *slog.Logger { return c.Logger })
	WithFlagSet = fopt.Setter(func(c *Command) *flag.FlagSet { return c.FlagSet })
	WithBefore  = fopt.Setter(func(c *Command) *HandlerFunc { return &c.Before })
	WithRun     = fopt.Setter(func(c *Command) *HandlerFunc { return &c.Run })
	WithAfter   = fopt.Setter(func(c *Command) *HandlerFunc { return &c.After })
	WithMatch   = fopt.Setter(func(c *Command) *func(string) bool { return &c.Match })
)
View Source
var DefaultRoot = NewRoot("", "", flag.ExitOnError)

Functions

func ParseAndRunFromCLI

func ParseAndRunFromCLI() error

func TryHandle

func TryHandle(ctx context.Context, hf HandlerFunc) error

Types

type Command

type Command struct {
	Name    string
	Summary string
	Before  HandlerFunc
	Run     HandlerFunc
	After   HandlerFunc
	Match   func(string) bool

	SubCommands []*Command
	Parent      *Command

	*flag.FlagSet
	*slog.Logger
}

func NewRoot

func NewRoot(name, summary string, errorHandling flag.ErrorHandling, opt ...fopt.Option[Command]) *Command

func SubCommand

func SubCommand(name, summary string, opt ...fopt.Option[Command]) *Command

func (*Command) Dispatch

func (c *Command) Dispatch(name string) *Command

func (*Command) ParseAndRun

func (c *Command) ParseAndRun(ctx context.Context, args []string) error

func (*Command) SubCommand

func (c *Command) SubCommand(name, summary string, opt ...fopt.Option[Command]) *Command

type HandlerFunc

type HandlerFunc func(context.Context) error

Jump to

Keyboard shortcuts

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