Help us shape the future of Go! Take the 2026 Go Developer Survey

cli

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 18 Imported by: 0

README

PkgGoDev Continuous Integration Coverage Status

cli4g

Typed command-line applications for Go: flags, arguments, subcommands, environment values, automatic help, and invocation-owned resources.

Install

Go 1.27.0+ is required.

go get github.com/echocat/cli4g

Quick start

package main

import (
    "context"
    "fmt"
    "os"

    cli "github.com/echocat/cli4g"
)

type options struct {
    Name     string `argument:"name" required:"true"`
    Greeting string `flag:"greeting" short:"g" default:"Hello"`
}

func main() {
    cli.NewApplication[options]().
		WithName("greet").
		WithHandler(greet).
		MustCreateParseAndExecute(context.Background(), nil, os.Args[1:]...)
}

func greet(_ context.Context, opts options) error {
	_, err := fmt.Printf("%s, %s!\n", opts.Greeting, opts.Name)
	return err
}
greet Ada                 # Hello, Ada!
greet -g Hey Ada          # Hey, Ada!
greet --help

The default error handler exits with 2 for input errors, 130 for cancellation, or 1 for other failures. For embedding, disable it with WithErrorHandlerEnabled(false).

Why cli4g?

  • Typed options: struct tags define inputs; handlers receive typed values.
  • Ordered lifecycle: parsing resolves and validates all selected options before initialization; handlers follow successful initialization.
  • Owned resources and cleanup: ParseAndExecute closes invocation-owned resources from child to parent, on success and returned errors—including partial initialization failures.
  • Reusable definitions: compile once, then parse independent invocations repeatedly or concurrently.
  • Consistent inputs: explicit CLI/environment/default precedence and validation rules.
  • Extensible values: custom codecs support application-specific types and resources.
  • Efficient reuse: competitive runtime and allocation costs in the measured workloads.

See benchmarks and methodology for timings, allocations, code size, and cognitive complexity.

Documentation

License

License · Contribute

Documentation

Overview

Package cli builds command-line applications with typed options, subcommands, flags, arguments, environment values, and automatic help.

Start with NewApplication, add a handler with ApplicationRequirement.WithHandler, and run ApplicationRequirement.MustCreateParseAndExecute from main. For caller-managed errors, use ApplicationRequirement.WithErrorHandlerEnabled and ApplicationRequirement.CreateParseAndExecute.

Options and bindings

Use exported fields in a struct or pointer-to-struct options type:

type Options struct {
    Name    string   `argument:"name" required:"true"`
    Port    uint32   `flag:"port" short:"p" env:"PORT" default:"8080"`
    Labels  []string `flag:"label"`
    Verbose bool     `flag:"verbose" short:"v"`
}

Supported tags:

  • flag|argument=<NAME>: name an input; `|` separates flag aliases
  • short=<RUNE>: names single-rune aliases
  • description=<STRING>: displays more information for help
  • placeholder=<STRING>: define how the placeholder is displayed in help
  • env=<NAME>: names environment sources; `|` separates fallback names, in order
  • default=<VALUE>: supplies a single input token
  • required=<true|false>: demands explicit input
  • type=<NAME>: selects a named codec registered with ApplicationRequirement.WithCodec
  • visible=<true|false>: If `false`, hides a flag from default help

Builders offer the same inputs. Bind them explicitly with FlagRequirement.WithField or ArgumentRequirement.WithField; names alone do not bind fields. Explicit bindings override tags on that field.

Input rules

  • Flags accept `--name=value`, `--name value`, short flags, and short clusters.
  • Bare bool flags mean true; use `--verbose=false` for false.
  • Slice flags collect one element per occurrence, preserving order and duplicates.
  • Slice arguments collect remaining values and must be last.
  • Map flags collect one key=value pair per occurrence; duplicate keys are errors.
  • Map arguments collect remaining pairs and must be last. Map helpers use string keys.
  • Use `--` before positional values starting with `-`, including negative numbers.
  • Subcommands are selected before the first positional value; flags are inherited.

Flag precedence is CLI, environment, declared default, options factory, zero. Arguments omit the environment step. CLI slices and maps replace defaults/factory values. Inputs are not shell-split or CSV-split. Required inputs cannot have defaults; factory values do not satisfy them. Required parent arguments cannot precede subcommands. See FlagRequirement, ArgumentRequirement, and ParseOpts.

Commands and parent options

Add typed commands with NewCommand and ApplicationRequirement.WithCommand. A child can borrow an exported struct pointer using parent:"application" or parent:"matchingType". MatchingType picks the nearest selected ancestor of the exact Go type. Borrowed options remain parent-owned; never close them in the child. Anonymous parent fields must not promote Validate, Initialize, or Close methods. Use ApplicationFromContext, CommandFromContext, or Command.OptionsFrom to read the current typed options.

Lifecycle and errors

Application.Parse resolves inputs, then validates and initializes options. Invocation.Execute runs handlers from application to selected leaf. Always close a successful Invocation, then its Application. Application.ParseAndExecute manages invocation cleanup for you. Pointer options retain field assignments; struct callbacks receive copies. See Validatable, Initializable, and ApplicationRequirement.WithCloseHandler.

Mark invalid user input with NewValidationError or NewValidationErrorf. Other errors remain operational. DefaultErrorHandler writes to stderr and exits with 2 for invalid input, 130 for cancellation, or 1 for other errors. Disable responses when embedding the library: os.Exit does not run caller defers.

Help and files

--help/-h is enabled by default and reserves those names. Help stops scanning immediately, skips options creation, and runs only the help handler. Earlier syntax errors and invalid displayed defaults still fail. Customize with ApplicationRequirement.WithHelpHandler and NewTemplatedHelpHandler.

File tags fileMode:"read|write|readWrite" and allowSpecial:"true" configure *os.File inputs. Invocations own codec-opened handles. Write modes create missing files but do not truncate existing files. Use the codec package for explicit append/truncate policies, dates, adapters, and custom value types.

Index

Examples

Constants

View Source
const DefaultApplicationHelpTemplate = `` /* 432-byte string literal not displayed */

DefaultApplicationHelpTemplate renders complete application help.

View Source
const DefaultArgumentHelpTemplate = `` /* 143-byte string literal not displayed */

DefaultArgumentHelpTemplate renders one positional argument.

View Source
const DefaultCommandEntryHelpTemplate = `  {{.Label}}{{if .Description}}	{{.Description}}{{end}}
`

DefaultCommandEntryHelpTemplate renders one available command.

View Source
const DefaultCommandHelpTemplate = DefaultApplicationHelpTemplate

DefaultCommandHelpTemplate renders complete selected-command help.

View Source
const DefaultFlagHelpTemplate = `` /* 195-byte string literal not displayed */

DefaultFlagHelpTemplate renders one own or inherited flag.

View Source
const DefaultUsageHelpTemplate = `Usage:
  {{.Usage}}
`

DefaultUsageHelpTemplate renders invocation syntax.

Variables

View Source
var (
	ErrInvocationNotReady = errors.New("invocation is not initialized")
	ErrInvocationClosed   = errors.New("invocation is already closed")
)
View Source
var ErrApplicationClosed = errors.New("application is closed")
View Source
var ErrValidation = codec.ErrValidation

ErrValidation is the codec package's shared invalid-input sentinel.

Functions

func ApplicationFromContext

func ApplicationFromContext[O any](ctx context.Context) (O, bool)

ApplicationFromContext returns the current root options, without cloning or resolving anything. Missing invocation/options or a wrong type returns false. Reference fields share data with the invocation; struct options are copied.

func CommandFromContext

func CommandFromContext[O any](ctx context.Context, path ...string) (O, bool)

CommandFromContext returns the current command's options when path is empty. An explicit path starts at the application and must identify a command selected in this invocation. Aliases are accepted; no options are created by this getter.

func FlagFromContext

func FlagFromContext[V any](ctx context.Context, name string) (V, bool)

FlagFromContext returns the existing decoded value, including declared defaults and environment inputs. Factory-only fields are available through options. A present typed nil, empty string, false or zero remains found=true.

func IsValidationError

func IsValidationError(err error) bool

IsValidationError recognizes the shared sentinel through wrapping and errors.Join.

func NewValidationError

func NewValidationError(err error) error

NewValidationError marks an input failure without changing its message or cause.

func NewValidationErrorf

func NewValidationErrorf(format string, args ...any) error

NewValidationErrorf formats an input failure, preserving causes supplied with %w.

Example
package main

import (
	"fmt"

	cli "github.com/echocat/cli4g"
)

func main() {
	err := cli.NewValidationErrorf("port must be positive")
	fmt.Println(cli.IsValidationError(err))
	fmt.Println(err)
}
Output:
true
port must be positive

Types

type Application

type Application[O any] struct {
	// contains filtered or unexported fields
}

Application is a reusable CLI definition with options of type O. Obtain it from ApplicationRequirement.Create; close invocations before Application.Close. Concurrent parses require concurrent-safe user callbacks.

func (Application) Argument

func (this Application) Argument(index int) (*Argument[any, any], bool)

Argument returns the definition at index, whether or not an invocation has a value for it. Invocation.Argument uses this same definition index.

func (Application) Arguments

func (this Application) Arguments() iter.Seq[*Argument[any, any]]

func (*Application[O]) Close

func (this *Application[O]) Close() error

Close prevents further parsing and execution, including through commands. Close all invocations first. Repeated calls are safe; metadata stays readable.

func (*Application[O]) CloseOptions

func (this *Application[O]) CloseOptions(options O) error

CloseOptions runs the close callback and options' Close method, including for partially initialized caller-owned options.

func (Application) Command

func (this Application) Command(name string) (CommandLike, bool)

func (Application) Commands

func (this Application) Commands() iter.Seq[CommandLike]

func (*Application[O]) Description

func (this *Application[O]) Description() string

Description returns the help description.

func (*Application[O]) Execute

func (this *Application[O]) Execute(ctx context.Context, options O) error

Execute runs the application handler with caller-owned options. It does not parse, validate, initialize, or close those options. Use Application.ParseAndExecute for the complete CLI lifecycle.

func (Application) Flag

func (this Application) Flag(name string) (*Flag[any, any], bool)

func (Application) Flags

func (this Application) Flags() iter.Seq[*Flag[any, any]]

func (*Application[O]) Initialize

func (this *Application[O]) Initialize(ctx context.Context, options O) error

Initialize runs options methods and callbacks like Parse. Use pointer options when assignments must be retained by the caller; struct arguments are copies.

func (*Application[O]) MustParse

func (this *Application[O]) MustParse(ctx context.Context, opts *ParseOpts, vs ...string) *Invocation[O]

MustParse calls Application.Parse and panics on a returned error.

func (*Application[O]) MustParseAndExecute

func (this *Application[O]) MustParseAndExecute(ctx context.Context, opts *ParseOpts, vs ...string)

MustParseAndExecute calls Application.ParseAndExecute and panics on a returned error.

func (*Application[O]) Name

func (this *Application[O]) Name() string

Name returns the application's command-line name.

func (*Application[O]) Names

func (this *Application[O]) Names() []string

Names returns a new slice containing Application.Name.

func (Application) OptionsType

func (this Application) OptionsType() reflect.Type

func (*Application[O]) Parse

func (this *Application[O]) Parse(ctx context.Context, opts *ParseOpts, vs ...string) (_ *Invocation[O], err error)

Parse decodes vs, resolves values, validates options, and initializes them. Always close a successful Invocation, even when it is not executed. Failure cleans up and returns nil; the configured ErrorHandler may exit. Use ApplicationRequirement.WithErrorHandlerEnabled for caller-managed errors.

A true --help/-h stops scanning and skips options creation and initialization. Nil opts uses the OS environment; nil ctx uses context.Background. Callbacks must honor cancellation. The definition supports repeated and concurrent parsing; each invocation owns its options and resources. Direct Execute calls from parse hooks share this operation's error boundary.

Example
package main

import (
	"context"
	"fmt"

	cli "github.com/echocat/cli4g"
)

func main() {
	app := cli.NewSimpleApplication().
		WithName("labels").
		WithErrorHandlerEnabled(false).
		WithStringSliceFlag("label").
		MustCreate()
	defer func() {
		if err := app.Close(); err != nil {
			panic(err)
		}
	}()
	invocation, err := app.Parse(context.Background(), nil, "--label=blue", "--label=green")
	if err != nil {
		panic(err)
	}
	defer func() {
		if err := invocation.Close(); err != nil {
			panic(err)
		}
	}()
	_, labels := invocation.Flag("label")
	fmt.Println(labels)
}
Output:
[blue green]

func (*Application[O]) ParseAndExecute

func (this *Application[O]) ParseAndExecute(ctx context.Context, opts *ParseOpts, vs ...string) (err error)

ParseAndExecute parses, executes, and closes an invocation. The application remains reusable until Application.Close.

func (Application) ShortFlag

func (this Application) ShortFlag(short rune) (*Flag[any, any], bool)

func (*Application[O]) Validate

func (this *Application[O]) Validate(ctx context.Context, options O) error

Validate runs the options' Validate method followed by the configured callback.

type ApplicationRequirement

type ApplicationRequirement[O any] struct {
	Name        string
	Description string
	// Help enables automatic --help/-h throughout the command tree. Constructors
	// enable it by default; a zero-valued requirement has it disabled.
	Help         bool
	HelpHandler  HelpHandler
	ErrorHandler ErrorHandler

	Commands  []CommandRequirementLike
	Codecs    []codec.Registration
	Flags     []FlagRequirementLike
	Arguments []ArgumentRequirementLike

	CreateOptionsHandler func(context.Context) (O, error)
	ValidateHandler      func(context.Context, O) error
	InitializeHandler    func(context.Context, O) error
	Handler              func(context.Context, O) error
	CloseHandler         func(O) error
	// contains filtered or unexported fields
}

ApplicationRequirement configures options, inputs, commands, and handlers. Call ApplicationRequirement.Create to obtain an independent Application. Use pointer options when callbacks need to retain field assignments.

func NewApplication

func NewApplication[O any]() *ApplicationRequirement[O]

NewApplication starts a CLI builder with automatic --help/-h enabled. O must be a struct or pointer to a struct; exported tags define inputs. By default, input and execution errors use DefaultErrorHandler.

Example
package main

import (
	"context"
	"fmt"

	cli "github.com/echocat/cli4g"
)

func main() {
	type options struct {
		Name     string `argument:"name" required:"true"`
		Greeting string `flag:"greeting" short:"g" default:"Hello"`
	}
	cli.NewApplication[options]().WithName("greet").
		WithHandler(func(_ context.Context, opts options) error {
			_, err := fmt.Printf("%s, %s!\n", opts.Greeting, opts.Name)
			return err
		}).MustCreateParseAndExecute(context.Background(), nil, "Ada")
}
Output:
Hello, Ada!

func NewSimpleApplication

func NewSimpleApplication() *ApplicationRequirement[NoOptions]

NewSimpleApplication starts a builder without an options struct. Read unbound values through Invocation.Flag and Invocation.Argument.

func (*ApplicationRequirement[O]) AddArgument added in v0.1.1

func (this *ApplicationRequirement[O]) AddArgument(v ...ArgumentRequirementLike)

func (*ApplicationRequirement[O]) AddCodec added in v0.1.1

func (this *ApplicationRequirement[O]) AddCodec(v any, names ...string)

func (*ApplicationRequirement[O]) AddCommand added in v0.1.1

func (this *ApplicationRequirement[O]) AddCommand(v ...CommandRequirementLike)

func (*ApplicationRequirement[O]) AddFlag added in v0.1.1

func (this *ApplicationRequirement[O]) AddFlag(v ...FlagRequirementLike)

func (*ApplicationRequirement[O]) Create

func (r *ApplicationRequirement[O]) Create() (_ *Application[O], err error)

Create compiles an independent read-only snapshot of the requirements. Requirements must not be modified concurrently with Create. Containers with subcommands cannot declare required positional arguments, because subcommands are recognized only before the first positional value.

func (*ApplicationRequirement[O]) CreateParseAndExecute

func (r *ApplicationRequirement[O]) CreateParseAndExecute(ctx context.Context, opts *ParseOpts, vs ...string) (err error)

CreateParseAndExecute manages compilation, parsing, execution and cleanup. Execution and completion-cleanup errors reach the error handler once, after cleanup. Configuration errors return directly without invoking a handler.

func (*ApplicationRequirement[O]) MustCreate

func (r *ApplicationRequirement[O]) MustCreate() *Application[O]

MustCreate compiles the application and panics on invalid configuration.

func (*ApplicationRequirement[O]) MustCreateParseAndExecute

