command

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PopRequestArg

func PopRequestArg[
	VALUE interfaces.Stringer,
	VALUE_PTR interfaces.StringerSetterPtr[VALUE],
](req Request, name string) VALUE_PTR

func PopRequestArgTo

func PopRequestArgTo(req Request, name string, value interfaces.StringerSetter)

func PopRequestArgToFunc

func PopRequestArgToFunc(req Request, name string, funcSet func(string) error)

func PopRequestArgs

func PopRequestArgs[
	VALUE interfaces.Stringer,
	VALUE_PTR interfaces.StringerSetterPtr[VALUE],
](
	req Request,
	name string,
) interfaces.Seq[VALUE_PTR]

func PrintSubcommandUsage

func PrintSubcommandUsage(flags flags.FlagSet)

TODO evaluate need

Types

type Arg

type Arg struct {
	// Name is used in synopsis, error messages, and as MCP schema property
	// key. Should match the string passed to PopArg(name).
	Name        string
	Description string
	Required    bool

	// Variadic means this arg consumes all remaining positional arguments.
	// At most one Arg per command may be Variadic, and it must be last.
	Variadic bool

	// EnumValues constrains the arg to listed values. Used for MCP schema
	// enum and shell completion.
	EnumValues []string

	// Value carries type information for schema generation and future
	// auto-parsing. Same interface flags use (StringerSetter). Nil means
	// plain string. When non-nil, the concrete type determines the JSON
	// schema type and Value.Set() provides validation.
	Value interfaces.FlagValue
}

Arg declares metadata for a single positional argument. Mirrors the flag pattern: flagSet.Var(&cmd.RepoId, "repo", "usage") becomes Arg{Name: "repo-id", Value: &ids.RepoId{}, ...}

type ArgGroup

type ArgGroup struct {
	Name        string // e.g. "query" (empty for inline groups)
	Description string // group-level description for docs
	Args        []Arg
}

ArgGroup is a named set of args contributed by a command or component. Commands compose ArgGroups from their embedded components.

type CLICompleter

type CLICompleter = cli.CLICompleter

type Cmd

type Cmd interface {
	Run(Request)
}

type CommandComponent

type CommandComponent interface {
	CommandComponentReader
	interfaces.CommandComponentWriter
}

type CommandComponentReader

type CommandComponentReader interface {
	GetCLIFlags() []string
}

type CommandLineInput

type CommandLineInput struct {
	FlagsOrArgs          collections_slice.String
	InProgress           string
	ContainsDoubleHyphen bool

	Args collections_slice.String
	Argi int
	// contains filtered or unexported fields
}

TODO complete merging Args, consumed and FlagsOrArgs for use by Run/Complete

func (CommandLineInput) LastArg

func (commandLine CommandLineInput) LastArg() (arg string, ok bool)

func (CommandLineInput) LastCompleteArg

func (commandLine CommandLineInput) LastCompleteArg() (arg string, ok bool)

type CommandWithArgs

type CommandWithArgs interface {
	GetArgs() []ArgGroup
}

CommandWithArgs is the opt-in interface for declarative arg metadata. Commands that implement this get improved manpage SYNOPSIS/ARGUMENTS sections and auto-generated MCP schemas. Commands that don't continue to work as before.

type CommandWithDescription

type CommandWithDescription interface {
	GetDescription() Description
}

type CommandWithMCPAnnotations

type CommandWithMCPAnnotations interface {
	GetMCPAnnotations() MCPAnnotations
}

CommandWithMCPAnnotations lets commands declare their MCP hints.

type Completer

type Completer interface {
	Complete(Request, env_local.Env, CommandLineInput)
}

type Completion

type Completion struct {
	Value, Description string
}

type Config

type Config interface {
	interfaces.CommandComponentWriter
	GetConfigCLI() config_cli.Config
}

type Description

type Description struct {
	Short, Long string
}

type FlagValueCompleter

type FlagValueCompleter struct {
	interfaces.FlagValue
	FuncCompleter
}

func (FlagValueCompleter) Complete

func (completer FlagValueCompleter) Complete(
	req Request,
	envLocal env_local.Env,
	commandLine CommandLineInput,
)

func (FlagValueCompleter) String

func (completer FlagValueCompleter) String() string

type FuncCompleter

type FuncCompleter func(Request, env_local.Env, CommandLineInput)

type MCPAnnotations

type MCPAnnotations struct {
	ReadOnly    bool
	Destructive bool
}

MCPAnnotations declares MCP tool hints without importing go-mcp protocol types, keeping the golf layer dependency-free.

type Request

type Request struct {
	errors.Context
	Utility Utility
	FlagSet *flags.FlagSet
	// contains filtered or unexported fields
}

func (*Request) AssertNoMoreArgs

func (req *Request) AssertNoMoreArgs()

func (Request) LastArg

func (req Request) LastArg() (arg string, ok bool)

func (Request) PeekArgs

func (req Request) PeekArgs() collections_slice.String

TODO switch to ActiveContext

func (Request) PopArg

func (req Request) PopArg(name string) string

func (Request) PopArgOrDefault

func (req Request) PopArgOrDefault(name, defaultArg string) string

func (Request) PopArgs

func (req Request) PopArgs() []string

func (Request) PopArgsAsMutableSet

func (req Request) PopArgsAsMutableSet() collections_value.MutableSet[string]

func (Request) RemainingArgCount

func (req Request) RemainingArgCount() int

type SupportsCompletion

type SupportsCompletion interface {
	SupportsCompletion()
}

type Utility

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

func MakeUtility

func MakeUtility(name string, defaultConfig Config) Utility

func (Utility) AddCmd

func (utility Utility) AddCmd(name string, cmd Cmd)

func (Utility) AllCmds

func (utility Utility) AllCmds() interfaces.Seq2[string, Cmd]

func (Utility) GetCmd

func (utility Utility) GetCmd(name string) (Cmd, bool)

func (Utility) GetConfig

func (utility Utility) GetConfig() config_cli.Config

func (Utility) GetConfigAny

func (utility Utility) GetConfigAny() any

GetConfigAny returns the raw config as any, allowing callers to type-assert to their specific config type (e.g., repo_config_cli.Config for dodder commands).

func (Utility) GetName

func (utility Utility) GetName() string

func (Utility) LenCmds

func (utility Utility) LenCmds() int

func (Utility) MakeCmdAndFlagSet

func (utility Utility) MakeCmdAndFlagSet(
	ctx errors.Context,
	args []string,
) (cmd Cmd, flagSet *flags.FlagSet, ok bool)

func (Utility) MakeRequest

func (utility Utility) MakeRequest(
	ctx errors.Context,
	cmd Cmd,
	flagSet *flags.FlagSet,
) (request Request, ok bool)

func (Utility) MergeUtility

func (utility Utility) MergeUtility(otherUtility Utility) Utility

func (Utility) MergeUtilityWithPrefix

func (utility Utility) MergeUtilityWithPrefix(
	otherUtility Utility,
	prefix string,
) Utility

func (Utility) PrintUsage

func (utility Utility) PrintUsage(ctx errors.Context, err error)

func (Utility) Run

func (utility Utility) Run(
	args []string,
)

Source Files

  • arg.go
  • cmd.go
  • command_line_input.go
  • completion.go
  • flags.go
  • main.go
  • request.go
  • utility.go
  • utility_run.go

Jump to

Keyboard shortcuts

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