cli

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package cli provides functionality for the Tako framework.

Package cli provides functionality for the Tako framework.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Colorize

func Colorize(text string) string

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

type CommandFunc func(ctx *Context, args []string) error

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

type Context struct {
	*tako.Context
	// contains filtered or unexported fields
}

Context provides CLI-specific contextual information and wraps the standard tako.Context.

func NewContext

func NewContext(takoCtx *tako.Context) *Context

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) Error

func (c *Context) Error(msg string)

Error prints a red colored message.

func (*Context) Info

func (c *Context) Info(msg string)

Info prints a blue colored message.

func (*Context) OptionBool

func (c *Context) OptionBool(name string) bool

OptionBool retrieves the boolean value of an option.

func (*Context) OptionString

func (c *Context) OptionString(name string) string

OptionString retrieves the string value of an option.

func (*Context) Success

func (c *Context) Success(msg string)

Success prints an emerald colored message.

func (*Context) Warn

func (c *Context) Warn(msg string)

Warn prints an amber colored message.

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 NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new CLI Command Registry.

func (*Registry) Commands

func (r *Registry) Commands() []Command

Commands returns a list of all registered commands.

func (*Registry) Get

func (r *Registry) Get(name string) Command

Get finds a command by name. Returns nil if not found.

func (*Registry) PrintHelp

func (r *Registry) PrintHelp()

PrintHelp prints the list of available commands grouped by namespace.

func (*Registry) Register

func (r *Registry) Register(cmd Command)

Register adds a new command to the registry.

func (*Registry) RegisterCommand

func (r *Registry) RegisterCommand(cmd any)

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

func (r *Registry) Route(ctx *Context, args []string) (bool, error)

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.

Jump to

Keyboard shortcuts

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