commander

package
v0.0.0-...-8635b2a Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: MIT Imports: 11 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommandWithDescription

func CommandWithDescription(description string) func(*namedRunnable)

func WithDescription

func WithDescription(description string) func(*CommandOption)

func WithOutcomeCallback

func WithOutcomeCallback(outcomeCallback func(context.Context, error)) func(*CommandOption)

Types

type Command

type Command[C any] struct {
	Callback func(context.Context, C) error
	CommandOption
}

func NewCommand

func NewCommand[C any](callback func(context.Context, C) error, options ...func(*CommandOption)) *Command[C]

func (*Command[C]) Help

func (cc *Command[C]) Help() string

func (*Command[C]) Run

func (cc *Command[C]) Run(ctx context.Context, args []string) error

type CommandOption

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

type CommandSet

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

func NewCommandSet

func NewCommandSet() *CommandSet

func (*CommandSet) Add

func (cs *CommandSet) Add(name string, command Runnable, options ...func(*namedRunnable))

func (*CommandSet) CommandDescriptions

func (cs *CommandSet) CommandDescriptions() [][]string

func (*CommandSet) Help

func (cs *CommandSet) Help() string

func (*CommandSet) Run

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

func (*CommandSet) RunMain

func (cs *CommandSet) RunMain(name, version string)

RunMain should run from the main command, it will handle OS Exits, and should be the only goroutine running.

type HelpError

type HelpError struct {
	Usage string
	Lines []string
}

func (HelpError) Error

func (he HelpError) Error() string

type Runnable

type Runnable interface {
	Run(ctx context.Context, args []string) error
	Help() string
}

Jump to

Keyboard shortcuts

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