func (r *ApplicationRequirement[O]) MustCreateParseAndExecute(ctx context.Context, opts *ParseOpts, vs ...string)

MustCreateParseAndExecute is the panic-on-returned-error variant. Standard handlers exit for ordinary parse/execution failures; invalid schemas panic. With returning or disabled handlers, their errors also cause a panic.

func (*ApplicationRequirement[O]) OptionsType

func (this *ApplicationRequirement[O]) OptionsType() reflect.Type

func (*ApplicationRequirement[O]) SetArguments

func (this *ApplicationRequirement[O]) SetArguments(v []ArgumentRequirementLike)

func (*ApplicationRequirement[O]) SetCloseHandler

func (this *ApplicationRequirement[O]) SetCloseHandler(v func(O) error)

func (*ApplicationRequirement[O]) SetCodecs

func (this *ApplicationRequirement[O]) SetCodecs(v []codec.Registration)

func (*ApplicationRequirement[O]) SetCommands

func (this *ApplicationRequirement[O]) SetCommands(v []CommandRequirementLike)

func (*ApplicationRequirement[O]) SetCreateOptionsHandler

func (this *ApplicationRequirement[O]) SetCreateOptionsHandler(v func(context.Context) (O, error))

func (*ApplicationRequirement[O]) SetDescription

func (this *ApplicationRequirement[O]) SetDescription(v string)

func (*ApplicationRequirement[O]) SetErrorHandler

func (this *ApplicationRequirement[O]) SetErrorHandler(v ErrorHandler)

func (*ApplicationRequirement[O]) SetErrorHandlerEnabled

func (this *ApplicationRequirement[O]) SetErrorHandlerEnabled(v bool)

func (*ApplicationRequirement[O]) SetFlags

func (this *ApplicationRequirement[O]) SetFlags(v []FlagRequirementLike)

func (*ApplicationRequirement[O]) SetHandler

func (this *ApplicationRequirement[O]) SetHandler(v func(context.Context, O) error)

func (*ApplicationRequirement[O]) SetHelp

func (this *ApplicationRequirement[O]) SetHelp(v bool)

func (*ApplicationRequirement[O]) SetHelpHandler

func (this *ApplicationRequirement[O]) SetHelpHandler(v HelpHandler)

func (*ApplicationRequirement[O]) SetInitializeHandler

func (this *ApplicationRequirement[O]) SetInitializeHandler(v func(context.Context, O) error)

func (*ApplicationRequirement[O]) SetName

func (this *ApplicationRequirement[O]) SetName(v string)

func (*ApplicationRequirement[O]) SetValidateHandler

func (this *ApplicationRequirement[O]) SetValidateHandler(v func(context.Context, O) error)

func (*ApplicationRequirement[O]) WithArgument

WithArgument adds positional arguments in order. Variadic arguments must be last. Bind options fields with ArgumentRequirement.WithField.

func (*ApplicationRequirement[O]) WithBoolArgument

func (this *ApplicationRequirement[O]) WithBoolArgument(name string, configure ...func(*ArgumentRequirement[bool, bool])) *ApplicationRequirement[O]

WithBoolArgument adds a standard bool argument. Like all typed argument helpers, it sets the name before applying callbacks in order. Fields bind only via WithField. Bool arguments consume one explicit input value.

func (*ApplicationRequirement[O]) WithBoolFlag

func (this *ApplicationRequirement[O]) WithBoolFlag(name string, configure ...func(*FlagRequirement[bool, bool])) *ApplicationRequirement[O]

WithBoolFlag adds a standard bool flag. Like all typed flag helpers, it sets the name before applying callbacks in order. Fields bind only via WithField.

func (*ApplicationRequirement[O]) WithBoolMapArgument added in v0.1.2

func (this *ApplicationRequirement[O]) WithBoolMapArgument(name string, configure ...func(*ArgumentRequirement[map[string]bool, map[string]bool])) *ApplicationRequirement[O]

WithBoolMapArgument adds a final variadic map[string]bool argument. Map arguments accept key=value pairs and reject duplicate keys.

func (*ApplicationRequirement[O]) WithBoolMapFlag added in v0.1.2

func (this *ApplicationRequirement[O]) WithBoolMapFlag(name string, configure ...func(*FlagRequirement[map[string]bool, map[string]bool])) *ApplicationRequirement[O]

WithBoolMapFlag adds a repeatable map[string]bool flag. Map helpers accept one key=value pair per occurrence and reject duplicate keys. Bind via WithField.

func (*ApplicationRequirement[O]) WithBoolSliceArgument

func (this *ApplicationRequirement[O]) WithBoolSliceArgument(name string, configure ...func(*ArgumentRequirement[[]bool, []bool])) *ApplicationRequirement[O]

WithBoolSliceArgument adds a standard variadic []bool argument. Like all standard slice arguments, it must be the final argument in its container.

func (*ApplicationRequirement[O]) WithBoolSliceFlag

func (this *ApplicationRequirement[O]) WithBoolSliceFlag(name string, configure ...func(*FlagRequirement[[]bool, []bool])) *ApplicationRequirement[O]

WithBoolSliceFlag adds a standard []bool flag. Slice helpers accept one value per occurrence and retain the standard codec's aggregation/default semantics.

func (*ApplicationRequirement[O]) WithCloseHandler

func (this *ApplicationRequirement[O]) WithCloseHandler(v func(O) error) *ApplicationRequirement[O]

WithCloseHandler provides cleanup for every created options instance, even after failed decoding, validation, or partial initialization. It must tolerate partially populated options. Options implementing io.Closer are also closed.

func (*ApplicationRequirement[O]) WithCodec

func (this *ApplicationRequirement[O]) WithCodec(v any, names ...string) *ApplicationRequirement[O]

WithCodec accepts an immutable codec.Codec[V, R]. Create validates and snapshots the codec; names bind it to matching options type tags.

func (*ApplicationRequirement[O]) WithCommand

WithCommand adds subcommands. Different commands may use different options types.

func (*ApplicationRequirement[O]) WithComplex64Argument

