Documentation
¶
Index ¶
- Constants
- Variables
- func AgentArgsValidator(minArgs int) cobra.PositionalArgs
- func AgentArgsValidatorExact(n int) cobra.PositionalArgs
- func DefaultFuncMap() template.FuncMap
- func ExactArgs(number int) cobra.PositionalArgs
- func ExecuteTemplate(w io.Writer, f Format, items []any) error
- func FlagErrorWrap(err error) error
- func FlagErrorf(format string, args ...any) error
- func HandleError(ios *iostreams.IOStreams, err error)deprecated
- func NoArgs(cmd *cobra.Command, args []string) error
- func OutputJSON(ios *iostreams.IOStreams, data any) errordeprecated
- func PrintErrorf(ios *iostreams.IOStreams, format string, args ...any)deprecated
- func PrintHelpHint(ios *iostreams.IOStreams, cmdPath string)deprecated
- func PrintNextSteps(ios *iostreams.IOStreams, steps ...string)deprecated
- func RequiresMaxArgs(maxArgs int) cobra.PositionalArgs
- func RequiresMinArgs(minArgs int) cobra.PositionalArgs
- func RequiresRangeArgs(minArgs int, maxArgs int) cobra.PositionalArgs
- func ToAny[T any](items []T) []any
- func ValidateFilterKeys(filters []Filter, validKeys []string) error
- func WriteJSON(w io.Writer, data any) error
- type ExitError
- type Factory
- type Filter
- type FilterFlags
- type FlagError
- type Format
- type FormatFlags
- type WorktreeSpec
Constants ¶
const ( ModeDefault = "" ModeTable = "table" ModeJSON = "json" ModeTemplate = "template" ModeTableTemplate = "table-template" )
Format mode constants for --format flag parsing.
Variables ¶
var ErrAborted = errors.New("operation aborted by user")
ErrAborted is returned when user cancels an operation.
var SilentError = errors.New("SilentError")
SilentError signals that the error has already been displayed to the user. Main() will exit non-zero but not print anything additional.
Functions ¶
func AgentArgsValidator ¶
func AgentArgsValidator(minArgs int) cobra.PositionalArgs
AgentArgsValidator creates a Cobra Args validator for commands with --agent flag. When --agent is provided, no positional arguments are allowed (mutually exclusive). When --agent is not provided, at least minArgs positional arguments are required.
func AgentArgsValidatorExact ¶
func AgentArgsValidatorExact(n int) cobra.PositionalArgs
AgentArgsValidatorExact creates a Cobra Args validator for commands with --agent flag that require exactly N positional arguments when --agent is not provided.
func DefaultFuncMap ¶
DefaultFuncMap returns the default template function map for --format templates. These functions are Docker CLI-compatible and available in all Go templates used by clawker commands.
func ExactArgs ¶
func ExactArgs(number int) cobra.PositionalArgs
ExactArgs returns an error if there is not the exact number of args
func ExecuteTemplate ¶
ExecuteTemplate parses and executes a Go template from the given Format for each item, writing results to w. For table-template formats, output is aligned through a tabwriter. Each item produces one line of output.
func FlagErrorWrap ¶
FlagErrorWrap wraps an existing error as a FlagError.
func FlagErrorf ¶
FlagErrorf creates a FlagError with a formatted message.
func HandleError
deprecated
func OutputJSON
deprecated
func PrintErrorf
deprecated
added in
v0.1.7
func PrintHelpHint
deprecated
func PrintNextSteps
deprecated
func RequiresMaxArgs ¶
func RequiresMaxArgs(maxArgs int) cobra.PositionalArgs
RequiresMaxArgs returns an error if there is not at most max args
func RequiresMinArgs ¶
func RequiresMinArgs(minArgs int) cobra.PositionalArgs
RequiresMinArgs returns an error if there is not at least min args
func RequiresRangeArgs ¶
func RequiresRangeArgs(minArgs int, maxArgs int) cobra.PositionalArgs
RequiresRangeArgs returns an error if there is not at least min args and at most max args
func ValidateFilterKeys ¶
ValidateFilterKeys checks that every filter's key is in validKeys. Returns a FlagError listing valid keys if an unknown key is found.
Types ¶
type ExitError ¶
type ExitError struct {
Code int
}
ExitError represents a container exit with a non-zero status code. Commands should return this instead of calling os.Exit() directly, allowing deferred cleanup to run. The root command handles os.Exit().
type Factory ¶
type Factory struct {
// Eager (set at construction)
Version string
IOStreams *iostreams.IOStreams
TUI *tui.TUI
// Lazy nouns
Client func(context.Context) (*docker.Client, error)
Config func() (config.Config, error)
Logger func() (*logger.Logger, error)
ProjectManager func() (project.ProjectManager, error)
GitManager func() (*git.GitManager, error)
HostProxy func() hostproxy.HostProxyService
SocketBridge func() socketbridge.SocketBridgeManager
Prompter func() *prompter.Prompter
Firewall func(context.Context) (firewall.FirewallManager, error)
}
Factory provides shared dependencies for CLI commands. It is a dependency injection container: the struct defines what dependencies exist (the contract), while internal/cmd/factory wires the real implementations.
Fields are either eager (set at construction) or lazy nouns (closures that return cached instances on first call). Commands extract only the fields they need into per-command Options structs.
type Filter ¶
Filter is a parsed filter key-value pair from --filter flags.
func ParseFilters ¶
ParseFilters parses raw --filter flag values into Filter structs. Each string must be "key=value" format, split on the first "=" only (the value may contain additional "=" characters). The key must not be empty, but the value may be empty.
type FilterFlags ¶
type FilterFlags struct {
// contains filtered or unexported fields
}
FilterFlags holds raw --filter flag values and provides parsing.
func AddFilterFlags ¶
func AddFilterFlags(cmd *cobra.Command) *FilterFlags
AddFilterFlags registers a repeatable --filter flag on cmd and returns the FilterFlags receiver for later parsing.
func (*FilterFlags) Parse ¶
func (ff *FilterFlags) Parse() ([]Filter, error)
Parse parses the raw filter values collected from the command flags.
type FlagError ¶
type FlagError struct {
// contains filtered or unexported fields
}
FlagError indicates bad flags or arguments. When Main() encounters this error type, it prints the error message followed by the command's usage string.
type Format ¶
type Format struct {
// contains filtered or unexported fields
}
Format is a parsed format specification from the --format flag.
func ParseFormat ¶
ParseFormat parses a raw --format flag value into a Format.
Recognized inputs:
- "" → ModeDefault
- "table" → ModeTable
- "json" → ModeJSON
- "table {{.Name}}\t{{.ID}}" → ModeTableTemplate (prefix "table ")
- "{{.Name}} {{.ID}}" → ModeTemplate (contains "{{")
- anything else → FlagError
func (Format) IsTableTemplate ¶
IsTableTemplate reports whether the format is a table with a Go template.
func (Format) IsTemplate ¶
IsTemplate reports whether the format uses a Go template (plain or table).
type FormatFlags ¶
FormatFlags holds parsed state for --format, --json, and --quiet flags.
func AddFormatFlags ¶
func AddFormatFlags(cmd *cobra.Command) *FormatFlags
AddFormatFlags registers --format, --json, and -q/--quiet flags on the command and chains PreRunE validation for mutual exclusivity.
The returned FormatFlags is populated during PreRunE; commands read it in RunE after flag parsing is complete.
func (*FormatFlags) IsDefault ¶
func (ff *FormatFlags) IsDefault() bool
IsDefault reports whether the format is the default table output.
func (*FormatFlags) IsJSON ¶
func (ff *FormatFlags) IsJSON() bool
IsJSON reports whether the format is JSON output.
func (*FormatFlags) IsTableTemplate ¶
func (ff *FormatFlags) IsTableTemplate() bool
IsTableTemplate reports whether the format is a table with a Go template.
func (*FormatFlags) IsTemplate ¶
func (ff *FormatFlags) IsTemplate() bool
IsTemplate reports whether the format uses a Go template.
func (*FormatFlags) Template ¶
func (ff *FormatFlags) Template() Format
Template returns the underlying Format value (for passing to ExecuteTemplate).
type WorktreeSpec ¶
type WorktreeSpec struct {
Branch string // Branch name to use/create
Base string // Base branch (empty if not specified)
}
WorktreeSpec holds the parsed --worktree flag value.
func ParseWorktreeFlag ¶
func ParseWorktreeFlag(value, agentName string) (*WorktreeSpec, error)
ParseWorktreeFlag parses the --worktree flag value.
Syntax:
- Empty string: auto-generate branch name
- "branch": use existing or create from HEAD
- "branch:base": create branch from specified base
Returns WorktreeSpec with Branch and Base fields. Returns error if branch name is invalid (contains shell metacharacters).