cli

package
v0.63.7 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetArguments added in v0.63.7

func GetArguments(config cfg.Config) ([]string, error)

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

func UnmarshalFlags[T any](config cfg.Config) (*T, error)

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.

func NewBlueprint added in v0.62.1

func NewBlueprint(router *Router, input *Input, globalFlags ...Flag) (*Blueprint, error)

NewBlueprint resolves parsed input against a router and returns the command blueprint to execute.

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.

func NewCli added in v0.62.1

func NewCli(options ...Option) *Cli

NewCli creates a CLI with the default router and applies the provided options when Run is called.

func (*Cli) Run added in v0.62.1

func (c *Cli) Run()

Run parses process arguments, resolves the selected command, and starts the configured gosoline application.

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

type CmdExample struct {
	Description string
	Args        string
}

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 (
	// 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
}

Input contains the parsed command line arguments and flags.

func NewInput added in v0.62.1

func NewInput() (*Input, error)

NewInput parses the current process command line arguments.

func NewInputWithArgs added in v0.62.1

func NewInputWithArgs(args []string) (*Input, error)

NewInputWithArgs parses the provided command line arguments into positional arguments and flags.

type InputFlag added in v0.63.7

type InputFlag struct {
	Name  string
	Value string
}

InputFlag is a parsed command line flag name and value pair.

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 WithFlag added in v0.62.1

func WithFlag(flag Flag) Option

WithFlag registers a global CLI flag available to every command.

func WithHelp added in v0.63.7

func WithHelp(name string, description string) Option

WithHelp configures top-level help text and registers the built-in help command.

func WithHelpLineLength added in v0.63.7

func WithHelpLineLength(length int) Option

WithHelpLineLength configures the maximum rendered help line length. Use a negative value to disable wrapping.

func WithVersion added in v0.62.1

func WithVersion(version string) Option

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

func NewRouter(parent *Router) *Router

NewRouter creates an empty router with an optional parent router for nested command groups.

func (*Router) Cmd added in v0.62.1

func (r *Router) Cmd(cmd Cmd) *Router

Cmd registers a command on the router.

func (*Router) DefaultCmd added in v0.62.1

func (r *Router) DefaultCmd(cmd Cmd) *Router

DefaultCmd sets the command used when no explicit command matches the input.

func (*Router) Group added in v0.62.1

func (r *Router) Group(group Group, subCommands ...Cmd) *Router

Group registers a command group and optional subcommands, returning the group's child router.

Jump to

Keyboard shortcuts

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