func (this *ApplicationRequirement[O]) WithComplex64Argument(name string, configure ...func(*ArgumentRequirement[complex64, complex64])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithComplex64Flag

func (this *ApplicationRequirement[O]) WithComplex64Flag(name string, configure ...func(*FlagRequirement[complex64, complex64])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithComplex64MapArgument added in v0.1.2

func (this *ApplicationRequirement[O]) WithComplex64MapArgument(name string, configure ...func(*ArgumentRequirement[map[string]complex64, map[string]complex64])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithComplex64MapFlag added in v0.1.2

func (this *ApplicationRequirement[O]) WithComplex64MapFlag(name string, configure ...func(*FlagRequirement[map[string]complex64, map[string]complex64])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithComplex64SliceArgument

func (this *ApplicationRequirement[O]) WithComplex64SliceArgument(name string, configure ...func(*ArgumentRequirement[[]complex64, []complex64])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithComplex64SliceFlag

func (this *ApplicationRequirement[O]) WithComplex64SliceFlag(name string, configure ...func(*FlagRequirement[[]complex64, []complex64])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithComplex128Argument

func (this *ApplicationRequirement[O]) WithComplex128Argument(name string, configure ...func(*ArgumentRequirement[complex128, complex128])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithComplex128Flag

func (this *ApplicationRequirement[O]) WithComplex128Flag(name string, configure ...func(*FlagRequirement[complex128, complex128])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithComplex128MapArgument added in v0.1.2

func (this *ApplicationRequirement[O]) WithComplex128MapArgument(name string, configure ...func(*ArgumentRequirement[map[string]complex128, map[string]complex128])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithComplex128MapFlag added in v0.1.2

func (this *ApplicationRequirement[O]) WithComplex128MapFlag(name string, configure ...func(*FlagRequirement[map[string]complex128, map[string]complex128])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithComplex128SliceArgument

func (this *ApplicationRequirement[O]) WithComplex128SliceArgument(name string, configure ...func(*ArgumentRequirement[[]complex128, []complex128])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithComplex128SliceFlag

func (this *ApplicationRequirement[O]) WithComplex128SliceFlag(name string, configure ...func(*FlagRequirement[[]complex128, []complex128])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithCreateOptionsHandler

func (this *ApplicationRequirement[O]) WithCreateOptionsHandler(v func(context.Context) (O, error)) *ApplicationRequirement[O]

WithCreateOptionsHandler supplies fresh options before input decoding. The concurrent-safe factory must return non-nil pointer options. Returned options are cleaned up even on error; unreturned resources remain caller-owned. Factory values do not satisfy required inputs. Initialize resources separately.

func (*ApplicationRequirement[O]) WithDateArgument

func (this *ApplicationRequirement[O]) WithDateArgument(name string, configure ...func(*ArgumentRequirement[time.Time, time.Time])) *ApplicationRequirement[O]

WithDateArgument adds a date-only argument; see codec.NewDate.

func (*ApplicationRequirement[O]) WithDateFlag

func (this *ApplicationRequirement[O]) WithDateFlag(name string, configure ...func(*FlagRequirement[time.Time, time.Time])) *ApplicationRequirement[O]

WithDateFlag adds a date-only flag; see codec.NewDate.

func (*ApplicationRequirement[O]) WithDateMapArgument added in v0.1.2

func (this *ApplicationRequirement[O]) WithDateMapArgument(name string, configure ...func(*ArgumentRequirement[map[string]time.Time, map[string]time.Time])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithDateMapFlag added in v0.1.2

func (this *ApplicationRequirement[O]) WithDateMapFlag(name string, configure ...func(*FlagRequirement[map[string]time.Time, map[string]time.Time])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithDateSliceArgument

func (this *ApplicationRequirement[O]) WithDateSliceArgument(name string, configure ...func(*ArgumentRequirement[[]time.Time, []time.Time])) *ApplicationRequirement[O]

WithDateSliceArgument adds variadic dates; see codec.NewDateSlice. It must be last.

func (*ApplicationRequirement[O]) WithDateSliceFlag

func (this *ApplicationRequirement[O]) WithDateSliceFlag(name string, configure ...func(*FlagRequirement[[]time.Time, []time.Time])) *ApplicationRequirement[O]

WithDateSliceFlag adds a repeatable date-only flag; see codec.NewDateSlice.

func (*ApplicationRequirement[O]) WithDateTimeArgument

func (this *ApplicationRequirement[O]) WithDateTimeArgument(name string, configure ...func(*ArgumentRequirement[time.Time, time.Time])) *ApplicationRequirement[O]

WithDateTimeArgument adds a timestamp argument; see codec.NewDateTime.

func (*ApplicationRequirement[O]) WithDateTimeFlag

func (this *ApplicationRequirement[O]) WithDateTimeFlag(name string, configure ...func(*FlagRequirement[time.Time, time.Time])) *ApplicationRequirement[O]

WithDateTimeFlag adds a timestamp flag; see codec.NewDateTime.

func (*ApplicationRequirement[O]) WithDateTimeMapArgument added in v0.1.2

func (this *ApplicationRequirement[O]) WithDateTimeMapArgument(name string, configure ...func(*ArgumentRequirement[map[string]time.Time, map[string]time.Time])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithDateTimeMapFlag added in v0.1.2

func (this *ApplicationRequirement[O]) WithDateTimeMapFlag(name string, configure ...func(*FlagRequirement[map[string]time.Time, map[string]time.Time])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithDateTimeSliceArgument

func (this *ApplicationRequirement[O]) WithDateTimeSliceArgument(name string, configure ...func(*ArgumentRequirement[[]time.Time, []time.Time])) *ApplicationRequirement[O]

WithDateTimeSliceArgument adds variadic timestamps; see codec.NewDateTimeSlice. It must be last.

func (*ApplicationRequirement[O]) WithDateTimeSliceFlag

func (this *ApplicationRequirement[O]) WithDateTimeSliceFlag(name string, configure ...func(*FlagRequirement[[]time.Time, []time.Time])) *ApplicationRequirement[O]

WithDateTimeSliceFlag adds a repeatable timestamp flag; see codec.NewDateTimeSlice.

func (*ApplicationRequirement[O]) WithDescription

func (this *ApplicationRequirement[O]) WithDescription(v string) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithDurationArgument

func (this *ApplicationRequirement[O]) WithDurationArgument(name string, configure ...func(*ArgumentRequirement[time.Duration, time.Duration])) *ApplicationRequirement[O]

WithDurationArgument adds a duration argument; use -- before negative values.

func (*ApplicationRequirement[O]) WithDurationFlag

func (this *ApplicationRequirement[O]) WithDurationFlag(name string, configure ...func(*FlagRequirement[time.Duration, time.Duration])) *ApplicationRequirement[O]

WithDurationFlag adds a flag accepting Go duration syntax; see codec.NewDuration.

func (*ApplicationRequirement[O]) WithDurationMapArgument added in v0.1.2

func (this *ApplicationRequirement[O]) WithDurationMapArgument(name string, configure ...func(*ArgumentRequirement[map[string]time.Duration, map[string]time.Duration])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithDurationMapFlag added in v0.1.2

func (this *ApplicationRequirement[O]) WithDurationMapFlag(name string, configure ...func(*FlagRequirement[map[string]time.Duration, map[string]time.Duration])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithDurationSliceArgument

func (this *ApplicationRequirement[O]) WithDurationSliceArgument(name string, configure ...func(*ArgumentRequirement[[]time.Duration, []time.Duration])) *ApplicationRequirement[O]

WithDurationSliceArgument adds variadic durations; it must be last.

func (*ApplicationRequirement[O]) WithDurationSliceFlag

func (this *ApplicationRequirement[O]) WithDurationSliceFlag(name string, configure ...func(*FlagRequirement[[]time.Duration, []time.Duration])) *ApplicationRequirement[O]

WithDurationSliceFlag adds a repeatable duration flag; see codec.NewDurationSlice.

func (*ApplicationRequirement[O]) WithErrorHandler

func (this *ApplicationRequirement[O]) WithErrorHandler(v ErrorHandler) *ApplicationRequirement[O]

WithErrorHandler replaces DefaultErrorHandler for input and operational errors. The handler runs after cleanup. A non-nil return replaces the error; nil preserves it. ErrValidation identifies input failures regardless of their phase.

func (*ApplicationRequirement[O]) WithErrorHandlerEnabled

func (this *ApplicationRequirement[O]) WithErrorHandlerEnabled(v bool) *ApplicationRequirement[O]

WithErrorHandlerEnabled controls this application's error response independently of the global default. Enabled is the default, including on zero requirements. A nil handler selects DefaultErrorHandler; disabling returns errors normally.

func (*ApplicationRequirement[O]) WithFileArgument

func (this *ApplicationRequirement[O]) WithFileArgument(name string, configure ...func(*ArgumentRequirement[*os.File, codec.FileRequirement])) *ApplicationRequirement[O]

WithFileArgument adds a read-only file argument; defaults use codec.FileRequirement.

func (*ApplicationRequirement[O]) WithFileFlag

func (this *ApplicationRequirement[O]) WithFileFlag(name string, configure ...func(*FlagRequirement[*os.File, codec.FileRequirement])) *ApplicationRequirement[O]

WithFileFlag adds a read-only file flag. Defaults use codec.FileRequirement; handles are invocation-owned. Select write policy with FlagRequirement.WithCodec.

func (*ApplicationRequirement[O]) WithFileMapArgument added in v0.1.2

func (this *ApplicationRequirement[O]) WithFileMapArgument(name string, configure ...func(*ArgumentRequirement[map[string]*os.File, map[string]codec.FileRequirement])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithFileMapFlag added in v0.1.2

func (this *ApplicationRequirement[O]) WithFileMapFlag(name string, configure ...func(*FlagRequirement[map[string]*os.File, map[string]codec.FileRequirement])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithFileSliceArgument

func (this *ApplicationRequirement[O]) WithFileSliceArgument(name string, configure ...func(*ArgumentRequirement[[]*os.File, []codec.FileRequirement])) *ApplicationRequirement[O]

WithFileSliceArgument adds variadic read-only files; it must be last.

func (*ApplicationRequirement[O]) WithFileSliceFlag

func (this *ApplicationRequirement[O]) WithFileSliceFlag(name string, configure ...func(*FlagRequirement[[]*os.File, []codec.FileRequirement])) *ApplicationRequirement[O]

WithFileSliceFlag adds a repeatable read-only file flag; see codec.NewSlice.

func (*ApplicationRequirement[O]) WithFlag

WithFlag adds explicit flags. Bind options fields with FlagRequirement.WithField.

func (*ApplicationRequirement[O]) WithFloat32Argument

func (this *ApplicationRequirement[O]) WithFloat32Argument(name string, configure ...func(*ArgumentRequirement[float32, float32])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithFloat32Flag

func (this *ApplicationRequirement[O]) WithFloat32Flag(name string, configure ...func(*FlagRequirement[float32, float32])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithFloat32MapArgument added in v0.1.2

func (this *ApplicationRequirement[O]) WithFloat32MapArgument(name string, configure ...func(*ArgumentRequirement[map[string]float32, map[string]float32])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithFloat32MapFlag added in v0.1.2

func (this *ApplicationRequirement[O]) WithFloat32MapFlag(name string, configure ...func(*FlagRequirement[map[string]float32, map[string]float32])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithFloat32SliceArgument

func (this *ApplicationRequirement[O]) WithFloat32SliceArgument(name string, configure ...func(*ArgumentRequirement[[]float32, []float32])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithFloat32SliceFlag

func (this *ApplicationRequirement[O]) WithFloat32SliceFlag(name string, configure ...func(*FlagRequirement[[]float32, []float32])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithFloat64Argument

func (this *ApplicationRequirement[O]) WithFloat64Argument(name string, configure ...func(*ArgumentRequirement[float64, float64])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithFloat64Flag

func (this *ApplicationRequirement[O]) WithFloat64Flag(name string, configure ...func(*FlagRequirement[float64, float64])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithFloat64MapArgument added in v0.1.2

func (this *ApplicationRequirement[O]) WithFloat64MapArgument(name string, configure ...func(*ArgumentRequirement[map[string]float64, map[string]float64])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithFloat64MapFlag added in v0.1.2

func (this *ApplicationRequirement[O]) WithFloat64MapFlag(name string, configure ...func(*FlagRequirement[map[string]float64, map[string]float64])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithFloat64SliceArgument

func (this *ApplicationRequirement[O]) WithFloat64SliceArgument(name string, configure ...func(*ArgumentRequirement[[]float64, []float64])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithFloat64SliceFlag

func (this *ApplicationRequirement[O]) WithFloat64SliceFlag(name string, configure ...func(*FlagRequirement[[]float64, []float64])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithHandler

func (this *ApplicationRequirement[O]) WithHandler(v func(context.Context, O) error) *ApplicationRequirement[O]

WithHandler receives this application's typed options. During invocation execution, InvocationFromContext and ContainerFromContext expose the complete invocation and the currently executing container.

func (*ApplicationRequirement[O]) WithHelp

func (this *ApplicationRequirement[O]) WithHelp(v bool) *ApplicationRequirement[O]

WithHelp enables or completely disables automatic help recognition and name reservation throughout the application, including every subcommand.

func (*ApplicationRequirement[O]) WithHelpHandler

func (this *ApplicationRequirement[O]) WithHelpHandler(v HelpHandler) *ApplicationRequirement[O]

WithHelpHandler replaces DefaultHelpHandler. Execute invokes it only for a help invocation; normal handlers and the options lifecycle are skipped.

func (*ApplicationRequirement[O]) WithInitializeHandler

func (this *ApplicationRequirement[O]) WithInitializeHandler(v func(context.Context, O) error) *ApplicationRequirement[O]

WithInitializeHandler prepares validated options after their Initialize method. Use pointer options to retain assignments. Release retained resources through ApplicationRequirement.WithCloseHandler or options' Close, including partial failures.

func (*ApplicationRequirement[O]) WithInt8Argument

func (this *ApplicationRequirement[O]) WithInt8Argument(name string, configure ...func(*ArgumentRequirement[int8, int8])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithInt8Flag

func (this *ApplicationRequirement[O]) WithInt8Flag(name string, configure ...func(*FlagRequirement[int8, int8])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithInt8MapArgument added in v0.1.2

func (this *ApplicationRequirement[O]) WithInt8MapArgument(name string, configure ...func(*ArgumentRequirement[map[string]int8, map[string]int8])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithInt8MapFlag added in v0.1.2

func (this *ApplicationRequirement[O]) WithInt8MapFlag(name string, configure ...func(*FlagRequirement[map[string]int8, map[string]int8])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithInt8SliceArgument

func (this *ApplicationRequirement[O]) WithInt8SliceArgument(name string, configure ...func(*ArgumentRequirement[[]int8, []int8])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithInt8SliceFlag

func (this *ApplicationRequirement[O]) WithInt8SliceFlag(name string, configure ...func(*FlagRequirement[[]int8, []int8])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithInt16Argument

func (this *ApplicationRequirement[O]) WithInt16Argument(name string, configure ...func(*ArgumentRequirement[int16, int16])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithInt16Flag

func (this *ApplicationRequirement[O]) WithInt16Flag(name string, configure ...func(*FlagRequirement[int16, int16])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithInt16MapArgument added in v0.1.2

func (this *ApplicationRequirement[O]) WithInt16MapArgument(name string, configure ...func(*ArgumentRequirement[map[string]int16, map[string]int16])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithInt16MapFlag added in v0.1.2

func (this *ApplicationRequirement[O]) WithInt16MapFlag(name string, configure ...func(*FlagRequirement[map[string]int16, map[string]int16])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithInt16SliceArgument

func (this *ApplicationRequirement[O]) WithInt16SliceArgument(name string, configure ...func(*ArgumentRequirement[[]int16, []int16])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithInt16SliceFlag

func (this *ApplicationRequirement[O]) WithInt16SliceFlag(name string, configure ...func(*FlagRequirement[[]int16, []int16])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithInt32Argument

func (this *ApplicationRequirement[O]) WithInt32Argument(name string, configure ...func(*ArgumentRequirement[int32, int32])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithInt32Flag

func (this *ApplicationRequirement[O]) WithInt32Flag(name string, configure ...func(*FlagRequirement[int32, int32])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithInt32MapArgument added in v0.1.2

func (this *ApplicationRequirement[O]) WithInt32MapArgument(name string, configure ...func(*ArgumentRequirement[map[string]int32, map[string]int32])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithInt32MapFlag added in v0.1.2

func (this *ApplicationRequirement[O]) WithInt32MapFlag(name string, configure ...func(*FlagRequirement[map[string]int32, map[string]int32])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithInt32SliceArgument

func (this *ApplicationRequirement[O]) WithInt32SliceArgument(name string, configure ...func(*ArgumentRequirement[[]int32, []int32])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithInt32SliceFlag

func (this *ApplicationRequirement[O]) WithInt32SliceFlag(name string, configure ...func(*FlagRequirement[[]int32, []int32])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithInt64Argument

func (this *ApplicationRequirement[O]) WithInt64Argument(name string, configure ...func(*ArgumentRequirement[int64, int64])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithInt64Flag

func (this *ApplicationRequirement[O]) WithInt64Flag(name string, configure ...func(*FlagRequirement[int64, int64])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithInt64MapArgument added in v0.1.2

func (this *ApplicationRequirement[O]) WithInt64MapArgument(name string, configure ...func(*ArgumentRequirement[map[string]int64, map[string]int64])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithInt64MapFlag added in v0.1.2

func (this *ApplicationRequirement[O]) WithInt64MapFlag(name string, configure ...func(*FlagRequirement[map[string]int64, map[string]int64])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithInt64SliceArgument

func (this *ApplicationRequirement[O]) WithInt64SliceArgument(name string, configure ...func(*ArgumentRequirement[[]int64, []int64])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithInt64SliceFlag

func (this *ApplicationRequirement[O]) WithInt64SliceFlag(name string, configure ...func(*FlagRequirement[[]int64, []int64])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithIntArgument

func (this *ApplicationRequirement[O]) WithIntArgument(name string, configure ...func(*ArgumentRequirement[int, int])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithIntFlag

func (this *ApplicationRequirement[O]) WithIntFlag(name string, configure ...func(*FlagRequirement[int, int])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithIntMapArgument added in v0.1.2

func (this *ApplicationRequirement[O]) WithIntMapArgument(name string, configure ...func(*ArgumentRequirement[map[string]int, map[string]int])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithIntMapFlag added in v0.1.2

func (this *ApplicationRequirement[O]) WithIntMapFlag(name string, configure ...func(*FlagRequirement[map[string]int, map[string]int])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithIntSliceArgument

func (this *ApplicationRequirement[O]) WithIntSliceArgument(name string, configure ...func(*ArgumentRequirement[[]int, []int])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithIntSliceFlag

func (this *ApplicationRequirement[O]) WithIntSliceFlag(name string, configure ...func(*FlagRequirement[[]int, []int])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithMarshallerArgument

func (this *ApplicationRequirement[O]) WithMarshallerArgument[T encoding.TextMarshaler, TP interface {
	*T
	encoding.TextUnmarshaler
}](name string, configure ...func(*ArgumentRequirement[T, string])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithMarshallerFlag

func (this *ApplicationRequirement[O]) WithMarshallerFlag[T encoding.TextMarshaler, TP interface {
	*T
	encoding.TextUnmarshaler
}](name string, configure ...func(*FlagRequirement[T, string])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithMarshallerMapArgument added in v0.1.2

func (this *ApplicationRequirement[O]) WithMarshallerMapArgument[T encoding.TextMarshaler, TP interface {
	*T
	encoding.TextUnmarshaler
}](name string, configure ...func(*ArgumentRequirement[map[string]T, map[string]string])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithMarshallerMapFlag added in v0.1.2

func (this *ApplicationRequirement[O]) WithMarshallerMapFlag[T encoding.TextMarshaler, TP interface {
	*T
	encoding.TextUnmarshaler
}](name string, configure ...func(*FlagRequirement[map[string]T, map[string]string])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithMarshallerPArgument

func (this *ApplicationRequirement[O]) WithMarshallerPArgument[T interface {
	encoding.TextMarshaler
	encoding.TextUnmarshaler
}](name string, factory func() T, configure ...func(*ArgumentRequirement[T, string])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithMarshallerPFlag

func (this *ApplicationRequirement[O]) WithMarshallerPFlag[T interface {
	encoding.TextMarshaler
	encoding.TextUnmarshaler
}](name string, factory func() T, configure ...func(*FlagRequirement[T, string])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithMarshallerPMapArgument added in v0.1.2

func (this *ApplicationRequirement[O]) WithMarshallerPMapArgument[T interface {
	encoding.TextMarshaler
	encoding.TextUnmarshaler
}](name string, factory func() T, configure ...func(*ArgumentRequirement[map[string]T, map[string]string])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithMarshallerPMapFlag added in v0.1.2

func (this *ApplicationRequirement[O]) WithMarshallerPMapFlag[T interface {
	encoding.TextMarshaler
	encoding.TextUnmarshaler
}](name string, factory func() T, configure ...func(*FlagRequirement[map[string]T, map[string]string])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithMarshallerPSliceArgument

func (this *ApplicationRequirement[O]) WithMarshallerPSliceArgument[T interface {
	encoding.TextMarshaler
	encoding.TextUnmarshaler
}](name string, factory func() T, configure ...func(*ArgumentRequirement[[]T, []string])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithMarshallerPSliceFlag

func (this *ApplicationRequirement[O]) WithMarshallerPSliceFlag[T interface {
	encoding.TextMarshaler
	encoding.TextUnmarshaler
}](name string, factory func() T, configure ...func(*FlagRequirement[[]T, []string])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithMarshallerSliceArgument

func (this *ApplicationRequirement[O]) WithMarshallerSliceArgument[T encoding.TextMarshaler, TP interface {
	*T
	encoding.TextUnmarshaler
}](name string, configure ...func(*ArgumentRequirement[[]T, []string])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithMarshallerSliceFlag

func (this *ApplicationRequirement[O]) WithMarshallerSliceFlag[T encoding.TextMarshaler, TP interface {
	*T
	encoding.TextUnmarshaler
}](name string, configure ...func(*FlagRequirement[[]T, []string])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithName

func (this *ApplicationRequirement[O]) WithName(v string) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithStringArgument

func (this *ApplicationRequirement[O]) WithStringArgument(name string, configure ...func(*ArgumentRequirement[string, string])) *ApplicationRequirement[O]

WithStringArgument adds a positional string; bind options with ArgumentRequirement.WithField.

func (*ApplicationRequirement[O]) WithStringFlag

func (this *ApplicationRequirement[O]) WithStringFlag(name string, configure ...func(*FlagRequirement[string, string])) *ApplicationRequirement[O]

WithStringFlag adds a string flag; bind options with FlagRequirement.WithField.

func (*ApplicationRequirement[O]) WithStringMapArgument added in v0.1.2

func (this *ApplicationRequirement[O]) WithStringMapArgument(name string, configure ...func(*ArgumentRequirement[map[string]string, map[string]string])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithStringMapFlag added in v0.1.2

func (this *ApplicationRequirement[O]) WithStringMapFlag(name string, configure ...func(*FlagRequirement[map[string]string, map[string]string])) *ApplicationRequirement[O]

WithStringMapFlag adds a repeatable map[string]string flag.

func (*ApplicationRequirement[O]) WithStringSliceArgument

func (this *ApplicationRequirement[O]) WithStringSliceArgument(name string, configure ...func(*ArgumentRequirement[[]string, []string])) *ApplicationRequirement[O]

WithStringSliceArgument adds a variadic string argument; it must be last.

func (*ApplicationRequirement[O]) WithStringSliceFlag

func (this *ApplicationRequirement[O]) WithStringSliceFlag(name string, configure ...func(*FlagRequirement[[]string, []string])) *ApplicationRequirement[O]

WithStringSliceFlag adds a repeatable string flag, one element per occurrence.

func (*ApplicationRequirement[O]) WithUint8Argument

func (this *ApplicationRequirement[O]) WithUint8Argument(name string, configure ...func(*ArgumentRequirement[uint8, uint8])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUint8Flag

func (this *ApplicationRequirement[O]) WithUint8Flag(name string, configure ...func(*FlagRequirement[uint8, uint8])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUint8MapArgument added in v0.1.2

func (this *ApplicationRequirement[O]) WithUint8MapArgument(name string, configure ...func(*ArgumentRequirement[map[string]uint8, map[string]uint8])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUint8MapFlag added in v0.1.2

func (this *ApplicationRequirement[O]) WithUint8MapFlag(name string, configure ...func(*FlagRequirement[map[string]uint8, map[string]uint8])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUint8SliceArgument

func (this *ApplicationRequirement[O]) WithUint8SliceArgument(name string, configure ...func(*ArgumentRequirement[[]uint8, []uint8])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUint8SliceFlag

func (this *ApplicationRequirement[O]) WithUint8SliceFlag(name string, configure ...func(*FlagRequirement[[]uint8, []uint8])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUint16Argument

func (this *ApplicationRequirement[O]) WithUint16Argument(name string, configure ...func(*ArgumentRequirement[uint16, uint16])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUint16Flag

func (this *ApplicationRequirement[O]) WithUint16Flag(name string, configure ...func(*FlagRequirement[uint16, uint16])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUint16MapArgument added in v0.1.2

func (this *ApplicationRequirement[O]) WithUint16MapArgument(name string, configure ...func(*ArgumentRequirement[map[string]uint16, map[string]uint16])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUint16MapFlag added in v0.1.2

func (this *ApplicationRequirement[O]) WithUint16MapFlag(name string, configure ...func(*FlagRequirement[map[string]uint16, map[string]uint16])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUint16SliceArgument

func (this *ApplicationRequirement[O]) WithUint16SliceArgument(name string, configure ...func(*ArgumentRequirement[[]uint16, []uint16])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUint16SliceFlag

func (this *ApplicationRequirement[O]) WithUint16SliceFlag(name string, configure ...func(*FlagRequirement[[]uint16, []uint16])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUint32Argument

func (this *ApplicationRequirement[O]) WithUint32Argument(name string, configure ...func(*ArgumentRequirement[uint32, uint32])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUint32Flag

func (this *ApplicationRequirement[O]) WithUint32Flag(name string, configure ...func(*FlagRequirement[uint32, uint32])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUint32MapArgument added in v0.1.2

func (this *ApplicationRequirement[O]) WithUint32MapArgument(name string, configure ...func(*ArgumentRequirement[map[string]uint32, map[string]uint32])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUint32MapFlag added in v0.1.2

func (this *ApplicationRequirement[O]) WithUint32MapFlag(name string, configure ...func(*FlagRequirement[map[string]uint32, map[string]uint32])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUint32SliceArgument

func (this *ApplicationRequirement[O]) WithUint32SliceArgument(name string, configure ...func(*ArgumentRequirement[[]uint32, []uint32])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUint32SliceFlag

func (this *ApplicationRequirement[O]) WithUint32SliceFlag(name string, configure ...func(*FlagRequirement[[]uint32, []uint32])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUint64Argument

func (this *ApplicationRequirement[O]) WithUint64Argument(name string, configure ...func(*ArgumentRequirement[uint64, uint64])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUint64Flag

func (this *ApplicationRequirement[O]) WithUint64Flag(name string, configure ...func(*FlagRequirement[uint64, uint64])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUint64MapArgument added in v0.1.2

func (this *ApplicationRequirement[O]) WithUint64MapArgument(name string, configure ...func(*ArgumentRequirement[map[string]uint64, map[string]uint64])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUint64MapFlag added in v0.1.2

func (this *ApplicationRequirement[O]) WithUint64MapFlag(name string, configure ...func(*FlagRequirement[map[string]uint64, map[string]uint64])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUint64SliceArgument

func (this *ApplicationRequirement[O]) WithUint64SliceArgument(name string, configure ...func(*ArgumentRequirement[[]uint64, []uint64])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUint64SliceFlag

func (this *ApplicationRequirement[O]) WithUint64SliceFlag(name string, configure ...func(*FlagRequirement[[]uint64, []uint64])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUintArgument

func (this *ApplicationRequirement[O]) WithUintArgument(name string, configure ...func(*ArgumentRequirement[uint, uint])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUintFlag

func (this *ApplicationRequirement[O]) WithUintFlag(name string, configure ...func(*FlagRequirement[uint, uint])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUintMapArgument added in v0.1.2

func (this *ApplicationRequirement[O]) WithUintMapArgument(name string, configure ...func(*ArgumentRequirement[map[string]uint, map[string]uint])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUintMapFlag added in v0.1.2

func (this *ApplicationRequirement[O]) WithUintMapFlag(name string, configure ...func(*FlagRequirement[map[string]uint, map[string]uint])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUintSliceArgument

func (this *ApplicationRequirement[O]) WithUintSliceArgument(name string, configure ...func(*ArgumentRequirement[[]uint, []uint])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUintSliceFlag

func (this *ApplicationRequirement[O]) WithUintSliceFlag(name string, configure ...func(*FlagRequirement[[]uint, []uint])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUintptrArgument

func (this *ApplicationRequirement[O]) WithUintptrArgument(name string, configure ...func(*ArgumentRequirement[uintptr, uintptr])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUintptrFlag

func (this *ApplicationRequirement[O]) WithUintptrFlag(name string, configure ...func(*FlagRequirement[uintptr, uintptr])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUintptrMapArgument added in v0.1.2

func (this *ApplicationRequirement[O]) WithUintptrMapArgument(name string, configure ...func(*ArgumentRequirement[map[string]uintptr, map[string]uintptr])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUintptrMapFlag added in v0.1.2

func (this *ApplicationRequirement[O]) WithUintptrMapFlag(name string, configure ...func(*FlagRequirement[map[string]uintptr, map[string]uintptr])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUintptrSliceArgument

func (this *ApplicationRequirement[O]) WithUintptrSliceArgument(name string, configure ...func(*ArgumentRequirement[[]uintptr, []uintptr])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithUintptrSliceFlag

func (this *ApplicationRequirement[O]) WithUintptrSliceFlag(name string, configure ...func(*FlagRequirement[[]uintptr, []uintptr])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithValidateHandler

func (this *ApplicationRequirement[O]) WithValidateHandler(v func(context.Context, O) error) *ApplicationRequirement[O]

WithValidateHandler checks fully decoded options after their Validate method and before any initializer runs. It must not mutate options or acquire resources. Mark invalid input with NewValidationErrorf; unmarked failures remain operational.

func (*ApplicationRequirement[O]) WithValueArgument

func (this *ApplicationRequirement[O]) WithValueArgument[T any, TP interface {
	*T
	codec.Value
}](name string, configure ...func(*ArgumentRequirement[T, []string])) *ApplicationRequirement[O]

WithValueArgument adds a positional Set/String value argument.

func (*ApplicationRequirement[O]) WithValueFlag

func (this *ApplicationRequirement[O]) WithValueFlag[T any, TP interface {
	*T
	codec.Value
}](name string, configure ...func(*FlagRequirement[T, []string])) *ApplicationRequirement[O]

WithValueFlag adds a Set/String value flag, keeping T as the field/value type.

func (*ApplicationRequirement[O]) WithValueMapArgument added in v0.1.2

func (this *ApplicationRequirement[O]) WithValueMapArgument[T any, TP interface {
	*T
	codec.Value
}](name string, configure ...func(*ArgumentRequirement[map[string]T, map[string][]string])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithValueMapFlag added in v0.1.2

func (this *ApplicationRequirement[O]) WithValueMapFlag[T any, TP interface {
	*T
	codec.Value
}](name string, configure ...func(*FlagRequirement[map[string]T, map[string][]string])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithValuePArgument

func (this *ApplicationRequirement[O]) WithValuePArgument[T codec.Value](name string, factory func() T, configure ...func(*ArgumentRequirement[T, []string])) *ApplicationRequirement[O]

WithValuePArgument adds a positional value with a fresh pointer factory.

func (*ApplicationRequirement[O]) WithValuePFlag

func (this *ApplicationRequirement[O]) WithValuePFlag[T codec.Value](name string, factory func() T, configure ...func(*FlagRequirement[T, []string])) *ApplicationRequirement[O]

WithValuePFlag adds a Set/String flag with a fresh pointer factory.

func (*ApplicationRequirement[O]) WithValuePMapArgument added in v0.1.2

func (this *ApplicationRequirement[O]) WithValuePMapArgument[T codec.Value](name string, factory func() T, configure ...func(*ArgumentRequirement[map[string]T, map[string][]string])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithValuePMapFlag added in v0.1.2

func (this *ApplicationRequirement[O]) WithValuePMapFlag[T codec.Value](name string, factory func() T, configure ...func(*FlagRequirement[map[string]T, map[string][]string])) *ApplicationRequirement[O]

func (*ApplicationRequirement[O]) WithValuePSliceArgument

func (this *ApplicationRequirement[O]) WithValuePSliceArgument[T codec.Value](name string, factory func() T, configure ...func(*ArgumentRequirement[[]T, [][]string])) *ApplicationRequirement[O]

WithValuePSliceArgument adds a final variadic slice of factory-created pointers.

func (*ApplicationRequirement[O]) WithValuePSliceFlag

func (this *ApplicationRequirement[O]) WithValuePSliceFlag[T codec.Value](name string, factory func() T, configure ...func(*FlagRequirement[[]T, [][]string])) *ApplicationRequirement[O]

WithValuePSliceFlag adds a repeated slice flag of factory-created pointers.

func (*ApplicationRequirement[O]) WithValueSliceArgument

func (this *ApplicationRequirement[O]) WithValueSliceArgument[T any, TP interface {
	*T
	codec.Value
}](name string, configure ...func(*ArgumentRequirement[[]T, [][]string])) *ApplicationRequirement[O]

WithValueSliceArgument adds a final variadic slice of Set/String values.

func (*ApplicationRequirement[O]) WithValueSliceFlag

func (this *ApplicationRequirement[O]) WithValueSliceFlag[T any, TP interface {
	*T
	codec.Value
}](name string, configure ...func(*FlagRequirement[[]T, [][]string])) *ApplicationRequirement[O]

WithValueSliceFlag adds a standard repeated slice flag of Set/String values.

type Argument

type Argument[V, R any] struct {
	// contains filtered or unexported fields
}

Argument describes a positional input. Use Invocation.Argument for parsed V and Argument.Default for its resource-free default R.

func (*Argument[V, R]) Codec

func (this *Argument[V, R]) Codec() codec.Codec[V, R]

func (*Argument[V, R]) Default

func (this *Argument[V, R]) Default(ctx context.Context) (value R, found bool, err error)

Default returns an independent resource-free requirement R, never a runtime V.

func (*Argument[V, R]) Description

func (this *Argument[V, R]) Description() string

func (*Argument[V, R]) FormatDefault

func (this *Argument[V, R]) FormatDefault(ctx context.Context) ([]string, bool, error)

FormatDefault returns help-safe default text without resolving resources.

func (*Argument[V, R]) HasDefault

func (this *Argument[V, R]) HasDefault() bool

func (*Argument[V, R]) IsRequired

func (this *Argument[V, R]) IsRequired() bool

func (*Argument[V, R]) Name

func (this *Argument[V, R]) Name() string

func (*Argument[V, R]) Placeholder

func (this *Argument[V, R]) Placeholder() string

func (*Argument[V, R]) ValueType

func (this *Argument[V, R]) ValueType() reflect.Type

type ArgumentRequirement

type ArgumentRequirement[V, R any] struct {
	Name        string
	Description string
	Required    bool
	Placeholder string
	Codec       codec.Codec[V, R]
	// CodecFactory supplies a codec at Create when Codec is nil. It configures
	// schema only; it must not acquire invocation resources.
	CodecFactory func() (codec.Codec[V, R], error)
	Field        []string
	// contains filtered or unexported fields
}

ArgumentRequirement configures a positional value V with input requirements R. Slice arguments must be last. Required arguments cannot have defaults or belong to a container with subcommands. Bool arguments require explicit input. See ArgumentRequirement.WithField and ArgumentRequirement.WithDefault. Explicit arguments retain registration order; field bindings replacing tags keep their tagged slots in mixed definitions. Other builder arguments come first.

func NewArgument

func NewArgument[V, R any](codec codec.Codec[V, R]) *ArgumentRequirement[V, R]

NewArgument starts a positional argument using codec. Set its name with ArgumentRequirement.WithName.

func (*ArgumentRequirement[V, R]) SetCodec

func (this *ArgumentRequirement[V, R]) SetCodec(v codec.Codec[V, R])

func (*ArgumentRequirement[V, R]) SetCodecFactory

func (this *ArgumentRequirement[V, R]) SetCodecFactory(v func() (codec.Codec[V, R], error))

func (*ArgumentRequirement[V, R]) SetDefault

func (this *ArgumentRequirement[V, R]) SetDefault(v R)

func (*ArgumentRequirement[V, R]) SetDefaultStr

func (this *ArgumentRequirement[V, R]) SetDefaultStr(v ...string)

func (*ArgumentRequirement[V, R]) SetDescription

func (this *ArgumentRequirement[V, R]) SetDescription(v string)

func (*ArgumentRequirement[V, R]) SetField

func (this *ArgumentRequirement[V, R]) SetField(v []string) *ArgumentRequirement[V, R]

func (*ArgumentRequirement[V, R]) SetName

func (this *ArgumentRequirement[V, R]) SetName(v string)

func (*ArgumentRequirement[V, R]) SetPlaceholder

func (this *ArgumentRequirement[V, R]) SetPlaceholder(v string)

func (*ArgumentRequirement[V, R]) SetRequired

func (this *ArgumentRequirement[V, R]) SetRequired(v bool)

func (*ArgumentRequirement[V, R]) WithCodec

func (this *ArgumentRequirement[V, R]) WithCodec(v codec.Codec[V, R]) *ArgumentRequirement[V, R]

WithCodec replaces the decoder and clears ArgumentRequirement.WithCodecFactory.

func (*ArgumentRequirement[V, R]) WithCodecFactory

func (this *ArgumentRequirement[V, R]) WithCodecFactory(v func() (codec.Codec[V, R], error)) *ArgumentRequirement[V, R]

WithCodecFactory configures the decoder during Create and replaces ArgumentRequirement.WithCodec. The factory must not acquire runtime resources; configuration errors fail Create.

func (*ArgumentRequirement[V, R]) WithDefault

func (this *ArgumentRequirement[V, R]) WithDefault(v R) *ArgumentRequirement[V, R]

WithDefault sets a resource-free typed default R for an omitted optional argument. R may differ from V; each parse receives an independent copy.

func (*ArgumentRequirement[V, R]) WithDefaultStr

func (this *ArgumentRequirement[V, R]) WithDefaultStr(v ...string) *ArgumentRequirement[V, R]

WithDefaultStr sets a complete codec input without shell or CSV splitting. Either default setter replaces the previously configured default.

func (*ArgumentRequirement[V, R]) WithDescription

func (this *ArgumentRequirement[V, R]) WithDescription(v string) *ArgumentRequirement[V, R]

func (*ArgumentRequirement[V, R]) WithField

func (this *ArgumentRequirement[V, R]) WithField(v ...string) *ArgumentRequirement[V, R]

WithField binds V to an exported options field; v is its nested field path. Explicit binding overrides that field's tags; an input name alone does not bind.

func (*ArgumentRequirement[V, R]) WithName

func (this *ArgumentRequirement[V, R]) WithName(v string) *ArgumentRequirement[V, R]

func (*ArgumentRequirement[V, R]) WithPlaceholder

func (this *ArgumentRequirement[V, R]) WithPlaceholder(v string) *ArgumentRequirement[V, R]

func (*ArgumentRequirement[V, R]) WithRequired

func (this *ArgumentRequirement[V, R]) WithRequired(v bool) *ArgumentRequirement[V, R]

WithRequired demands a positional value. Defaults and factory values cannot satisfy it; containers with subcommands cannot declare required arguments.

type ArgumentRequirementLike

type ArgumentRequirementLike interface {
	// contains filtered or unexported methods
}

ArgumentRequirementLike allows differently typed arguments in one builder. It is implemented by ArgumentRequirement, not by callers.

type Command

type Command[O any] struct {
	// contains filtered or unexported fields
}

Command is a typed command definition belonging to an Application. Build it with NewCommand. Read selected options with Command.OptionsFrom.

func FindCommand

func FindCommand[O any](container Container, path ...string) (*Command[O], bool)

FindCommand resolves a command path and verifies its options type once. The returned handle provides typed access to that command's invocation options.

func (Command) Argument

func (this Command) Argument(index int) (*Argument[any, any], bool)

Argument returns the definition at index, whether or not an invocation has a value for it. Invocation.Argument uses this same definition index.

func (Command) Arguments

func (this Command) Arguments() iter.Seq[*Argument[any, any]]

func (*Command[O]) Close

func (c *Command[O]) Close(options O) error

Close runs the close callback and options' Close method, including partial state.

func (Command) Command

func (this Command) Command(name string) (CommandLike, bool)

func (Command) Commands

func (this Command) Commands() iter.Seq[CommandLike]

func (*Command[O]) Description

func (c *Command[O]) Description() string

Description returns the help description.

func (*Command[O]) Execute

func (c *Command[O]) Execute(ctx context.Context, options O) error

Execute runs this command's handler with caller-owned options. It does not parse, validate, initialize, or close those options.

func (Command) Flag

func (this Command) Flag(name string) (*Flag[any, any], bool)

func (Command) Flags

func (this Command) Flags() iter.Seq[*Flag[any, any]]

func (*Command[O]) Initialize

func (c *Command[O]) Initialize(ctx context.Context, options O) error

Initialize runs options methods and callbacks. Use pointer options to retain mutations in the caller's instance; struct arguments follow Go value semantics.

func (*Command[O]) IsVisible added in v0.1.2

func (c *Command[O]) IsVisible() bool

IsVisible reports whether the command appears in help listings.

func (*Command[O]) Name

func (c *Command[O]) Name() string

Name returns the primary command name.

func (*Command[O]) Names

func (c *Command[O]) Names() []string

Names returns a new slice containing the primary name and aliases.

func (*Command[O]) OptionsFrom

func (c *Command[O]) OptionsFrom(invocation InvocationLike) (O, bool)

OptionsFrom reads this command's options from an invocation. Unselected commands and help invocations return false. Structs are copied; pointers and reference fields share invocation-owned data.

func (Command) OptionsType

func (this Command) OptionsType() reflect.Type

func (Command) ShortFlag

func (this Command) ShortFlag(short rune) (*Flag[any, any], bool)

func (*Command[O]) Validate

func (c *Command[O]) Validate(ctx context.Context, options O) error

Validate runs the options' Validate method followed by the configured callback.

type CommandLike

type CommandLike interface {
	Container
	IsVisible() bool
	// contains filtered or unexported methods
}

CommandLike allows commands with different options types in one command tree.

type CommandRequirement

type CommandRequirement[O any] struct {
	// Names contains the primary name followed by aliases.
	Names []string

	Description string
	Visible     bool

	Commands  []CommandRequirementLike
	Codecs    []codec.Registration
	Flags     []FlagRequirementLike
	Arguments []ArgumentRequirementLike

	CreateOptionsHandler func(context.Context) (O, error)
	ValidateHandler      func(context.Context, O) error
	InitializeHandler    func(context.Context, O) error
	Handler              func(context.Context, O) error
	CloseHandler         func(O) error
}

CommandRequirement configures a command's names, options, inputs, and handlers. Struct callbacks receive copies; use pointer options to retain assignments.

func NewCommand

func NewCommand[O any]() *CommandRequirement[O]

NewCommand starts a visible command builder with struct or pointer-to-struct options O. Attach it using ApplicationRequirement.WithCommand or CommandRequirement.WithCommand.

Example
package main

import (
	"context"
	"fmt"

	cli "github.com/echocat/cli4g"
)

func main() {
	type options struct {
		Name string `argument:"name" default:"Ada"`
	}
	command := cli.NewCommand[options]().WithName("hello").
		WithHandler(func(_ context.Context, opts options) error {
			_, err := fmt.Println("Hello, " + opts.Name + "!")
			return err
		})
	cli.NewSimpleApplication().
		WithName("app").
		WithCommand(command).
		MustCreateParseAndExecute(context.Background(), nil, "hello", "Grace")
}
Output:
Hello, Grace!

func NewSimpleCommand

func NewSimpleCommand() *CommandRequirement[NoOptions]

NewSimpleCommand starts a command without an options struct.

func (*CommandRequirement[O]) AddArgument added in v0.1.1

func (this *CommandRequirement[O]) AddArgument(v ...ArgumentRequirementLike)

func (*CommandRequirement[O]) AddCodec added in v0.1.1

func (this *CommandRequirement[O]) AddCodec(v any, names ...string)

func (*CommandRequirement[O]) AddCommand added in v0.1.1

func (this *CommandRequirement[O]) AddCommand(v ...CommandRequirementLike)

func (*CommandRequirement[O]) AddFlag added in v0.1.1

func (this *CommandRequirement[O]) AddFlag(v ...FlagRequirementLike)

func (*CommandRequirement[O]) OptionsType

func (this *CommandRequirement[O]) OptionsType() reflect.Type

func (*CommandRequirement[O]) SetArguments

func (this *CommandRequirement[O]) SetArguments(v []ArgumentRequirementLike)

func (*CommandRequirement[O]) SetCloseHandler

func (this *CommandRequirement[O]) SetCloseHandler(v func(O) error)

func (*CommandRequirement[O]) SetCodecs

func (this *CommandRequirement[O]) SetCodecs(v []codec.Registration)

func (*CommandRequirement[O]) SetCommands

func (this *CommandRequirement[O]) SetCommands(v []CommandRequirementLike)

func (*CommandRequirement[O]) SetCreateOptionsHandler

func (this *CommandRequirement[O]) SetCreateOptionsHandler(v func(context.Context) (O, error))

func (*CommandRequirement[O]) SetDescription

func (this *CommandRequirement[O]) SetDescription(v string)

func (*CommandRequirement[O]) SetFlags

func (this *CommandRequirement[O]) SetFlags(v []FlagRequirementLike)

func (*CommandRequirement[O]) SetHandler

func (this *CommandRequirement[O]) SetHandler(v func(context.Context, O) error)

func (*CommandRequirement[O]) SetInitializeHandler

func (this *CommandRequirement[O]) SetInitializeHandler(v func(context.Context, O) error)

func (*CommandRequirement[O]) SetNames

func (this *CommandRequirement[O]) SetNames(v []string)

func (*CommandRequirement[O]) SetValidateHandler

func (this *CommandRequirement[O]) SetValidateHandler(v func(context.Context, O) error)

func (*CommandRequirement[O]) SetVisible added in v0.1.2

func (this *CommandRequirement[O]) SetVisible(v bool)

func (*CommandRequirement[O]) WithAliases

func (this *CommandRequirement[O]) WithAliases(v ...string) *CommandRequirement[O]

func (*CommandRequirement[O]) WithArgument

func (this *CommandRequirement[O]) WithArgument(v ...ArgumentRequirementLike) *CommandRequirement[O]

func (*CommandRequirement[O]) WithBoolArgument

func (this *CommandRequirement[O]) WithBoolArgument(name string, configure ...func(*ArgumentRequirement[bool, bool])) *CommandRequirement[O]

WithBoolArgument adds a standard bool argument. Like all typed argument helpers, it sets the name before applying callbacks in order. Fields bind only via WithField. Bool arguments consume one explicit input value.

func (*CommandRequirement[O]) WithBoolFlag

func (this *CommandRequirement[O]) WithBoolFlag(name string, configure ...func(*FlagRequirement[bool, bool])) *CommandRequirement[O]

WithBoolFlag adds a standard bool flag. Like all typed flag helpers, it sets the name before applying callbacks in order. Fields bind only via WithField.

func (*CommandRequirement[O]) WithBoolMapArgument added in v0.1.2

func (this *CommandRequirement[O]) WithBoolMapArgument(name string, configure ...func(*ArgumentRequirement[map[string]bool, map[string]bool])) *CommandRequirement[O]

WithBoolMapArgument adds a final variadic map[string]bool argument. Map arguments accept key=value pairs and reject duplicate keys.

func (*CommandRequirement[O]) WithBoolMapFlag added in v0.1.2

func (this *CommandRequirement[O]) WithBoolMapFlag(name string, configure ...func(*FlagRequirement[map[string]bool, map[string]bool])) *CommandRequirement[O]

WithBoolMapFlag adds a repeatable map[string]bool flag. Map helpers accept one key=value pair per occurrence and reject duplicate keys. Bind via WithField.

func (*CommandRequirement[O]) WithBoolSliceArgument

func (this *CommandRequirement[O]) WithBoolSliceArgument(name string, configure ...func(*ArgumentRequirement[[]bool, []bool])) *CommandRequirement[O]

WithBoolSliceArgument adds a standard variadic []bool argument. Like all standard slice arguments, it must be the final argument in its container.

func (*CommandRequirement[O]) WithBoolSliceFlag

func (this *CommandRequirement[O]) WithBoolSliceFlag(name string, configure ...func(*FlagRequirement[[]bool, []bool])) *CommandRequirement[O]

WithBoolSliceFlag adds a standard []bool flag. Slice helpers accept one value per occurrence and retain the standard codec's aggregation/default semantics.

func (*CommandRequirement[O]) WithCloseHandler

func (this *CommandRequirement[O]) WithCloseHandler(v func(O) error) *CommandRequirement[O]

WithCloseHandler provides cleanup for every created options instance, even after failed decoding, validation, or partial initialization. It must tolerate partially populated options. Options implementing io.Closer are also closed.

func (*CommandRequirement[O]) WithCodec

func (this *CommandRequirement[O]) WithCodec(v any, names ...string) *CommandRequirement[O]

WithCodec accepts an immutable codec.Codec[V, R]; Create validates it.

func (*CommandRequirement[O]) WithCommand

func (this *CommandRequirement[O]) WithCommand(v ...CommandRequirementLike) *CommandRequirement[O]

func (*CommandRequirement[O]) WithComplex64Argument

func (this *CommandRequirement[O]) WithComplex64Argument(name string, configure ...func(*ArgumentRequirement[complex64, complex64])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithComplex64Flag

func (this *CommandRequirement[O]) WithComplex64Flag(name string, configure ...func(*FlagRequirement[complex64, complex64])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithComplex64MapArgument added in v0.1.2

func (this *CommandRequirement[O]) WithComplex64MapArgument(name string, configure ...func(*ArgumentRequirement[map[string]complex64, map[string]complex64])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithComplex64MapFlag added in v0.1.2

func (this *CommandRequirement[O]) WithComplex64MapFlag(name string, configure ...func(*FlagRequirement[map[string]complex64, map[string]complex64])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithComplex64SliceArgument

func (this *CommandRequirement[O]) WithComplex64SliceArgument(name string, configure ...func(*ArgumentRequirement[[]complex64, []complex64])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithComplex64SliceFlag

func (this *CommandRequirement[O]) WithComplex64SliceFlag(name string, configure ...func(*FlagRequirement[[]complex64, []complex64])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithComplex128Argument

func (this *CommandRequirement[O]) WithComplex128Argument(name string, configure ...func(*ArgumentRequirement[complex128, complex128])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithComplex128Flag

func (this *CommandRequirement[O]) WithComplex128Flag(name string, configure ...func(*FlagRequirement[complex128, complex128])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithComplex128MapArgument added in v0.1.2

func (this *CommandRequirement[O]) WithComplex128MapArgument(name string, configure ...func(*ArgumentRequirement[map[string]complex128, map[string]complex128])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithComplex128MapFlag added in v0.1.2

func (this *CommandRequirement[O]) WithComplex128MapFlag(name string, configure ...func(*FlagRequirement[map[string]complex128, map[string]complex128])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithComplex128SliceArgument

func (this *CommandRequirement[O]) WithComplex128SliceArgument(name string, configure ...func(*ArgumentRequirement[[]complex128, []complex128])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithComplex128SliceFlag

func (this *CommandRequirement[O]) WithComplex128SliceFlag(name string, configure ...func(*FlagRequirement[[]complex128, []complex128])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithCreateOptionsHandler

func (this *CommandRequirement[O]) WithCreateOptionsHandler(v func(context.Context) (O, error)) *CommandRequirement[O]

WithCreateOptionsHandler supplies this command's invocation-owned options before decoding. It runs only for selected commands and must return fresh mutable state. Non-nil returned options are owned even on error; nil pointers are invalid. Factory values do not satisfy Required. Resources not returned remain the factory's responsibility; acquire resources in Initialize.

func (*CommandRequirement[O]) WithDateArgument

func (this *CommandRequirement[O]) WithDateArgument(name string, configure ...func(*ArgumentRequirement[time.Time, time.Time])) *CommandRequirement[O]

WithDateArgument adds a date-only argument; see codec.NewDate.

func (*CommandRequirement[O]) WithDateFlag

func (this *CommandRequirement[O]) WithDateFlag(name string, configure ...func(*FlagRequirement[time.Time, time.Time])) *CommandRequirement[O]

WithDateFlag adds a date-only flag; see codec.NewDate.

func (*CommandRequirement[O]) WithDateMapArgument added in v0.1.2

func (this *CommandRequirement[O]) WithDateMapArgument(name string, configure ...func(*ArgumentRequirement[map[string]time.Time, map[string]time.Time])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithDateMapFlag added in v0.1.2

func (this *CommandRequirement[O]) WithDateMapFlag(name string, configure ...func(*FlagRequirement[map[string]time.Time, map[string]time.Time])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithDateSliceArgument

func (this *CommandRequirement[O]) WithDateSliceArgument(name string, configure ...func(*ArgumentRequirement[[]time.Time, []time.Time])) *CommandRequirement[O]

WithDateSliceArgument adds variadic dates; see codec.NewDateSlice. It must be last.

func (*CommandRequirement[O]) WithDateSliceFlag

func (this *CommandRequirement[O]) WithDateSliceFlag(name string, configure ...func(*FlagRequirement[[]time.Time, []time.Time])) *CommandRequirement[O]

WithDateSliceFlag adds a repeatable date-only flag; see codec.NewDateSlice.

func (*CommandRequirement[O]) WithDateTimeArgument

func (this *CommandRequirement[O]) WithDateTimeArgument(name string, configure ...func(*ArgumentRequirement[time.Time, time.Time])) *CommandRequirement[O]

WithDateTimeArgument adds a timestamp argument; see codec.NewDateTime.

func (*CommandRequirement[O]) WithDateTimeFlag

func (this *CommandRequirement[O]) WithDateTimeFlag(name string, configure ...func(*FlagRequirement[time.Time, time.Time])) *CommandRequirement[O]

WithDateTimeFlag adds a timestamp flag; see codec.NewDateTime.

func (*CommandRequirement[O]) WithDateTimeMapArgument added in v0.1.2

func (this *CommandRequirement[O]) WithDateTimeMapArgument(name string, configure ...func(*ArgumentRequirement[map[string]time.Time, map[string]time.Time])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithDateTimeMapFlag added in v0.1.2

func (this *CommandRequirement[O]) WithDateTimeMapFlag(name string, configure ...func(*FlagRequirement[map[string]time.Time, map[string]time.Time])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithDateTimeSliceArgument

func (this *CommandRequirement[O]) WithDateTimeSliceArgument(name string, configure ...func(*ArgumentRequirement[[]time.Time, []time.Time])) *CommandRequirement[O]

WithDateTimeSliceArgument adds variadic timestamps; see codec.NewDateTimeSlice. It must be last.

func (*CommandRequirement[O]) WithDateTimeSliceFlag

func (this *CommandRequirement[O]) WithDateTimeSliceFlag(name string, configure ...func(*FlagRequirement[[]time.Time, []time.Time])) *CommandRequirement[O]

WithDateTimeSliceFlag adds a repeatable timestamp flag; see codec.NewDateTimeSlice.

func (*CommandRequirement[O]) WithDescription

func (this *CommandRequirement[O]) WithDescription(v string) *CommandRequirement[O]

func (*CommandRequirement[O]) WithDurationArgument

func (this *CommandRequirement[O]) WithDurationArgument(name string, configure ...func(*ArgumentRequirement[time.Duration, time.Duration])) *CommandRequirement[O]

WithDurationArgument adds a duration argument; use -- before negative values.

func (*CommandRequirement[O]) WithDurationFlag

func (this *CommandRequirement[O]) WithDurationFlag(name string, configure ...func(*FlagRequirement[time.Duration, time.Duration])) *CommandRequirement[O]

WithDurationFlag adds a flag accepting Go duration syntax; see codec.NewDuration.

func (*CommandRequirement[O]) WithDurationMapArgument added in v0.1.2

func (this *CommandRequirement[O]) WithDurationMapArgument(name string, configure ...func(*ArgumentRequirement[map[string]time.Duration, map[string]time.Duration])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithDurationMapFlag added in v0.1.2

func (this *CommandRequirement[O]) WithDurationMapFlag(name string, configure ...func(*FlagRequirement[map[string]time.Duration, map[string]time.Duration])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithDurationSliceArgument

func (this *CommandRequirement[O]) WithDurationSliceArgument(name string, configure ...func(*ArgumentRequirement[[]time.Duration, []time.Duration])) *CommandRequirement[O]

WithDurationSliceArgument adds variadic durations; it must be last.

func (*CommandRequirement[O]) WithDurationSliceFlag

func (this *CommandRequirement[O]) WithDurationSliceFlag(name string, configure ...func(*FlagRequirement[[]time.Duration, []time.Duration])) *CommandRequirement[O]

WithDurationSliceFlag adds a repeatable duration flag; see codec.NewDurationSlice.

func (*CommandRequirement[O]) WithFileArgument

func (this *CommandRequirement[O]) WithFileArgument(name string, configure ...func(*ArgumentRequirement[*os.File, codec.FileRequirement])) *CommandRequirement[O]

WithFileArgument adds a read-only file argument; defaults use codec.FileRequirement.

func (*CommandRequirement[O]) WithFileFlag

func (this *CommandRequirement[O]) WithFileFlag(name string, configure ...func(*FlagRequirement[*os.File, codec.FileRequirement])) *CommandRequirement[O]

WithFileFlag adds a read-only file flag. Defaults use codec.FileRequirement; handles are invocation-owned. Select write policy with FlagRequirement.WithCodec.

func (*CommandRequirement[O]) WithFileMapArgument added in v0.1.2

func (this *CommandRequirement[O]) WithFileMapArgument(name string, configure ...func(*ArgumentRequirement[map[string]*os.File, map[string]codec.FileRequirement])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithFileMapFlag added in v0.1.2

func (this *CommandRequirement[O]) WithFileMapFlag(name string, configure ...func(*FlagRequirement[map[string]*os.File, map[string]codec.FileRequirement])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithFileSliceArgument

func (this *CommandRequirement[O]) WithFileSliceArgument(name string, configure ...func(*ArgumentRequirement[[]*os.File, []codec.FileRequirement])) *CommandRequirement[O]

WithFileSliceArgument adds variadic read-only files; it must be last.

func (*CommandRequirement[O]) WithFileSliceFlag

func (this *CommandRequirement[O]) WithFileSliceFlag(name string, configure ...func(*FlagRequirement[[]*os.File, []codec.FileRequirement])) *CommandRequirement[O]

WithFileSliceFlag adds a repeatable read-only file flag; see codec.NewSlice.

func (*CommandRequirement[O]) WithFlag

func (this *CommandRequirement[O]) WithFlag(v ...FlagRequirementLike) *CommandRequirement[O]

func (*CommandRequirement[O]) WithFloat32Argument

func (this *CommandRequirement[O]) WithFloat32Argument(name string, configure ...func(*ArgumentRequirement[float32, float32])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithFloat32Flag

func (this *CommandRequirement[O]) WithFloat32Flag(name string, configure ...func(*FlagRequirement[float32, float32])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithFloat32MapArgument added in v0.1.2

func (this *CommandRequirement[O]) WithFloat32MapArgument(name string, configure ...func(*ArgumentRequirement[map[string]float32, map[string]float32])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithFloat32MapFlag added in v0.1.2

func (this *CommandRequirement[O]) WithFloat32MapFlag(name string, configure ...func(*FlagRequirement[map[string]float32, map[string]float32])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithFloat32SliceArgument

func (this *CommandRequirement[O]) WithFloat32SliceArgument(name string, configure ...func(*ArgumentRequirement[[]float32, []float32])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithFloat32SliceFlag

func (this *CommandRequirement[O]) WithFloat32SliceFlag(name string, configure ...func(*FlagRequirement[[]float32, []float32])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithFloat64Argument

func (this *CommandRequirement[O]) WithFloat64Argument(name string, configure ...func(*ArgumentRequirement[float64, float64])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithFloat64Flag

func (this *CommandRequirement[O]) WithFloat64Flag(name string, configure ...func(*FlagRequirement[float64, float64])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithFloat64MapArgument added in v0.1.2

func (this *CommandRequirement[O]) WithFloat64MapArgument(name string, configure ...func(*ArgumentRequirement[map[string]float64, map[string]float64])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithFloat64MapFlag added in v0.1.2

func (this *CommandRequirement[O]) WithFloat64MapFlag(name string, configure ...func(*FlagRequirement[map[string]float64, map[string]float64])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithFloat64SliceArgument

func (this *CommandRequirement[O]) WithFloat64SliceArgument(name string, configure ...func(*ArgumentRequirement[[]float64, []float64])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithFloat64SliceFlag

func (this *CommandRequirement[O]) WithFloat64SliceFlag(name string, configure ...func(*FlagRequirement[[]float64, []float64])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithHandler

func (this *CommandRequirement[O]) WithHandler(v func(context.Context, O) error) *CommandRequirement[O]

WithHandler receives this command's typed options. During invocation execution, InvocationFromContext and ContainerFromContext expose the complete invocation and the currently executing container.

func (*CommandRequirement[O]) WithInitializeHandler

func (this *CommandRequirement[O]) WithInitializeHandler(v func(context.Context, O) error) *CommandRequirement[O]

WithInitializeHandler runs after every selected scope has been decoded and validated. Resources retained by owned options are closed on any later error; other partial resources remain the handler's responsibility. Use pointer options when the handler needs to attach resources or change fields on the owned instance; assignments to struct copies are not retained.

func (*CommandRequirement[O]) WithInt8Argument

func (this *CommandRequirement[O]) WithInt8Argument(name string, configure ...func(*ArgumentRequirement[int8, int8])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithInt8Flag

func (this *CommandRequirement[O]) WithInt8Flag(name string, configure ...func(*FlagRequirement[int8, int8])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithInt8MapArgument added in v0.1.2

func (this *CommandRequirement[O]) WithInt8MapArgument(name string, configure ...func(*ArgumentRequirement[map[string]int8, map[string]int8])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithInt8MapFlag added in v0.1.2

func (this *CommandRequirement[O]) WithInt8MapFlag(name string, configure ...func(*FlagRequirement[map[string]int8, map[string]int8])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithInt8SliceArgument

func (this *CommandRequirement[O]) WithInt8SliceArgument(name string, configure ...func(*ArgumentRequirement[[]int8, []int8])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithInt8SliceFlag

func (this *CommandRequirement[O]) WithInt8SliceFlag(name string, configure ...func(*FlagRequirement[[]int8, []int8])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithInt16Argument

func (this *CommandRequirement[O]) WithInt16Argument(name string, configure ...func(*ArgumentRequirement[int16, int16])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithInt16Flag

func (this *CommandRequirement[O]) WithInt16Flag(name string, configure ...func(*FlagRequirement[int16, int16])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithInt16MapArgument added in v0.1.2

func (this *CommandRequirement[O]) WithInt16MapArgument(name string, configure ...func(*ArgumentRequirement[map[string]int16, map[string]int16])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithInt16MapFlag added in v0.1.2

func (this *CommandRequirement[O]) WithInt16MapFlag(name string, configure ...func(*FlagRequirement[map[string]int16, map[string]int16])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithInt16SliceArgument

func (this *CommandRequirement[O]) WithInt16SliceArgument(name string, configure ...func(*ArgumentRequirement[[]int16, []int16])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithInt16SliceFlag

func (this *CommandRequirement[O]) WithInt16SliceFlag(name string, configure ...func(*FlagRequirement[[]int16, []int16])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithInt32Argument

func (this *CommandRequirement[O]) WithInt32Argument(name string, configure ...func(*ArgumentRequirement[int32, int32])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithInt32Flag

func (this *CommandRequirement[O]) WithInt32Flag(name string, configure ...func(*FlagRequirement[int32, int32])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithInt32MapArgument added in v0.1.2

func (this *CommandRequirement[O]) WithInt32MapArgument(name string, configure ...func(*ArgumentRequirement[map[string]int32, map[string]int32])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithInt32MapFlag added in v0.1.2

func (this *CommandRequirement[O]) WithInt32MapFlag(name string, configure ...func(*FlagRequirement[map[string]int32, map[string]int32])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithInt32SliceArgument

func (this *CommandRequirement[O]) WithInt32SliceArgument(name string, configure ...func(*ArgumentRequirement[[]int32, []int32])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithInt32SliceFlag

func (this *CommandRequirement[O]) WithInt32SliceFlag(name string, configure ...func(*FlagRequirement[[]int32, []int32])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithInt64Argument

func (this *CommandRequirement[O]) WithInt64Argument(name string, configure ...func(*ArgumentRequirement[int64, int64])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithInt64Flag

func (this *CommandRequirement[O]) WithInt64Flag(name string, configure ...func(*FlagRequirement[int64, int64])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithInt64MapArgument added in v0.1.2

func (this *CommandRequirement[O]) WithInt64MapArgument(name string, configure ...func(*ArgumentRequirement[map[string]int64, map[string]int64])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithInt64MapFlag added in v0.1.2

func (this *CommandRequirement[O]) WithInt64MapFlag(name string, configure ...func(*FlagRequirement[map[string]int64, map[string]int64])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithInt64SliceArgument

func (this *CommandRequirement[O]) WithInt64SliceArgument(name string, configure ...func(*ArgumentRequirement[[]int64, []int64])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithInt64SliceFlag

func (this *CommandRequirement[O]) WithInt64SliceFlag(name string, configure ...func(*FlagRequirement[[]int64, []int64])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithIntArgument

func (this *CommandRequirement[O]) WithIntArgument(name string, configure ...func(*ArgumentRequirement[int, int])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithIntFlag

func (this *CommandRequirement[O]) WithIntFlag(name string, configure ...func(*FlagRequirement[int, int])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithIntMapArgument added in v0.1.2

func (this *CommandRequirement[O]) WithIntMapArgument(name string, configure ...func(*ArgumentRequirement[map[string]int, map[string]int])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithIntMapFlag added in v0.1.2

func (this *CommandRequirement[O]) WithIntMapFlag(name string, configure ...func(*FlagRequirement[map[string]int, map[string]int])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithIntSliceArgument

func (this *CommandRequirement[O]) WithIntSliceArgument(name string, configure ...func(*ArgumentRequirement[[]int, []int])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithIntSliceFlag

func (this *CommandRequirement[O]) WithIntSliceFlag(name string, configure ...func(*FlagRequirement[[]int, []int])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithMarshallerArgument

func (this *CommandRequirement[O]) WithMarshallerArgument[
	T encoding.TextMarshaler,
	TP interface {
		*T
		encoding.TextUnmarshaler
	},
](name string, configure ...func(*ArgumentRequirement[T, string])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithMarshallerFlag

func (this *CommandRequirement[O]) WithMarshallerFlag[
	T encoding.TextMarshaler,
	TP interface {
		*T
		encoding.TextUnmarshaler
	},
](name string, configure ...func(*FlagRequirement[T, string])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithMarshallerMapArgument added in v0.1.2

func (this *CommandRequirement[O]) WithMarshallerMapArgument[T encoding.TextMarshaler, TP interface {
	*T
	encoding.TextUnmarshaler
}](name string, configure ...func(*ArgumentRequirement[map[string]T, map[string]string])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithMarshallerMapFlag added in v0.1.2

func (this *CommandRequirement[O]) WithMarshallerMapFlag[T encoding.TextMarshaler, TP interface {
	*T
	encoding.TextUnmarshaler
}](name string, configure ...func(*FlagRequirement[map[string]T, map[string]string])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithMarshallerPArgument

func (this *CommandRequirement[O]) WithMarshallerPArgument[
	T interface {
		encoding.TextMarshaler
		encoding.TextUnmarshaler
	},
](name string, factory func() T, configure ...func(*ArgumentRequirement[T, string])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithMarshallerPFlag

func (this *CommandRequirement[O]) WithMarshallerPFlag[
	T interface {
		encoding.TextMarshaler
		encoding.TextUnmarshaler
	},
](name string, factory func() T, configure ...func(*FlagRequirement[T, string])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithMarshallerPMapArgument added in v0.1.2

func (this *CommandRequirement[O]) WithMarshallerPMapArgument[T interface {
	encoding.TextMarshaler
	encoding.TextUnmarshaler
}](name string, factory func() T, configure ...func(*ArgumentRequirement[map[string]T, map[string]string])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithMarshallerPMapFlag added in v0.1.2

func (this *CommandRequirement[O]) WithMarshallerPMapFlag[T interface {
	encoding.TextMarshaler
	encoding.TextUnmarshaler
}](name string, factory func() T, configure ...func(*FlagRequirement[map[string]T, map[string]string])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithMarshallerPSliceArgument

func (this *CommandRequirement[O]) WithMarshallerPSliceArgument[
	T interface {
		encoding.TextMarshaler
		encoding.TextUnmarshaler
	},
](name string, factory func() T, configure ...func(*ArgumentRequirement[[]T, []string])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithMarshallerPSliceFlag

func (this *CommandRequirement[O]) WithMarshallerPSliceFlag[
	T interface {
		encoding.TextMarshaler
		encoding.TextUnmarshaler
	},
](name string, factory func() T, configure ...func(*FlagRequirement[[]T, []string])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithMarshallerSliceArgument

func (this *CommandRequirement[O]) WithMarshallerSliceArgument[
	T encoding.TextMarshaler,
	TP interface {
		*T
		encoding.TextUnmarshaler
	},
](name string, configure ...func(*ArgumentRequirement[[]T, []string])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithMarshallerSliceFlag

func (this *CommandRequirement[O]) WithMarshallerSliceFlag[
	T encoding.TextMarshaler,
	TP interface {
		*T
		encoding.TextUnmarshaler
	},
](name string, configure ...func(*FlagRequirement[[]T, []string])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithName

func (this *CommandRequirement[O]) WithName(v ...string) *CommandRequirement[O]

WithName replaces the primary name and optional aliases. WithAliases appends aliases.

func (*CommandRequirement[O]) WithStringArgument

func (this *CommandRequirement[O]) WithStringArgument(name string, configure ...func(*ArgumentRequirement[string, string])) *CommandRequirement[O]

WithStringArgument adds a positional string; bind options with ArgumentRequirement.WithField.

func (*CommandRequirement[O]) WithStringFlag

func (this *CommandRequirement[O]) WithStringFlag(name string, configure ...func(*FlagRequirement[string, string])) *CommandRequirement[O]

WithStringFlag adds a string flag; bind options with FlagRequirement.WithField.

func (*CommandRequirement[O]) WithStringMapArgument added in v0.1.2

func (this *CommandRequirement[O]) WithStringMapArgument(name string, configure ...func(*ArgumentRequirement[map[string]string, map[string]string])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithStringMapFlag added in v0.1.2

func (this *CommandRequirement[O]) WithStringMapFlag(name string, configure ...func(*FlagRequirement[map[string]string, map[string]string])) *CommandRequirement[O]

WithStringMapFlag adds a repeatable map[string]string flag.

func (*CommandRequirement[O]) WithStringSliceArgument

func (this *CommandRequirement[O]) WithStringSliceArgument(name string, configure ...func(*ArgumentRequirement[[]string, []string])) *CommandRequirement[O]

WithStringSliceArgument adds a variadic string argument; it must be last.

func (*CommandRequirement[O]) WithStringSliceFlag

func (this *CommandRequirement[O]) WithStringSliceFlag(name string, configure ...func(*FlagRequirement[[]string, []string])) *CommandRequirement[O]

WithStringSliceFlag adds a repeatable string flag, one element per occurrence.

func (*CommandRequirement[O]) WithUint8Argument

func (this *CommandRequirement[O]) WithUint8Argument(name string, configure ...func(*ArgumentRequirement[uint8, uint8])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUint8Flag

func (this *CommandRequirement[O]) WithUint8Flag(name string, configure ...func(*FlagRequirement[uint8, uint8])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUint8MapArgument added in v0.1.2

func (this *CommandRequirement[O]) WithUint8MapArgument(name string, configure ...func(*ArgumentRequirement[map[string]uint8, map[string]uint8])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUint8MapFlag added in v0.1.2

func (this *CommandRequirement[O]) WithUint8MapFlag(name string, configure ...func(*FlagRequirement[map[string]uint8, map[string]uint8])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUint8SliceArgument

func (this *CommandRequirement[O]) WithUint8SliceArgument(name string, configure ...func(*ArgumentRequirement[[]uint8, []uint8])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUint8SliceFlag

func (this *CommandRequirement[O]) WithUint8SliceFlag(name string, configure ...func(*FlagRequirement[[]uint8, []uint8])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUint16Argument

func (this *CommandRequirement[O]) WithUint16Argument(name string, configure ...func(*ArgumentRequirement[uint16, uint16])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUint16Flag

func (this *CommandRequirement[O]) WithUint16Flag(name string, configure ...func(*FlagRequirement[uint16, uint16])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUint16MapArgument added in v0.1.2

func (this *CommandRequirement[O]) WithUint16MapArgument(name string, configure ...func(*ArgumentRequirement[map[string]uint16, map[string]uint16])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUint16MapFlag added in v0.1.2

func (this *CommandRequirement[O]) WithUint16MapFlag(name string, configure ...func(*FlagRequirement[map[string]uint16, map[string]uint16])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUint16SliceArgument

func (this *CommandRequirement[O]) WithUint16SliceArgument(name string, configure ...func(*ArgumentRequirement[[]uint16, []uint16])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUint16SliceFlag

func (this *CommandRequirement[O]) WithUint16SliceFlag(name string, configure ...func(*FlagRequirement[[]uint16, []uint16])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUint32Argument

func (this *CommandRequirement[O]) WithUint32Argument(name string, configure ...func(*ArgumentRequirement[uint32, uint32])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUint32Flag

func (this *CommandRequirement[O]) WithUint32Flag(name string, configure ...func(*FlagRequirement[uint32, uint32])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUint32MapArgument added in v0.1.2

func (this *CommandRequirement[O]) WithUint32MapArgument(name string, configure ...func(*ArgumentRequirement[map[string]uint32, map[string]uint32])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUint32MapFlag added in v0.1.2

func (this *CommandRequirement[O]) WithUint32MapFlag(name string, configure ...func(*FlagRequirement[map[string]uint32, map[string]uint32])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUint32SliceArgument

func (this *CommandRequirement[O]) WithUint32SliceArgument(name string, configure ...func(*ArgumentRequirement[[]uint32, []uint32])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUint32SliceFlag

func (this *CommandRequirement[O]) WithUint32SliceFlag(name string, configure ...func(*FlagRequirement[[]uint32, []uint32])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUint64Argument

func (this *CommandRequirement[O]) WithUint64Argument(name string, configure ...func(*ArgumentRequirement[uint64, uint64])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUint64Flag

func (this *CommandRequirement[O]) WithUint64Flag(name string, configure ...func(*FlagRequirement[uint64, uint64])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUint64MapArgument added in v0.1.2

func (this *CommandRequirement[O]) WithUint64MapArgument(name string, configure ...func(*ArgumentRequirement[map[string]uint64, map[string]uint64])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUint64MapFlag added in v0.1.2

func (this *CommandRequirement[O]) WithUint64MapFlag(name string, configure ...func(*FlagRequirement[map[string]uint64, map[string]uint64])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUint64SliceArgument

func (this *CommandRequirement[O]) WithUint64SliceArgument(name string, configure ...func(*ArgumentRequirement[[]uint64, []uint64])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUint64SliceFlag

func (this *CommandRequirement[O]) WithUint64SliceFlag(name string, configure ...func(*FlagRequirement[[]uint64, []uint64])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUintArgument

func (this *CommandRequirement[O]) WithUintArgument(name string, configure ...func(*ArgumentRequirement[uint, uint])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUintFlag

func (this *CommandRequirement[O]) WithUintFlag(name string, configure ...func(*FlagRequirement[uint, uint])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUintMapArgument added in v0.1.2

func (this *CommandRequirement[O]) WithUintMapArgument(name string, configure ...func(*ArgumentRequirement[map[string]uint, map[string]uint])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUintMapFlag added in v0.1.2

func (this *CommandRequirement[O]) WithUintMapFlag(name string, configure ...func(*FlagRequirement[map[string]uint, map[string]uint])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUintSliceArgument

func (this *CommandRequirement[O]) WithUintSliceArgument(name string, configure ...func(*ArgumentRequirement[[]uint, []uint])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUintSliceFlag

func (this *CommandRequirement[O]) WithUintSliceFlag(name string, configure ...func(*FlagRequirement[[]uint, []uint])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUintptrArgument

func (this *CommandRequirement[O]) WithUintptrArgument(name string, configure ...func(*ArgumentRequirement[uintptr, uintptr])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUintptrFlag

func (this *CommandRequirement[O]) WithUintptrFlag(name string, configure ...func(*FlagRequirement[uintptr, uintptr])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUintptrMapArgument added in v0.1.2

func (this *CommandRequirement[O]) WithUintptrMapArgument(name string, configure ...func(*ArgumentRequirement[map[string]uintptr, map[string]uintptr])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUintptrMapFlag added in v0.1.2

func (this *CommandRequirement[O]) WithUintptrMapFlag(name string, configure ...func(*FlagRequirement[map[string]uintptr, map[string]uintptr])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUintptrSliceArgument

func (this *CommandRequirement[O]) WithUintptrSliceArgument(name string, configure ...func(*ArgumentRequirement[[]uintptr, []uintptr])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithUintptrSliceFlag

func (this *CommandRequirement[O]) WithUintptrSliceFlag(name string, configure ...func(*FlagRequirement[[]uintptr, []uintptr])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithValidateHandler

func (this *CommandRequirement[O]) WithValidateHandler(v func(context.Context, O) error) *CommandRequirement[O]

WithValidateHandler checks fully decoded options after their Validate method and before any initializer runs. It must not mutate options or acquire resources. Mark invalid input with NewValidationErrorf; unmarked failures remain operational.

func (*CommandRequirement[O]) WithValueArgument

func (this *CommandRequirement[O]) WithValueArgument[T any, TP interface {
	*T
	codec.Value
}](name string, configure ...func(*ArgumentRequirement[T, []string])) *CommandRequirement[O]

WithValueArgument adds a positional Set/String value argument.

func (*CommandRequirement[O]) WithValueFlag

func (this *CommandRequirement[O]) WithValueFlag[T any, TP interface {
	*T
	codec.Value
}](name string, configure ...func(*FlagRequirement[T, []string])) *CommandRequirement[O]

WithValueFlag adds a Set/String value flag, keeping T as the field/value type.

func (*CommandRequirement[O]) WithValueMapArgument added in v0.1.2

func (this *CommandRequirement[O]) WithValueMapArgument[T any, TP interface {
	*T
	codec.Value
}](name string, configure ...func(*ArgumentRequirement[map[string]T, map[string][]string])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithValueMapFlag added in v0.1.2

func (this *CommandRequirement[O]) WithValueMapFlag[T any, TP interface {
	*T
	codec.Value
}](name string, configure ...func(*FlagRequirement[map[string]T, map[string][]string])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithValuePArgument

func (this *CommandRequirement[O]) WithValuePArgument[T codec.Value](name string, factory func() T, configure ...func(*ArgumentRequirement[T, []string])) *CommandRequirement[O]

WithValuePArgument adds a positional value with a fresh pointer factory.

func (*CommandRequirement[O]) WithValuePFlag

func (this *CommandRequirement[O]) WithValuePFlag[T codec.Value](name string, factory func() T, configure ...func(*FlagRequirement[T, []string])) *CommandRequirement[O]

WithValuePFlag adds a Set/String flag with a fresh pointer factory.

func (*CommandRequirement[O]) WithValuePMapArgument added in v0.1.2

func (this *CommandRequirement[O]) WithValuePMapArgument[T codec.Value](name string, factory func() T, configure ...func(*ArgumentRequirement[map[string]T, map[string][]string])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithValuePMapFlag added in v0.1.2

func (this *CommandRequirement[O]) WithValuePMapFlag[T codec.Value](name string, factory func() T, configure ...func(*FlagRequirement[map[string]T, map[string][]string])) *CommandRequirement[O]

func (*CommandRequirement[O]) WithValuePSliceArgument

func (this *CommandRequirement[O]) WithValuePSliceArgument[T codec.Value](name string, factory func() T, configure ...func(*ArgumentRequirement[[]T, [][]string])) *CommandRequirement[O]

WithValuePSliceArgument adds a final variadic slice of factory-created pointers.

func (*CommandRequirement[O]) WithValuePSliceFlag

func (this *CommandRequirement[O]) WithValuePSliceFlag[T codec.Value](name string, factory func() T, configure ...func(*FlagRequirement[[]T, [][]string])) *CommandRequirement[O]

WithValuePSliceFlag adds a repeated slice flag of factory-created pointers.

func (*CommandRequirement[O]) WithValueSliceArgument

func (this *CommandRequirement[O]) WithValueSliceArgument[T any, TP interface {
	*T
	codec.Value
}](name string, configure ...func(*ArgumentRequirement[[]T, [][]string])) *CommandRequirement[O]

WithValueSliceArgument adds a final variadic slice of Set/String values.

func (*CommandRequirement[O]) WithValueSliceFlag

func (this *CommandRequirement[O]) WithValueSliceFlag[T any, TP interface {
	*T
	codec.Value
}](name string, configure ...func(*FlagRequirement[[]T, [][]string])) *CommandRequirement[O]

WithValueSliceFlag adds a standard repeated slice flag of Set/String values.

func (*CommandRequirement[O]) WithVisible added in v0.1.2

func (this *CommandRequirement[O]) WithVisible(v bool) *CommandRequirement[O]

WithVisible controls whether the command appears in help listings.

type CommandRequirementLike

type CommandRequirementLike interface {
	// contains filtered or unexported methods
}

CommandRequirementLike accepts value and pointer builders with independent options types. Each builder compiles its own typed handler adapters.

type Container

type Container interface {
	Name() string
	Names() []string
	Description() string
	Commands() iter.Seq[CommandLike]
	Command(string) (CommandLike, bool)
	Flags() iter.Seq[*Flag[any, any]]
	Flag(string) (*Flag[any, any], bool)
	ShortFlag(rune) (*Flag[any, any], bool)
	Arguments() iter.Seq[*Argument[any, any]]
	Argument(int) (*Argument[any, any], bool)
	OptionsType() reflect.Type
	// contains filtered or unexported methods
}

Container exposes metadata common to applications and commands. Options and handler types remain specific to their respective typed definitions. Applications and commands implement it; callers cannot implement it externally.

func ContainerFromContext

func ContainerFromContext(ctx context.Context) (Container, bool)

ContainerFromContext identifies the application or command whose hook or handler is currently running, independently of its options type.

type ContainerRequirement

type ContainerRequirement[R any] interface {
	ContainerRequirementSetters
	WithCommand(...CommandRequirementLike) R
	WithCodec(any, ...string) R
	WithFlag(...FlagRequirementLike) R
	WithArgument(...ArgumentRequirementLike) R
}

type ContainerRequirementSetters

type ContainerRequirementSetters interface {
	AddCommand(...CommandRequirementLike)
	SetCommands([]CommandRequirementLike)

	AddCodec(any, ...string)
	SetCodecs([]codec.Registration)

	AddFlag(...FlagRequirementLike)
	SetFlags([]FlagRequirementLike)

	AddArgument(...ArgumentRequirementLike)
	SetArguments([]ArgumentRequirementLike)
}

type ErrorHandler

type ErrorHandler func(context.Context, InvocationLike, error) error

ErrorHandler observes input and operational failures after invocation cleanup. A non-nil return replaces the error; nil preserves it. The context exposes the invocation and the container whose execution failed. Direct container calls can have a nil invocation and retain caller ownership of their supplied options.

var DefaultErrorHandler ErrorHandler = (&RespondErrorHandlerRequirement{
	ValidationExitCode: 2, CanceledExitCode: 130, ExecutionExitCode: 1,
}).MustCreate()

DefaultErrorHandler is captured by Create when no error handler is set. Its built-in value writes to os.Stderr, shows help for ErrValidation, and exits with status 2 for input errors, 130 for context.Canceled, or 1 for other operational errors. Configure this variable before Create, without concurrent modification. Nil disables the global fallback; individual applications can disable error handling.

type Flag

type Flag[V, R any] struct {
	// contains filtered or unexported fields
}

Flag describes a CLI flag. Metadata and defaults remain separate from parsed values; use Invocation.Flag to read V and Flag.Default to read a default R.

func (*Flag[V, R]) Codec

func (this *Flag[V, R]) Codec() codec.Codec[V, R]

func (*Flag[V, R]) Default

func (this *Flag[V, R]) Default(ctx context.Context) (value R, found bool, err error)

Default returns an independent default R, or found=false if none is declared. It does not acquire runtime resources.

func (*Flag[V, R]) Description

func (this *Flag[V, R]) Description() string

func (*Flag[V, R]) EnvVars

func (this *Flag[V, R]) EnvVars() []string

func (*Flag[V, R]) FormatDefault

func (this *Flag[V, R]) FormatDefault(ctx context.Context) ([]string, bool, error)

FormatDefault returns help-safe default text without opening resources. Invalid declared defaults return an error, even if CLI input could override them.

func (*Flag[V, R]) HasDefault

func (this *Flag[V, R]) HasDefault() bool

func (*Flag[V, R]) IsBoolFlag

func (this *Flag[V, R]) IsBoolFlag() bool

func (*Flag[V, R]) IsCumulative

func (this *Flag[V, R]) IsCumulative() bool

func (*Flag[V, R]) IsRequired

func (this *Flag[V, R]) IsRequired() bool

func (*Flag[V, R]) IsVisible

func (this *Flag[V, R]) IsVisible() bool

func (*Flag[V, R]) Name

func (this *Flag[V, R]) Name() string

func (*Flag[V, R]) Names

func (this *Flag[V, R]) Names() []string

func (*Flag[V, R]) Placeholder

func (this *Flag[V, R]) Placeholder() string

func (*Flag[V, R]) Shorts

func (this *Flag[V, R]) Shorts() []rune

func (*Flag[V, R]) ValueType

func (this *Flag[V, R]) ValueType() reflect.Type

type FlagRequirement

type FlagRequirement[V, R any] struct {
	// Names contains the primary name followed by aliases.
	Names []string
	// Shorts contains optional single-rune aliases.
	Shorts []rune

	// EnvVars contains environment fallback names in lookup order.
	EnvVars []string

	Description string
	Required    bool
	Visible     bool
	Placeholder string
	Codec       codec.Codec[V, R]
	// CodecFactory configures a codec during Create, without acquiring resources.
	CodecFactory func() (codec.Codec[V, R], error)
	Field        []string
	// contains filtered or unexported fields
}

FlagRequirement configures a flag producing V from input requirements R. Use FlagRequirement.WithDefault for typed R or FlagRequirement.WithDefaultStr for input tokens. Required flags cannot declare defaults, including zero/nil. Repetition requires codec.Cumulative; standard slice flags accept one element per occurrence. Bind fields explicitly with FlagRequirement.WithField.

func NewFlag

func NewFlag[V, R any](codec codec.Codec[V, R]) *FlagRequirement[V, R]

NewFlag starts a visible flag using codec. Set its name with FlagRequirement.WithName.

func (*FlagRequirement[V, R]) SetCodec

func (this *FlagRequirement[V, R]) SetCodec(v codec.Codec[V, R])

func (*FlagRequirement[V, R]) SetCodecFactory

func (this *FlagRequirement[V, R]) SetCodecFactory(v func() (codec.Codec[V, R], error))

func (*FlagRequirement[V, R]) SetDefault

func (this *FlagRequirement[V, R]) SetDefault(v R)

func (*FlagRequirement[V, R]) SetDefaultStr

func (this *FlagRequirement[V, R]) SetDefaultStr(v ...string)

func (*FlagRequirement[V, R]) SetDescription

func (this *FlagRequirement[V, R]) SetDescription(v string)

func (*FlagRequirement[V, R]) SetEnvVars

func (this *FlagRequirement[V, R]) SetEnvVars(v []string)

func (*FlagRequirement[V, R]) SetField

func (this *FlagRequirement[V, R]) SetField(v []string) *FlagRequirement[V, R]

func (*FlagRequirement[V, R]) SetNames

func (this *FlagRequirement[V, R]) SetNames(v []string)

func (*FlagRequirement[V, R]) SetPlaceholder

func (this *FlagRequirement[V, R]) SetPlaceholder(v string)

func (*FlagRequirement[V, R]) SetRequired

func (this *FlagRequirement[V, R]) SetRequired(v bool)

func (*FlagRequirement[V, R]) SetShorts

func (this *FlagRequirement[V, R]) SetShorts(v []rune)

func (*FlagRequirement[V, R]) SetVisible

func (this *FlagRequirement[V, R]) SetVisible(v bool)

func (*FlagRequirement[V, R]) WithAliases

func (this *FlagRequirement[V, R]) WithAliases(v ...string) *FlagRequirement[V, R]

func (*FlagRequirement[V, R]) WithCodec

func (this *FlagRequirement[V, R]) WithCodec(v codec.Codec[V, R]) *FlagRequirement[V, R]

WithCodec replaces the decoder and clears any FlagRequirement.WithCodecFactory.

func (*FlagRequirement[V, R]) WithCodecFactory

func (this *FlagRequirement[V, R]) WithCodecFactory(v func() (codec.Codec[V, R], error)) *FlagRequirement[V, R]

WithCodecFactory configures the decoder during Create and replaces FlagRequirement.WithCodec. The factory must not acquire runtime resources; configuration errors fail Create.

func (*FlagRequirement[V, R]) WithDefault

func (this *FlagRequirement[V, R]) WithDefault(v R) *FlagRequirement[V, R]

WithDefault sets a resource-free typed default R, independently copied for each parse. R can differ from V, for example codec.FileRequirement instead of *os.File.

func (*FlagRequirement[V, R]) WithDefaultStr

func (this *FlagRequirement[V, R]) WithDefaultStr(v ...string) *FlagRequirement[V, R]

WithDefaultStr sets default input tokens without shell/CSV splitting. It replaces any previous typed or string default.

func (*FlagRequirement[V, R]) WithDescription

func (this *FlagRequirement[V, R]) WithDescription(v string) *FlagRequirement[V, R]

func (*FlagRequirement[V, R]) WithEnvVar

func (this *FlagRequirement[V, R]) WithEnvVar(v ...string) *FlagRequirement[V, R]

WithEnvVar adds environment fallback names. CLI input takes precedence.

func (*FlagRequirement[V, R]) WithField

func (this *FlagRequirement[V, R]) WithField(v ...string) *FlagRequirement[V, R]

WithField binds V to an exported options field; v is its nested field path. The binding overrides tags on that field. Omit it to keep the flag unbound.

Example
package main

import (
	"context"
	"fmt"

	cli "github.com/echocat/cli4g"
)

func main() {
	type options struct{ Port uint32 }
	app := cli.NewApplication[options]().
		WithName("server").
		WithUint32Flag("port", func(flag *cli.FlagRequirement[uint32, uint32]) {
			flag.
				WithField("Port").
				WithDefault(8080)
		}).
		MustCreate()
	defer func() {
		if err := app.Close(); err != nil {
			panic(err)
		}
	}()
	invocation, err := app.Parse(context.Background(), nil)
	if err != nil {
		panic(err)
	}
	defer func() {
		if err := invocation.Close(); err != nil {
			panic(err)
		}
	}()
	_, opts := invocation.Application()
	fmt.Println(opts.Port)
}
Output:
8080

func (*FlagRequirement[V, R]) WithName

func (this *FlagRequirement[V, R]) WithName(v ...string) *FlagRequirement[V, R]

WithName replaces the primary name and optional aliases. WithAliases appends aliases.

func (*FlagRequirement[V, R]) WithPlaceholder

func (this *FlagRequirement[V, R]) WithPlaceholder(v string) *FlagRequirement[V, R]

func (*FlagRequirement[V, R]) WithRequired

func (this *FlagRequirement[V, R]) WithRequired(v bool) *FlagRequirement[V, R]

WithRequired demands CLI or environment input. Defaults are incompatible; options-factory values do not satisfy this requirement.

func (*FlagRequirement[V, R]) WithShort

func (this *FlagRequirement[V, R]) WithShort(v ...rune) *FlagRequirement[V, R]

func (*FlagRequirement[V, R]) WithVisible

func (this *FlagRequirement[V, R]) WithVisible(v bool) *FlagRequirement[V, R]

type FlagRequirementLike

type FlagRequirementLike interface {
	// contains filtered or unexported methods
}

FlagRequirementLike allows flags with different value types in one builder. It is implemented by FlagRequirement, not by callers.

type HelpArgumentInfo

type HelpArgumentInfo struct {
	Definition *Argument[any, any]
	MinValues  int
	MaxValues  int
}

type HelpArgumentTemplateData

type HelpArgumentTemplateData struct {
	HelpArgumentInfo
	Name        string
	Label       string
	Description string
	Placeholder string
	ValueType   reflect.Type
	Required    bool
	HasDefault  bool
	Default     []string
	DefaultText string
}

HelpArgumentTemplateData is the input to the argument template.

type HelpCommandTemplateData

type HelpCommandTemplateData struct {
	Definition  CommandLike
	Names       []string
	FullName    string
	Label       string
	Description string
}

HelpCommandTemplateData is the input to the command-entry template.

type HelpFlagInfo

type HelpFlagInfo struct {
	Definition *Flag[any, any]
	Owner      Container
	Inherited  bool
	MinValues  int
	MaxValues  int // -1 means variadic
}

type HelpFlagTemplateData

type HelpFlagTemplateData struct {
	HelpFlagInfo
	Names       []string
	Shorts      []rune
	Label       string
	Description string
	Placeholder string
	ValueType   reflect.Type
	Required    bool
	EnvVars     []string
	HasDefault  bool
	Default     []string
	DefaultText string
}

HelpFlagTemplateData is the input to the flag template, including safe default text.

type HelpHandler

type HelpHandler func(context.Context, InvocationLike) error

HelpHandler executes a valid help invocation. Its metadata includes the selected path's resolved codecs; no options or normal lifecycle are created.

var DefaultHelpHandler HelpHandler = func(ctx context.Context, invocation InvocationLike) error {
	if ctx == nil {
		ctx = context.Background()
	}
	if err := ctx.Err(); err != nil {
		return err
	}
	return defaultHelpHandler()(ctx, invocation)
}

DefaultHelpHandler is the overridable fallback captured by ApplicationRequirement.Create when no application handler is set. Configure it before Create, without concurrent modification. Its built-in value compiles templates once on first use, writes to os.Stderr and returns normally.

type HelpInfo

type HelpInfo struct {
	Application Container
	Target      Container
	Path        []Container
	Commands    []CommandLike
	Flags       []HelpFlagInfo
	Arguments   []HelpArgumentInfo
}

HelpInfo is a fresh metadata view of the selected path. Definition pointers refer to immutable compiled snapshots. Mutating the returned lists does not change the application. No options, codecs, defaults or handlers are executed.

type HelpTemplateData

type HelpTemplateData struct {
	HelpInfo
	Invocation     InvocationLike
	FullName       string
	NamePath       []string
	Description    string
	Usage          string
	Commands       []HelpCommandTemplateData
	Flags          []HelpFlagTemplateData
	InheritedFlags []HelpFlagTemplateData
	Arguments      []HelpArgumentTemplateData
}

HelpTemplateData supplies visible commands, inputs, and display-safe defaults to application, command, and usage templates. Embedded HelpInfo also contains hidden definitions. DefaultText uses codec DisplayRequirement, not serialization.

type Initializable

type Initializable interface {
	// Initialize prepares options. Retained resources must be released by
	// options' Close method, including after partial initialization.
	Initialize(context.Context) error
}

Initializable prepares options after successful validation. Pointer-receiver methods retain assignments, including for struct options. See Invocation.Close and ApplicationRequirement.WithInitializeHandler.

type Invocation

type Invocation[O any] struct {
	// contains filtered or unexported fields
}

Invocation owns the options and resources of one successful parse. Execute it with Invocation.Execute and always call Invocation.Close. Option getters read current fields; input getters retain decoded values. Pointers, maps, and slices can share data within this invocation.

func (Invocation[O]) Application

func (this Invocation[O]) Application() (*Application[O], O)

Application returns the application and its current options. Struct options are returned by value; pointer options refer to the owned instance. Reference fields in returned structs still share their underlying data. Help invocations have no options and return the zero value of O.

func (Invocation[O]) Argument

func (this Invocation[O]) Argument(i int) (*Argument[any, any], any)

Argument returns a decoded leaf argument by definition index, or nil, nil if absent.

func (Invocation[O]) Arguments

func (this Invocation[O]) Arguments() iter.Seq2[*Argument[any, any], any]

Arguments and Argument expose resolved runtime values of the deepest selected container. Arguments iterates only values present in the invocation. Argument uses the container's definition index; omitted arguments return nil, nil.

func (*Invocation[O]) Close

func (this *Invocation[O]) Close() error

Close closes owned options in reverse scope order, exactly once. Repeated calls return the original cleanup result. Callers must Close every invocation returned by a successful Parse, including after an Execute error. Execute and Close must not run concurrently on the same invocation.

func (Invocation[O]) ErrorHandler

func (this Invocation[O]) ErrorHandler() ErrorHandler

ErrorHandler returns the application's captured input/operational response.

func (*Invocation[O]) Execute

func (this *Invocation[O]) Execute(ctx context.Context) (err error)

Execute runs handlers from root to leaf and checks cancellation before and after each handler. Handlers must honor their context during their own work. A nil context is replaced with context.Background. With a configured error handler, failures close this invocation before reporting. Without one, the caller retains cleanup responsibility. Successful invocations must be closed. A help invocation executes only the application's HelpHandler.

func (Invocation[O]) Flag

func (this Invocation[O]) Flag(name string) (*Flag[any, any], any)

Flag returns a decoded flag by name or alias; the deepest selected definition wins. Missing values return nil, nil. Factory-only fields are not decoded inputs.

func (Invocation[O]) Flags

func (this Invocation[O]) Flags() iter.Seq2[*Flag[any, any], any]

Flags exposes successfully resolved runtime values, including after failed parsing or cleanup. Prepared requirements are never published by these getters.

func (Invocation[O]) HelpHandler

func (this Invocation[O]) HelpHandler() HelpHandler

HelpHandler returns the application's captured handler, including its global fallback. It is usable directly for parse-error responses after cleanup.

func (Invocation[O]) HelpInfo

func (this Invocation[O]) HelpInfo() HelpInfo

func (Invocation[O]) HelpRequested

func (this Invocation[O]) HelpRequested() bool

func (Invocation[O]) NameStack

func (this Invocation[O]) NameStack() []string

NameStack returns the selected canonical command names, excluding the application.

func (Invocation[O]) Root

func (this Invocation[O]) Root() Container

Root exposes the application's metadata when its concrete options type is unknown to a command handler obtaining the invocation from its context.

func (Invocation[O]) ShortFlag

func (this Invocation[O]) ShortFlag(short rune) (*Flag[any, any], any)

ShortFlag returns a decoded flag by its short alias, or nil, nil if absent.

func (Invocation[O]) Stack

func (this Invocation[O]) Stack() []InvocationStackFrame

Stack returns a new list of the selected commands and their current options. It does not deep-copy options or include the root application. Help invocations contain the selected commands with nil Options.

type InvocationLike

type InvocationLike interface {
	Root() Container
	HelpRequested() bool
	HelpInfo() HelpInfo
	HelpHandler() HelpHandler
	ErrorHandler() ErrorHandler
	Stack() []InvocationStackFrame
	NameStack() []string
	Flags() iter.Seq2[*Flag[any, any], any]
	Flag(string) (*Flag[any, any], any)
	ShortFlag(rune) (*Flag[any, any], any)
	Arguments() iter.Seq2[*Argument[any, any], any]
	Argument(int) (*Argument[any, any], any)
	// contains filtered or unexported methods
}

InvocationLike gives handlers and tools access to any invocation's metadata and decoded values. It is implemented by Invocation, not by callers.

func InvocationFromContext

func InvocationFromContext(ctx context.Context) (InvocationLike, bool)

InvocationFromContext returns the complete invocation associated with a lifecycle hook or handler. No new invocation is attached during decoding.

type InvocationStackFrame

type InvocationStackFrame struct {
	Command CommandLike
	Options any
}

InvocationStackFrame contains a selected command and its current options. Use Command.OptionsFrom for typed access. Reference data remains shared.

type NoOptions

type NoOptions struct{}

NoOptions is the concrete options type for definitions using only explicit flags and arguments. Their handlers can obtain the complete invocation and its values with InvocationFromContext.

type ParseOpts

type ParseOpts struct {
	// LookupEnv replaces os.LookupEnv. Return exists=false to disable environment input.
	// CLI flags take precedence; callbacks used by concurrent parses must be safe.
	LookupEnv func(ctx context.Context, name string) (value string, exists bool)
}

ParseOpts customizes environment input. Nil uses os.LookupEnv.

type RespondErrorHandlerRequirement

type RespondErrorHandlerRequirement struct {
	Output             io.Writer   // nil selects os.Stderr
	HelpHandler        HelpHandler // nil selects the invocation's application handler
	ValidationExitCode int         // zero returns validation errors normally
	CanceledExitCode   int         // zero returns context.Canceled errors normally
	ExecutionExitCode  int         // zero returns operational errors normally
}

RespondErrorHandlerRequirement configures output responses and exit codes. Validation errors show help; cancellations and other errors do not. Zero codes return the original error joined with any response errors. Nonzero codes call os.Exit, which does not run caller defers.

func NewRespondErrorHandler

func NewRespondErrorHandler() *RespondErrorHandlerRequirement

NewRespondErrorHandler starts a returning responder with all exit codes zero. Attach the created handler with ApplicationRequirement.WithErrorHandler.

func (*RespondErrorHandlerRequirement) Create

func (*RespondErrorHandlerRequirement) MustCreate

func (this *RespondErrorHandlerRequirement) MustCreate() ErrorHandler

MustCreate creates the handler and panics on invalid configuration.

func (*RespondErrorHandlerRequirement) SetCanceledExitCode

func (this *RespondErrorHandlerRequirement) SetCanceledExitCode(v int)

func (*RespondErrorHandlerRequirement) SetExecutionExitCode

func (this *RespondErrorHandlerRequirement) SetExecutionExitCode(v int)

func (*RespondErrorHandlerRequirement) SetHelpHandler

func (this *RespondErrorHandlerRequirement) SetHelpHandler(v HelpHandler)

func (*RespondErrorHandlerRequirement) SetOutput

func (this *RespondErrorHandlerRequirement) SetOutput(v io.Writer)

func (*RespondErrorHandlerRequirement) SetValidationExitCode

func (this *RespondErrorHandlerRequirement) SetValidationExitCode(v int)

func (*RespondErrorHandlerRequirement) WithCanceledExitCode

func (this *RespondErrorHandlerRequirement) WithCanceledExitCode(v int) *RespondErrorHandlerRequirement

func (*RespondErrorHandlerRequirement) WithExecutionExitCode

func (this *RespondErrorHandlerRequirement) WithExecutionExitCode(v int) *RespondErrorHandlerRequirement

func (*RespondErrorHandlerRequirement) WithHelpHandler

func (*RespondErrorHandlerRequirement) WithOutput

func (*RespondErrorHandlerRequirement) WithValidationExitCode

func (this *RespondErrorHandlerRequirement) WithValidationExitCode(v int) *RespondErrorHandlerRequirement

type TemplatedHelpHandlerRequirement

type TemplatedHelpHandlerRequirement struct {
	// Output remains caller-owned. Custom writers and handlers need their own synchronization.
	Output   io.Writer // nil selects os.Stderr
	ExitCode int       // non-zero calls os.Exit after successful rendering/writing

	ApplicationTemplate  string           // template "application": root help
	CommandTemplate      string           // template "command": selected command help
	UsageTemplate        string           // template "usage": invocation syntax
	CommandEntryTemplate string           // template "command-entry": available command
	FlagTemplate         string           // template "flag": flag entry
	ArgumentTemplate     string           // template "argument": positional entry
	Funcs                template.FuncMap // custom functions must be concurrent-safe
}

TemplatedHelpHandlerRequirement configures text/template-based help. Empty templates stay empty; defaults are not inserted automatically. Main templates receive HelpTemplateData; entry templates receive the matching Help*TemplateData type. Built-in functions include join and quote. Create reports invalid syntax; execution reports render/write/default errors.

func NewTemplatedHelpHandler

func NewTemplatedHelpHandler() *TemplatedHelpHandlerRequirement

NewTemplatedHelpHandler starts an empty help-template builder. Set templates explicitly, using the Default*HelpTemplate constants as needed.

func (*TemplatedHelpHandlerRequirement) Create

Create compiles an independent template set. Template execution may run concurrently; framework help/error writes are serialized and rendering errors do not produce partial output. Custom functions must be concurrency-safe.

func (*TemplatedHelpHandlerRequirement) MustCreate

func (this *TemplatedHelpHandlerRequirement) MustCreate() HelpHandler

MustCreate compiles the templates and panics on invalid configuration.

func (*TemplatedHelpHandlerRequirement) SetApplicationTemplate

func (this *TemplatedHelpHandlerRequirement) SetApplicationTemplate(v string)

func (*TemplatedHelpHandlerRequirement) SetArgumentTemplate

func (this *TemplatedHelpHandlerRequirement) SetArgumentTemplate(v string)

func (*TemplatedHelpHandlerRequirement) SetCommandEntryTemplate

func (this *TemplatedHelpHandlerRequirement) SetCommandEntryTemplate(v string)

func (*TemplatedHelpHandlerRequirement) SetCommandTemplate

func (this *TemplatedHelpHandlerRequirement) SetCommandTemplate(v string)

func (*TemplatedHelpHandlerRequirement) SetExitCode

func (this *TemplatedHelpHandlerRequirement) SetExitCode(v int)

func (*TemplatedHelpHandlerRequirement) SetFlagTemplate

func (this *TemplatedHelpHandlerRequirement) SetFlagTemplate(v string)

func (*TemplatedHelpHandlerRequirement) SetFuncs

func (*TemplatedHelpHandlerRequirement) SetOutput

func (this *TemplatedHelpHandlerRequirement) SetOutput(v io.Writer)

func (*TemplatedHelpHandlerRequirement) SetUsageTemplate

func (this *TemplatedHelpHandlerRequirement) SetUsageTemplate(v string)

func (*TemplatedHelpHandlerRequirement) WithApplicationTemplate

func (*TemplatedHelpHandlerRequirement) WithArgumentTemplate

func (*TemplatedHelpHandlerRequirement) WithCommandEntryTemplate

func (this *TemplatedHelpHandlerRequirement) WithCommandEntryTemplate(v string) *TemplatedHelpHandlerRequirement

func (*TemplatedHelpHandlerRequirement) WithCommandTemplate

func (*TemplatedHelpHandlerRequirement) WithExitCode

func (*TemplatedHelpHandlerRequirement) WithFlagTemplate

func (*TemplatedHelpHandlerRequirement) WithFuncs

func (*TemplatedHelpHandlerRequirement) WithOutput

func (*TemplatedHelpHandlerRequirement) WithUsageTemplate

type Validatable

type Validatable interface {
	// Validate checks the fully decoded options before any initializer runs.
	// It must not acquire resources or mutate the options.
	// Mark invalid input with NewValidationError or NewValidationErrorf; unmarked
	// failures remain operational and retain their original causes.
	Validate(context.Context) error
}

Validatable checks decoded options before initialization. Mark invalid user input with NewValidationErrorf; return technical errors normally.

type ValidationError

type ValidationError = codec.ValidationError

ValidationError is the codec package's input-error wrapper.

Source Files

Directories

Path Synopsis
Package codec parses CLI inputs into typed values and provides codecs for custom types, dates, durations, slices, maps, and invocation-owned files.
Package codec parses CLI inputs into typed values and provides codecs for custom types, dates, durations, slices, maps, and invocation-owned files.
internal
examplecmd command
Command examplecmd implements mise's example run/list tasks using only Go.
Command examplecmd implements mise's example run/list tasks using only Go.
exampleutil
Package exampleutil shares example discovery between Go tests and the runner.
Package exampleutil shares example discovery between Go tests and the runner.
testexec
Package testexec runs native test subprocesses with bounded output and cleanup.
Package testexec runs native test subprocesses with bounded output and cleanup.

Jump to

Keyboard shortcuts

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