Documentation
¶
Overview ¶
Package cli provides functionality for the Tako framework.
Package cli provides functionality for the Tako framework.
Index ¶
- func Colorize(text string) string
- func ParseSignature(signature string, builder *CommandBuilder)
- type Command
- type CommandBuilder
- type CommandFunc
- type ComponentOutput
- type Context
- type Middleware
- type Option
- type OptionBuilder
- type OptionType
- type Registry
- func (r *Registry) Commands() []Command
- func (r *Registry) Get(name string) Command
- func (r *Registry) PrintHelp()
- func (r *Registry) Register(cmd Command)
- func (r *Registry) RegisterCommand(cmd any)
- func (r *Registry) Route(ctx *Context, args []string) (bool, error)
- func (r *Registry) Use(middleware Middleware)
- type SignatureProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Colorize ¶
Colorize parses semantic HTML-like tags and replaces them with ANSI color codes degraded to the terminal's color capability. When the terminal does not support ANSI color (e.g. TERM=dumb, NO_COLOR set, or non-TTY output), tags are stripped and plain text is returned.
func ParseSignature ¶
func ParseSignature(signature string, builder *CommandBuilder)
ParseSignature parses a Laravel-like command signature string and applies it to a CommandBuilder. Example: "log:viewer {--w|watch : Watch the log file} {limit=100 : Maximum lines}"
Types ¶
type Command ¶
type Command interface {
// Name returns the CLI command name (e.g., "help", "version")
Name() string
// Description returns a short description of what the command does
Description() string
// Execute runs the command logic. It receives the cli context.
Execute(ctx *Context, args []string) error
}
Command represents an Artisan-like headless command that can be executed from the CLI.
type CommandBuilder ¶
type CommandBuilder struct {
// contains filtered or unexported fields
}
CommandBuilder helps construct a list of options fluently.
func NewCommandBuilder ¶
func NewCommandBuilder() *CommandBuilder
NewCommandBuilder creates a new CommandBuilder.
func (*CommandBuilder) AddOption ¶
func (b *CommandBuilder) AddOption(name string) *OptionBuilder
AddOption starts building a new option with the given name.
func (*CommandBuilder) Options ¶
func (b *CommandBuilder) Options() []Option
Options returns the built slice of options.
type CommandFunc ¶
CommandFunc is the signature for the actual command execution logic.
type ComponentOutput ¶
type ComponentOutput struct{}
ComponentOutput provides Artisan-like badge outputs.
func (*ComponentOutput) Error ¶
func (c *ComponentOutput) Error(msg string)
Error prints a message with a red ERROR badge.
func (*ComponentOutput) Info ¶
func (c *ComponentOutput) Info(msg string)
Info prints a message with a blue INFO badge.
func (*ComponentOutput) Success ¶
func (c *ComponentOutput) Success(msg string)
Success prints a message with an emerald SUCCESS badge.
func (*ComponentOutput) Warn ¶
func (c *ComponentOutput) Warn(msg string)
Warn prints a message with an amber WARN badge.
type Context ¶
Context provides CLI-specific contextual information and wraps the standard tako.Context.
func NewContext ¶
NewContext creates a new CLI Context.
func (*Context) Component ¶
func (c *Context) Component() *ComponentOutput
Component returns the component printer for badge-style outputs.
func (*Context) OptionBool ¶
OptionBool retrieves the boolean value of an option.
func (*Context) OptionString ¶
OptionString retrieves the string value of an option.
type Middleware ¶
type Middleware func(next CommandFunc) CommandFunc
Middleware defines a function that wraps a Command execution.
type Option ¶
type Option struct {
Name string
Shortcut string
Mode OptionType
Description string
Default any
}
Option represents a declarative CLI option configuration.
type OptionBuilder ¶
type OptionBuilder struct {
// contains filtered or unexported fields
}
OptionBuilder is a fluent interface for configuring a single option.
func (*OptionBuilder) Alias ¶
func (o *OptionBuilder) Alias(shortcut string) *OptionBuilder
Alias sets the shorthand/shortcut for the option.
func (*OptionBuilder) AsBool ¶
func (o *OptionBuilder) AsBool() *OptionBuilder
AsBool sets the option to not require a value (boolean flag).
func (*OptionBuilder) AsString ¶
func (o *OptionBuilder) AsString() *OptionBuilder
AsString sets the option to require a string value.
func (*OptionBuilder) Default ¶
func (o *OptionBuilder) Default(val any) *OptionBuilder
Default sets the default value for the option.
func (*OptionBuilder) Description ¶
func (o *OptionBuilder) Description(desc string) *CommandBuilder
Description sets the usage description for the option and finalize the option building.
type OptionType ¶
type OptionType int
OptionType defines the expected value type for an option.
const ( // ValueNone indicates the option does not accept a value (boolean flag). ValueNone OptionType = iota // ValueRequired indicates the option requires a string value. ValueRequired // ValueOptional indicates the option accepts an optional string value. ValueOptional )
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages the registration and execution of CLI commands.
func (*Registry) PrintHelp ¶
func (r *Registry) PrintHelp()
PrintHelp prints the list of available commands grouped by namespace.
func (*Registry) RegisterCommand ¶
RegisterCommand allows registering a command dynamically from an `any` type. This is used by tako.Context to provide fluent APIs without cyclic dependencies.
func (*Registry) Route ¶
Route checks args and executes the appropriate command. Returns true if a command was executed, false if no command was present. It receives a cli.Context which supports UI mounting.
func (*Registry) Use ¶
func (r *Registry) Use(middleware Middleware)
Use adds a middleware that wraps command execution.
type SignatureProvider ¶
type SignatureProvider interface {
Signature() string
}
SignatureProvider is an optional interface for commands that declare their flags via a Laravel-style signature string (e.g. "{--json : Output as JSON}"). Commands that do not implement this interface use no auto-parsed flags.