command

package
v0.1.4-0...-0b1df8e Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatValue

func FormatValue(value any) string

FormatValue formats a command table value.

Types

type Command

type Command interface {
	Name() string
	Summary() string
	Run(ctx context.Context, cmd *Context) error
}

Command is an application command executed by the project binary.

type Context

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

Context is the execution context for application commands.

func NewContext

func NewContext(app any, cmd *cli.Command) *Context

NewContext creates a command context.

func (*Context) App

func (ctx *Context) App() any

App returns the current application object.

func (*Context) Args

func (ctx *Context) Args() []string

Args returns raw command arguments after the command name.

func (*Context) Get

func (ctx *Context) Get[T any](name string, fallback ...T) T

Get reads a flag value and casts it to T.

func (*Context) JSON

func (ctx *Context) JSON(data any) error

JSON writes indented JSON to the command output.

func (*Context) Print

func (ctx *Context) Print(values ...any) error

Print writes values to the command output.

func (*Context) Println

func (ctx *Context) Println(values ...any) error

Println writes values and a newline to the command output.

func (*Context) Table

func (ctx *Context) Table(data any) error

Table writes a simple tab-separated table to the command output.

type ExecuteConfig

type ExecuteConfig struct {
	Name        string
	Usage       string
	DefaultArgs []string
	Writer      io.Writer
	ErrWriter   io.Writer
}

ExecuteConfig configures command execution.

type FlagSet

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

FlagSet is the command flag definition facade.

func (*FlagSet) Bool

func (flags *FlagSet) Bool(name string, value bool, usage string)

Bool defines a bool flag.

func (*FlagSet) CLIFlags

func (flags *FlagSet) CLIFlags() []cli.Flag

CLIFlags returns flags for the underlying CLI runtime.

func (*FlagSet) Int

func (flags *FlagSet) Int(name string, value int, usage string)

Int defines an int flag.

func (*FlagSet) String

func (flags *FlagSet) String(name string, value string, usage string)

String defines a string flag.

type Flags

type Flags interface {
	Flags(flags *FlagSet)
}

Flags lets a command define flags.

type Registry

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

Registry stores application commands.

func New

func New() *Registry

New creates a command registry.

func (*Registry) Commands

func (registry *Registry) Commands(app any) []*cli.Command

Commands returns CLI command definitions.

func (*Registry) Execute

func (registry *Registry) Execute(ctx context.Context, app any, args []string, config ExecuteConfig) error

Execute runs a command set. Empty args use DefaultArgs.

func (*Registry) Names

func (registry *Registry) Names() []string

Names returns registered command names.

func (*Registry) Register

func (registry *Registry) Register(commands ...Command)

Register registers commands by name.

Jump to

Keyboard shortcuts

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