cli

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package cli defines a lightweight framework for building CLI commands. It's designed to be generic and self-contained, with no embedded business logic or dependencies on the surrounding application's configuration or behavior.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Version

func Version() string

Version return the version information for the binary, which is constructed following https://go.dev/ref/mod#versions.

Types

type Command

type Command struct {
	// Short is a concise one-line description of the command.
	Short string

	// UsageLine is the one line usage.
	UsageLine string

	// Long is the full description of the command.
	Long string

	// Action executes the command.
	Action func(context.Context, *Command) error

	// Commands are the sub commands.
	Commands []*Command

	// Flags is the command's flag set for parsing arguments and generating
	// usage messages. This is populated for each command in init().
	Flags *flag.FlagSet

	// Config contains the configs for the command.
	Config *config.Config
}

Command represents a single command that can be executed by the application.

func NewCommandSet added in v0.7.0

func NewCommandSet(commands []*Command, short, usageLine, long string) *Command

NewCommandSet creates and initializes a root *Command object. It automatically appends a "version" subcommand to the list.

func (*Command) Init

func (c *Command) Init() *Command

Init creates a new set of flags for the command and initializes them such that any parsing failures result in the command usage being displayed.

func (*Command) Name

func (c *Command) Name() string

Name is the command name. Command.Short is always expected to begin with this name.

func (*Command) Run

func (c *Command) Run(ctx context.Context, args []string) error

Run executes the command with the provided arguments.

Jump to

Keyboard shortcuts

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