Documentation
¶
Index ¶
- func GetArguments(config cfg.Config) ([]string, error)
- func LogHandler(channels ...string) logHandler
- func Module[T any](fac func(ctx context.Context, config cfg.Config, logger log.Logger) (T, error), ...) application.Option
- func UnmarshalFlags[T any](config cfg.Config) (*T, error)
- func WithRunFunc(...) kernelPkg.ModuleFactory
- type Blueprint
- type BlueprintFlag
- type Cli
- type Cmd
- type CmdArguments
- type CmdExample
- type Flag
- type FlagKind
- type Group
- type Handler
- type Input
- type InputFlag
- type Option
- type Router
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetArguments ¶ added in v0.63.7
GetArguments returns the positional arguments from the application's cli.args configuration section.
func LogHandler ¶ added in v0.62.1
func LogHandler(channels ...string) logHandler
LogHandler creates a CLI log handler that writes debug output for the selected channels.
func Module ¶ added in v0.63.7
func Module[T any](fac func(ctx context.Context, config cfg.Config, logger log.Logger) (T, error), call func(m T) Handler) application.Option
Module builds a main application module from a typed dependency factory and command handler.
func UnmarshalFlags ¶ added in v0.63.7
UnmarshalFlags unmarshals CLI flag values from the application's cli.flags configuration section.
func WithRunFunc ¶ added in v0.62.1
func WithRunFunc(f func(ctx context.Context, config cfg.Config, logger log.Logger) (kernelPkg.ModuleRunFunc, error)) kernelPkg.ModuleFactory
WithRunFunc adapts a module run function factory into a gosoline module factory.
Types ¶
type Blueprint ¶ added in v0.62.1
type Blueprint struct {
Cmd []string
Args []string
Flags []BlueprintFlag
AppOptions []application.Option
}
Blueprint describes the command, arguments, flags, and application options selected from parsed CLI input.
type BlueprintFlag ¶ added in v0.62.1
type BlueprintFlag struct {
Key string
CustomKey string
Value any
AppOptions []application.Option
}
BlueprintFlag contains the resolved value and configuration bindings for a matched CLI flag.
type Cli ¶ added in v0.62.1
type Cli struct {
*Router
// contains filtered or unexported fields
}
Cli wires command routing, option parsing, and gosoline application startup for command line programs.
type Cmd ¶ added in v0.62.1
type Cmd struct {
Name string
Description string
Arguments CmdArguments
Examples []CmdExample
Flags []Flag
AppOptions []application.Option
}
Cmd defines an executable command with help metadata, flags, and application options.
type CmdArguments ¶ added in v0.63.7
type CmdArguments string
CmdArguments identifies whether a CLI command accepts positional arguments.
const ( // CmdArgumentsNone documents that a command does not accept positional arguments. CmdArgumentsNone CmdArguments = "" // CmdArgumentsSingle documents that a command accepts one positional argument. CmdArgumentsSingle CmdArguments = "single" // CmdArgumentsMultiple documents that a command accepts multiple positional arguments. CmdArgumentsMultiple CmdArguments = "multiple" )
type CmdExample ¶ added in v0.63.7
CmdExample describes a command example rendered in help output.
type Flag ¶ added in v0.62.1
type Flag struct {
Short string
Long string
Kind FlagKind
CfgKey string
Default string
Description string
AppOptions []application.Option
}
Flag defines a supported CLI flag and how it maps into application configuration.
type FlagKind ¶ added in v0.63.7
type FlagKind string
FlagKind identifies how a CLI flag value is parsed.
const ( // FlagKindBool parses a boolean switch; a bare switch is true and explicit values use =. FlagKindBool FlagKind = "bool" // FlagKindString parses a flag as a single string value where the last occurrence wins. FlagKindString FlagKind = "string" // FlagKindList parses every occurrence of a flag into a string slice. FlagKindList FlagKind = "list" )
type Group ¶ added in v0.62.1
type Group struct {
Name string
Description string
Flags []Flag
AppOptions []application.Option
// contains filtered or unexported fields
}
Group defines a named command namespace with shared flags and application options.
type Handler ¶ added in v0.63.7
type Handler = kernel.ModuleRunFunc
Handler is the function executed by a CLI command module.
type Input ¶ added in v0.62.1
type Input struct {
Arguments []string
Flags []InputFlag
// contains filtered or unexported fields
}
Input contains the parsed command line arguments and flags.
func NewInputWithArgs ¶ added in v0.62.1
NewInputWithArgs parses arguments using optional flag definitions. Boolean flags never consume the next argument; explicit boolean values must use =.
func NewInputWithRouter ¶ added in v0.69.3
NewInputWithRouter parses arguments using the flags of the selected command, including inherited group and global flags. This permits boolean switches before command names and preserves aliases with different kinds across commands.
type Option ¶ added in v0.62.1
type Option func(cli *Cli)
Option configures a Cli before it parses input and runs the selected command.
func WithAppOptions ¶ added in v0.62.1
func WithAppOptions(option ...application.Option) Option
WithAppOptions adds gosoline application options that apply to every command.
func WithHelp ¶ added in v0.63.7
WithHelp configures top-level help text and registers the built-in help command.
func WithHelpLineLength ¶ added in v0.63.7
WithHelpLineLength configures the maximum rendered help line length. Use a negative value to disable wrapping.
func WithVersion ¶ added in v0.62.1
WithVersion registers a built-in version command that prints the provided version string.
type Router ¶ added in v0.62.1
type Router struct {
// contains filtered or unexported fields
}
Router stores the command and group hierarchy used to resolve CLI input.
func NewRouter ¶ added in v0.62.1
NewRouter creates an empty router with an optional parent router for nested command groups.
func (*Router) DefaultCmd ¶ added in v0.62.1
DefaultCmd sets the command used when no explicit command matches the input.