cli

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2025 License: Apache-2.0 Imports: 8 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

	// Run executes the command.
	Run func(ctx context.Context, cfg *config.Config) 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 (*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) Lookup

func (c *Command) Lookup(name string) (*Command, error)

Lookup finds a command by its name, and returns an error if the command is not found.

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) Parse

func (c *Command) Parse(args []string) error

Parse parses the provided command-line arguments using the command's flag set.

Jump to

Keyboard shortcuts

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