Documentation
¶
Overview ¶
Code generated by apic; DO NOT EDIT.
Code generated by apic; DO NOT EDIT.
Index ¶
- Variables
- func As[T any](in any) T
- func Children(children ...*cobra.Command) opt.Option[*Command]
- func Feat() opt.Option[*Command]
- func Hide() opt.Option[*Command]
- func Parent(p *cobra.Command) opt.Option[*Command]
- func SetArgs(flags *pflag.FlagSet, prefix string, args Args) error
- func WithArgs(prefix string, a Args) opt.Option[*Command]
- func WithLogger(l *slog.Logger) opt.Option[*Command]
- type Arg
- type Args
- type Command
- type Docs
- type Execute
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidLogger = errors.New("cli: invalid logger specified")
ErrInvalidLogger is returned by WithLogger when a nil *slog.Logger is supplied.
var ErrUnknownType = fmt.Errorf("unknown type")
ErrUnknownType is returned by SetArgs when an Arg's Value holds a type outside the fixed set SetArgs knows how to register as a pflag (string, []string, bool, the signed/unsigned integer and float widths, and time.Duration).
Functions ¶
func As ¶
As type-asserts in to T, returning T's zero value when in is nil or holds a different concrete type (the failed assertion is discarded rather than panicking). Handy for narrowing the any values returned by Args.Get.
func Children ¶
Children registers each of children as a subcommand of the Command being built, via cobra's AddCommand.
func Feat ¶
Feat marks the Command hidden, the same as Hide, and is the marker used for feature-gated subcommands. QG-065: intentionally minimal -- any richer feature-gating semantics are tracked separately; until then it deliberately behaves identically to Hide rather than pretending to more.
func Hide ¶
Hide marks the Command hidden, excluding it from cobra's generated help listings while leaving it fully invocable by name.
func Parent ¶
Parent registers the Command as a child of p via p.AddCommand, wiring it into an existing cobra command tree.
Types ¶
type Arg ¶
type Arg struct {
Short string `json:"short" yaml:"short"` // one-letter abbreviated flag
Value any `json:"value" yaml:"value"`
Deprecated bool `json:"deprecated" yaml:"deprecated"`
Replacement string `json:"replacement" yaml:"replacement"`
Description string `json:"description" yaml:"description"`
Required bool `json:"required" yaml:"required"`
GetFN func() any
}
Arg describes a single pflag/viper-bound command-line argument: its default Value, an optional one-letter Short flag, human-readable Description, Required/Deprecated markers, and (once registered via SetArgs) a GetFN closure that reads the live value back from viper.
type Args ¶
Args is a named collection of command-line/config arguments, keyed by the flag name under which each Arg is registered (see SetArgs).
func (Args) Get ¶
Get returns the current value of the argument named key: the live viper-bound value when the arg has been registered via SetArgs (through Arg.GetFN), or its static Value otherwise. Returns nil and logs a warning if key is not present in a, or if the argument's getter reports it was not found.
type Command ¶
type Command struct {
*cobra.Command
Args Args
Docs Docs
// contains filtered or unexported fields
}
Command wraps a *cobra.Command with a structured logger, the bound Args used to register its flags, and the Docs describing it for help/usage output.
func NewCommand ¶
NewCommand builds a Command from docs, wrapping exec with debug-level entry/exit logging (via the default slog.Logger, unless overridden with WithLogger) before installing it as the underlying cobra.Command's RunE. Each opt is applied in order and NewCommand returns the first error any of them produce.
type Docs ¶
type Docs struct {
Name string `json:"name" yaml:"name"`
Usage string `json:"usage" yaml:"usage"`
Short string `json:"short_desc" yaml:"short_desc"`
Desc string `json:"desc" yaml:"desc"`
}
Docs holds the help/usage text for a Command: its Name, cobra Usage string, one-line Short description, and longer Desc.