cli

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2025 License: MIT Imports: 12 Imported by: 15

README

CLI Package

A simple and lightweight package for building command-line tools in Go.

This library was developed to address the need for creating CLI applications without the added complexity and dependencies of larger frameworks. It is designed to have a minimal footprint while maintaining functionality.

Features

  • Command and subcommand support
  • Named arguments
  • Flags including global flags
  • Configuration file support (TOML and JSON)
  • Environment variable support
  • Built-in help and version commands
  • Optional suggestions when command not found
  • Automatic help generation
  • Command completions for Bash, Zsh, Fish and PowerShell
  • Storing of flag values into variables
  • Type safe

Installation

go get github.com/paularlott/cli

Requires Go version 1.24.4 or later

Quick Start

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/paularlott/cli"
)

func main() {
	cmd := &cli.Command{
		Name:        "myapp",
		Version:     "1.0.0",
		Usage:       "Simple Example",
		Description: "This is a simple example command to demonstrate the CLI package features.",
		Flags: []cli.Flag{
			&cli.StringFlag{
				Name:     "name",
				Usage:    "Your name",
			},
		},
		Run: func(ctx context.Context, cmd *cli.Command) error {
			fmt.Println("Hello:", cmd.GetString("name"))

			return nil
		},
	}

	err := cmd.Execute(context.Background())
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(1)
	}

	os.Exit(0)
}

Help Command

When the help is enabled -h or --help will show the usage information for the current command.

Help Syntax Notation
Syntax Description
<required> A required argument
[optional] An optional argument
[args...] Additional optional arguments
<args...> Additional arguments
[flags] Command flags
[command] Subcommands available

Documentation

License

This project is licensed under the MIT License - see LICENSE.txt file for details.

Documentation

Index

Constants

View Source
const (
	NoArgs        = 0  // No unnamed arguments allowed
	UnlimitedArgs = -1 // Unlimited unnamed arguments allowed
)

Variables

View Source
var (
	ConfigFileNotFoundError = fmt.Errorf("configuration file not found")
)

Functions

func GetTypeText

func GetTypeText(value interface{}) string

GetTypeText returns a string representation of a type for help text display

func StrToPtr

func StrToPtr(v string) *string

StrToPtr converts a string to a pointer to a string.

Types

type Argument

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

type ArgumentTyped

type ArgumentTyped[T any] struct {
	Name        string               // Name of the argument
	Usage       string               // Usage description for the argument
	Required    bool                 // Whether this flag is required
	AssignTo    *T                   // Optional pointer to the variable where the value should be stored
	ValidateArg func(*Command) error // Optional validation for the argument
}

type BoolArg

type BoolArg = ArgumentTyped[bool]

type BoolFlag

type BoolFlag = FlagTyped[bool]

type Command

type Command struct {
	Name           string                                                           // Name of the command, e.g. "server", "config", etc.
	Version        string                                                           // Version of the command, e.g. "1.0.0"
	Usage          string                                                           // Short description of the command, e.g. "Start the server", "Show config", etc.
	Description    string                                                           // Longer description of the command, e.g. "This command starts the server with the given configuration", "This command shows the current configuration", etc.
	Flags          []Flag                                                           // Flags that are available for this command only
	Arguments      []Argument                                                       // Arguments that can be passed to this command, e.g. "server start <config-file>", "config show <section>", etc.
	MinArgs        int                                                              // Minimum number of unnamed arguments that are required for this command e.g. 0 for no minimum.
	MaxArgs        int                                                              // Maximum number of unnamed arguments that are allowed for this command e.g. 0 for no arguments, -1 for unlimited, or a specific number like 2 for "server start <config-file> <port>
	ConfigFile     ConfigFileSource                                                 // Configuration file reader.
	Commands       []*Command                                                       // Subcommands that can be executed under this command, e.g. "server start", "server stop", etc.
	Run            func(ctx context.Context, cmd *Command) error                    // Function to run when this command is executed, e.g. to start the server, show the config, etc.
	PreRun         func(ctx context.Context, cmd *Command) (context.Context, error) // Function to run before any command is executed, e.g. to set up logging, read config files, etc.
	PostRun        func(ctx context.Context, cmd *Command) error                    // Function to run after any command is executed, e.g. to clean up resources, log the result, etc.
	DisableHelp    bool                                                             // Disable the automatic help command for this command
	DisableVersion bool                                                             // Disable the automatic version command for this command
	Suggestions    bool                                                             // Enable suggestions for unknown commands, if true then the command will try to suggest similar commands if the command is not found
	// contains filtered or unexported fields
}

func GenerateCompletionCommand

func GenerateCompletionCommand() *Command

GenerateCompletionCommand creates a new command that outputs shell completion scripts

func (*Command) Execute

func (c *Command) Execute(ctx context.Context) error

func (*Command) GetArgs

func (c *Command) GetArgs() []string

Args returns the list of arguments that were passed to the command and have not been consumed by subcommands, flags and arguments

func (*Command) GetBool

func (c *Command) GetBool(name string) bool

func (*Command) GetBoolArg

func (c *Command) GetBoolArg(name string) bool

func (*Command) GetFloat32

func (c *Command) GetFloat32(name string) float32

func (*Command) GetFloat32Arg

func (c *Command) GetFloat32Arg(name string) float32

func (*Command) GetFloat32Slice

func (c *Command) GetFloat32Slice(name string) []float32

func (*Command) GetFloat64

func (c *Command) GetFloat64(name string) float64

func (*Command) GetFloat64Arg

func (c *Command) GetFloat64Arg(name string) float64

func (*Command) GetFloat64Slice

func (c *Command) GetFloat64Slice(name string) []float64

func (*Command) GetInt

func (c *Command) GetInt(name string) int

func (*Command) GetInt16

func (c *Command) GetInt16(name string) int16

func (*Command) GetInt16Arg

func (c *Command) GetInt16Arg(name string) int16

func (*Command) GetInt16Slice

func (c *Command) GetInt16Slice(name string) []int16

func (*Command) GetInt32

func (c *Command) GetInt32(name string) int32

func (*Command) GetInt32Arg

func (c *Command) GetInt32Arg(name string) int32

func (*Command) GetInt32Slice

func (c *Command) GetInt32Slice(name string) []int32

func (*Command) GetInt64

func (c *Command) GetInt64(name string) int64

func (*Command) GetInt64Arg

func (c *Command) GetInt64Arg(name string) int64

func (*Command) GetInt64Slice

func (c *Command) GetInt64Slice(name string) []int64

func (*Command) GetInt8

func (c *Command) GetInt8(name string) int8

func (*Command) GetInt8Arg

func (c *Command) GetInt8Arg(name string) int8

func (*Command) GetInt8Slice

func (c *Command) GetInt8Slice(name string) []int8

func (*Command) GetIntArg

func (c *Command) GetIntArg(name string) int

func (*Command) GetIntSlice

func (c *Command) GetIntSlice(name string) []int

func (*Command) GetRootCmd

func (c *Command) GetRootCmd() *Command

func (*Command) GetString

func (c *Command) GetString(name string) string

Flag getters

func (*Command) GetStringArg

func (c *Command) GetStringArg(name string) string

Argument getters

func (*Command) GetStringSlice

func (c *Command) GetStringSlice(name string) []string

Slice getters

func (*Command) GetUint

func (c *Command) GetUint(name string) uint

func (*Command) GetUint16

func (c *Command) GetUint16(name string) uint16

func (*Command) GetUint16Arg

func (c *Command) GetUint16Arg(name string) uint16

func (*Command) GetUint16Slice

func (c *Command) GetUint16Slice(name string) []uint16

func (*Command) GetUint32

func (c *Command) GetUint32(name string) uint32

func (*Command) GetUint32Arg

func (c *Command) GetUint32Arg(name string) uint32

func (*Command) GetUint32Slice

func (c *Command) GetUint32Slice(name string) []uint32

func (*Command) GetUint64

func (c *Command) GetUint64(name string) uint64

func (*Command) GetUint64Arg

func (c *Command) GetUint64Arg(name string) uint64

func (*Command) GetUint64Slice

func (c *Command) GetUint64Slice(name string) []uint64

func (*Command) GetUint8

func (c *Command) GetUint8(name string) uint8

func (*Command) GetUint8Arg

func (c *Command) GetUint8Arg(name string) uint8

func (*Command) GetUint8Slice

func (c *Command) GetUint8Slice(name string) []uint8

func (*Command) GetUintArg

func (c *Command) GetUintArg(name string) uint

func (*Command) GetUintSlice

func (c *Command) GetUintSlice(name string) []uint

func (*Command) HasArg

func (c *Command) HasArg(name string) bool

func (*Command) HasFlag

func (c *Command) HasFlag(name string) bool

HasFlag checks if a flag with the given name was set for this command

func (*Command) ReloadFlags

func (c *Command) ReloadFlags() error

func (*Command) ShowHelp

func (c *Command) ShowHelp()

type ConfigFileBase

type ConfigFileBase struct {
	FileName   *string             // Point to the configuration file name
	SearchPath SearchPathFunc      // Function to define the search paths for the config file
	Unmarshal  ConfigFileUnmarshal // Function to decode the configuration file content
	Marshal    ConfigFileMarshal   // Function to encode the configuration file content
	// contains filtered or unexported fields
}

func (*ConfigFileBase) DeleteKey

func (c *ConfigFileBase) DeleteKey(path string) error

func (*ConfigFileBase) FileUsed

func (c *ConfigFileBase) FileUsed() string

func (*ConfigFileBase) GetKeys

func (c *ConfigFileBase) GetKeys(path string) []string

func (*ConfigFileBase) GetValue

func (c *ConfigFileBase) GetValue(path string) (any, bool)

func (*ConfigFileBase) InitConfigFile

func (c *ConfigFileBase) InitConfigFile()

func (*ConfigFileBase) LoadData

func (c *ConfigFileBase) LoadData() error

func (*ConfigFileBase) OnChange

func (c *ConfigFileBase) OnChange(handler ConfigFileChangeHandler) error

func (*ConfigFileBase) Save

func (c *ConfigFileBase) Save() error

func (*ConfigFileBase) SetValue

func (c *ConfigFileBase) SetValue(path string, value any) error

type ConfigFileChangeHandler

type ConfigFileChangeHandler func()

type ConfigFileMarshal

type ConfigFileMarshal func(v any) ([]byte, error)

type ConfigFileSource

type ConfigFileSource interface {
	GetValue(string) (any, bool)            // Get the value from the configuration file at the specified path.
	GetKeys(string) []string                // Get the keys from the configuration file at the specified path.
	SetValue(string, any) error             // Set a value in the configuration file at the specified path.
	DeleteKey(string) error                 // Delete a key from the configuration file at the specified path.
	Save() error                            // Save the configuration file.
	OnChange(ConfigFileChangeHandler) error // Track changes to the configuration file.
	FileUsed() string                       // Get the file used for the configuration.
	LoadData() error                        // Load the configuration data from the file.
}

type ConfigFileTyped

type ConfigFileTyped interface {
	ConfigFileSource

	GetString(string) string                 // Get the string value from the configuration file at the specified path.
	GetInt(string) int                       // Get the int value from the configuration file at the specified path.
	GetInt64(string) int64                   // Get the int64 value from the configuration file at the specified path.
	GetInt32(string) int32                   // Get the int32 value from the configuration file at the specified path.
	GetInt16(string) int16                   // Get the int16 value from the configuration file at the specified path.
	GetInt8(string) int8                     // Get the int8 value from the configuration file at the specified path.
	GetUint(string) uint                     // Get the uint value from the configuration file at the specified path.
	GetUint64(string) uint64                 // Get the uint64 value from the configuration file at the specified path.
	GetUint32(string) uint32                 // Get the uint32 value from the configuration file at the specified path.
	GetUint16(string) uint16                 // Get the uint16 value from the configuration file at the specified path.
	GetUint8(string) uint8                   // Get the uint8 value from the configuration file at the specified path.
	GetFloat32(string) float32               // Get the float32 value from the configuration file at the specified path.
	GetFloat64(string) float64               // Get the float64 value from the configuration file at the specified path.
	GetBool(string) bool                     // Get the bool value from the configuration file at the specified path.
	GetStringSlice(string) []string          // Get the string slice value from the configuration file at the specified path.
	GetIntSlice(string) []int                // Get the int slice value from the configuration file at the specified path.
	GetInt64Slice(string) []int64            // Get the int64 slice value from the configuration file at the specified path.
	GetInt32Slice(string) []int32            // Get the int32 slice value from the configuration file at the specified path.
	GetInt16Slice(string) []int16            // Get the int16 slice value from the configuration file at the specified path.
	GetInt8Slice(string) []int8              // Get the int8 slice value from the configuration file at the specified path.
	GetUintSlice(string) []uint              // Get the uint slice value from the configuration file at the specified path.
	GetUint64Slice(string) []uint64          // Get the uint64 slice value from the configuration file at the specified path.
	GetUint32Slice(string) []uint32          // Get the uint32 slice value from the configuration file at the specified path.
	GetUint16Slice(string) []uint16          // Get the uint16 slice value from the configuration file at the specified path.
	GetUint8Slice(string) []uint8            // Get the uint8 slice value from the configuration file at the specified path.
	GetFloat32Slice(string) []float32        // Get the float32 slice value from the configuration file at the specified path.
	GetFloat64Slice(string) []float64        // Get the float64 slice value from the configuration file at the specified path.
	SetString(string, string) error          // Set the string value in the configuration file at the specified path.
	SetInt(string, int) error                // Set the int value in the configuration file at the specified path.
	SetInt64(string, int64) error            // Set the int64 value in the configuration file at the specified path.
	SetInt32(string, int32) error            // Set the int32 value in the configuration file at the specified path.
	SetInt16(string, int16) error            // Set the int16 value in the configuration file at the specified path.
	SetInt8(string, int8) error              // Set the int8 value in the configuration file at the specified path.
	SetUint(string, uint) error              // Set the uint value in the configuration file at the specified path.
	SetUint64(string, uint64) error          // Set the uint64 value in the configuration file at the specified path.
	SetUint32(string, uint32) error          // Set the uint32 value in the configuration file at the specified path.
	SetUint16(string, uint16) error          // Set the uint16 value in the configuration file at the specified path.
	SetUint8(string, uint8) error            // Set the uint8 value in the configuration file at the specified path.
	SetFloat32(string, float32) error        // Set the float32 value in the configuration file at the specified path.
	SetFloat64(string, float64) error        // Set the float64 value in the configuration file at the specified path.
	SetBool(string, bool) error              // Set the bool value in the configuration file at the specified path.
	SetStringSlice(string, []string) error   // Set the string slice value in the configuration file at the specified path.
	SetIntSlice(string, []int) error         // Set the int slice value in the configuration file at the specified path.
	SetInt64Slice(string, []int64) error     // Set the int64 slice value in the configuration file at the specified path.
	SetInt32Slice(string, []int32) error     // Set the int32 slice value in the configuration file at the specified path.
	SetInt16Slice(string, []int16) error     // Set the int16 slice value in the configuration file at the specified path.
	SetInt8Slice(string, []int8) error       // Set the int8 slice value in the configuration file at the specified path.
	SetUintSlice(string, []uint) error       // Set the uint slice value in the configuration file at the specified path.
	SetUint64Slice(string, []uint64) error   // Set the uint64 slice value in the configuration file at the specified path.
	SetUint32Slice(string, []uint32) error   // Set the uint32 slice value in the configuration file at the specified path.
	SetUint16Slice(string, []uint16) error   // Set the uint16 slice value in the configuration file at the specified path.
	SetUint8Slice(string, []uint8) error     // Set the uint8 slice value in the configuration file at the specified path.
	SetFloat32Slice(string, []float32) error // Set the float32 slice value in the configuration file at the specified path.
	SetFloat64Slice(string, []float64) error // Set the float64 slice value in the configuration file at the specified path.
}

type ConfigFileTypedWrapper

type ConfigFileTypedWrapper struct {
	// contains filtered or unexported fields
}

func NewTypedConfigFile

func NewTypedConfigFile(inner ConfigFileSource) *ConfigFileTypedWrapper

func (*ConfigFileTypedWrapper) DeleteKey

func (w *ConfigFileTypedWrapper) DeleteKey(path string) error

func (*ConfigFileTypedWrapper) FileUsed

func (w *ConfigFileTypedWrapper) FileUsed() string

func (*ConfigFileTypedWrapper) GetBool

func (c *ConfigFileTypedWrapper) GetBool(path string) bool

func (*ConfigFileTypedWrapper) GetFloat32

func (c *ConfigFileTypedWrapper) GetFloat32(path string) float32

func (*ConfigFileTypedWrapper) GetFloat32Slice

func (c *ConfigFileTypedWrapper) GetFloat32Slice(path string) []float32

func (*ConfigFileTypedWrapper) GetFloat64

func (c *ConfigFileTypedWrapper) GetFloat64(path string) float64

func (*ConfigFileTypedWrapper) GetFloat64Slice

func (c *ConfigFileTypedWrapper) GetFloat64Slice(path string) []float64

func (*ConfigFileTypedWrapper) GetInt

func (c *ConfigFileTypedWrapper) GetInt(path string) int

func (*ConfigFileTypedWrapper) GetInt16

func (c *ConfigFileTypedWrapper) GetInt16(path string) int16

func (*ConfigFileTypedWrapper) GetInt16Slice

func (c *ConfigFileTypedWrapper) GetInt16Slice(path string) []int16

func (*ConfigFileTypedWrapper) GetInt32

func (c *ConfigFileTypedWrapper) GetInt32(path string) int32

func (*ConfigFileTypedWrapper) GetInt32Slice

func (c *ConfigFileTypedWrapper) GetInt32Slice(path string) []int32

func (*ConfigFileTypedWrapper) GetInt64

func (c *ConfigFileTypedWrapper) GetInt64(path string) int64

func (*ConfigFileTypedWrapper) GetInt64Slice

func (c *ConfigFileTypedWrapper) GetInt64Slice(path string) []int64

func (*ConfigFileTypedWrapper) GetInt8

func (c *ConfigFileTypedWrapper) GetInt8(path string) int8

func (*ConfigFileTypedWrapper) GetInt8Slice

func (c *ConfigFileTypedWrapper) GetInt8Slice(path string) []int8

func (*ConfigFileTypedWrapper) GetIntSlice

func (c *ConfigFileTypedWrapper) GetIntSlice(path string) []int

func (*ConfigFileTypedWrapper) GetKeys

func (w *ConfigFileTypedWrapper) GetKeys(path string) []string

func (*ConfigFileTypedWrapper) GetString

func (c *ConfigFileTypedWrapper) GetString(path string) string

func (*ConfigFileTypedWrapper) GetStringSlice

func (c *ConfigFileTypedWrapper) GetStringSlice(path string) []string

func (*ConfigFileTypedWrapper) GetUint

func (c *ConfigFileTypedWrapper) GetUint(path string) uint

func (*ConfigFileTypedWrapper) GetUint16

func (c *ConfigFileTypedWrapper) GetUint16(path string) uint16

func (*ConfigFileTypedWrapper) GetUint16Slice

func (c *ConfigFileTypedWrapper) GetUint16Slice(path string) []uint16

func (*ConfigFileTypedWrapper) GetUint32

func (c *ConfigFileTypedWrapper) GetUint32(path string) uint32

func (*ConfigFileTypedWrapper) GetUint32Slice

func (c *ConfigFileTypedWrapper) GetUint32Slice(path string) []uint32

func (*ConfigFileTypedWrapper) GetUint64

func (c *ConfigFileTypedWrapper) GetUint64(path string) uint64

func (*ConfigFileTypedWrapper) GetUint64Slice

func (c *ConfigFileTypedWrapper) GetUint64Slice(path string) []uint64

func (*ConfigFileTypedWrapper) GetUint8

func (c *ConfigFileTypedWrapper) GetUint8(path string) uint8

func (*ConfigFileTypedWrapper) GetUint8Slice

func (c *ConfigFileTypedWrapper) GetUint8Slice(path string) []uint8

func (*ConfigFileTypedWrapper) GetUintSlice

func (c *ConfigFileTypedWrapper) GetUintSlice(path string) []uint

func (*ConfigFileTypedWrapper) GetValue

func (w *ConfigFileTypedWrapper) GetValue(path string) (any, bool)

func (*ConfigFileTypedWrapper) LoadData added in v0.2.0

func (c *ConfigFileTypedWrapper) LoadData() error

func (*ConfigFileTypedWrapper) OnChange

func (*ConfigFileTypedWrapper) Save

func (w *ConfigFileTypedWrapper) Save() error

func (*ConfigFileTypedWrapper) SetBool

func (c *ConfigFileTypedWrapper) SetBool(path string, value bool) error

func (*ConfigFileTypedWrapper) SetFloat32

func (c *ConfigFileTypedWrapper) SetFloat32(path string, value float32) error

func (*ConfigFileTypedWrapper) SetFloat32Slice

func (c *ConfigFileTypedWrapper) SetFloat32Slice(path string, value []float32) error

func (*ConfigFileTypedWrapper) SetFloat64

func (c *ConfigFileTypedWrapper) SetFloat64(path string, value float64) error

func (*ConfigFileTypedWrapper) SetFloat64Slice

func (c *ConfigFileTypedWrapper) SetFloat64Slice(path string, value []float64) error

func (*ConfigFileTypedWrapper) SetInt

func (c *ConfigFileTypedWrapper) SetInt(path string, value int) error

func (*ConfigFileTypedWrapper) SetInt16

func (c *ConfigFileTypedWrapper) SetInt16(path string, value int16) error

func (*ConfigFileTypedWrapper) SetInt16Slice

func (c *ConfigFileTypedWrapper) SetInt16Slice(path string, value []int16) error

func (*ConfigFileTypedWrapper) SetInt32

func (c *ConfigFileTypedWrapper) SetInt32(path string, value int32) error

func (*ConfigFileTypedWrapper) SetInt32Slice

func (c *ConfigFileTypedWrapper) SetInt32Slice(path string, value []int32) error

func (*ConfigFileTypedWrapper) SetInt64

func (c *ConfigFileTypedWrapper) SetInt64(path string, value int64) error

func (*ConfigFileTypedWrapper) SetInt64Slice

func (c *ConfigFileTypedWrapper) SetInt64Slice(path string, value []int64) error

func (*ConfigFileTypedWrapper) SetInt8

func (c *ConfigFileTypedWrapper) SetInt8(path string, value int8) error

func (*ConfigFileTypedWrapper) SetInt8Slice

func (c *ConfigFileTypedWrapper) SetInt8Slice(path string, value []int8) error

func (*ConfigFileTypedWrapper) SetIntSlice

func (c *ConfigFileTypedWrapper) SetIntSlice(path string, value []int) error

func (*ConfigFileTypedWrapper) SetString

func (c *ConfigFileTypedWrapper) SetString(path string, value string) error

func (*ConfigFileTypedWrapper) SetStringSlice

func (c *ConfigFileTypedWrapper) SetStringSlice(path string, value []string) error

func (*ConfigFileTypedWrapper) SetUint

func (c *ConfigFileTypedWrapper) SetUint(path string, value uint) error

func (*ConfigFileTypedWrapper) SetUint16

func (c *ConfigFileTypedWrapper) SetUint16(path string, value uint16) error

func (*ConfigFileTypedWrapper) SetUint16Slice

func (c *ConfigFileTypedWrapper) SetUint16Slice(path string, value []uint16) error

func (*ConfigFileTypedWrapper) SetUint32

func (c *ConfigFileTypedWrapper) SetUint32(path string, value uint32) error

func (*ConfigFileTypedWrapper) SetUint32Slice

func (c *ConfigFileTypedWrapper) SetUint32Slice(path string, value []uint32) error

func (*ConfigFileTypedWrapper) SetUint64

func (c *ConfigFileTypedWrapper) SetUint64(path string, value uint64) error

func (*ConfigFileTypedWrapper) SetUint64Slice

func (c *ConfigFileTypedWrapper) SetUint64Slice(path string, value []uint64) error

func (*ConfigFileTypedWrapper) SetUint8

func (c *ConfigFileTypedWrapper) SetUint8(path string, value uint8) error

func (*ConfigFileTypedWrapper) SetUint8Slice

func (c *ConfigFileTypedWrapper) SetUint8Slice(path string, value []uint8) error

func (*ConfigFileTypedWrapper) SetUintSlice

func (c *ConfigFileTypedWrapper) SetUintSlice(path string, value []uint) error

func (*ConfigFileTypedWrapper) SetValue

func (w *ConfigFileTypedWrapper) SetValue(path string, v any) error

type ConfigFileUnmarshal

type ConfigFileUnmarshal func(data []byte, v any) error

type Flag

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

type FlagTyped

type FlagTyped[T any] struct {
	Name         string               // Name of the flag, e.g. "server"
	Usage        string               // Short description of the flag, e.g. "The server to connect to"
	Aliases      []string             // Aliases for the flag, e.g. "s" for "server"
	ConfigPath   []string             // Configuration paths for the flag, e.g. "cli.server"
	DefaultValue T                    // Default value for the flag, e.g. "localhost" for server
	DefaultText  string               // Text to show in usage as the default value, e.g. "localhost"
	AssignTo     *T                   // Optional pointer to the variable where the value should be stored
	EnvVars      []string             // Environment variables that can be used to set this flag, first found will be used
	Required     bool                 // Whether this flag is required
	Global       bool                 // Whether this flag is global, i.e. available in all commands
	HideDefault  bool                 // Whether to hide the default value in usage output
	HideType     bool                 // Whether to hide the type in usage output
	Hidden       bool                 // Whether this flag is hidden from help and command completions
	ValidateFlag func(*Command) error // Validation function for the flag
}

type Float32Arg

type Float32Arg = ArgumentTyped[float32]

type Float32Flag

type Float32Flag = FlagTyped[float32]

type Float32SliceFlag

type Float32SliceFlag = FlagTyped[[]float32]

type Float64Arg

type Float64Arg = ArgumentTyped[float64]

type Float64Flag

type Float64Flag = FlagTyped[float64]

type Float64SliceFlag

type Float64SliceFlag = FlagTyped[[]float64]

type Int16Arg

type Int16Arg = ArgumentTyped[int16]

type Int16Flag

type Int16Flag = FlagTyped[int16]

type Int16SliceFlag

type Int16SliceFlag = FlagTyped[[]int16]

type Int32Arg

type Int32Arg = ArgumentTyped[int32]

type Int32Flag

type Int32Flag = FlagTyped[int32]

type Int32SliceFlag

type Int32SliceFlag = FlagTyped[[]int32]

type Int64Arg

type Int64Arg = ArgumentTyped[int64]

type Int64Flag

type Int64Flag = FlagTyped[int64]

type Int64SliceFlag

type Int64SliceFlag = FlagTyped[[]int64]

type Int8Arg

type Int8Arg = ArgumentTyped[int8]

type Int8Flag

type Int8Flag = FlagTyped[int8]

type Int8SliceFlag

type Int8SliceFlag = FlagTyped[[]int8]

type IntArg

type IntArg = ArgumentTyped[int]

type IntFlag

type IntFlag = FlagTyped[int]

type IntSliceFlag

type IntSliceFlag = FlagTyped[[]int]

type SearchPathFunc

type SearchPathFunc func() []string

type StringArg

type StringArg = ArgumentTyped[string]

type StringFlag

type StringFlag = FlagTyped[string]

type StringSliceFlag

type StringSliceFlag = FlagTyped[[]string]

type Uint16Arg

type Uint16Arg = ArgumentTyped[uint16]

type Uint16Flag

type Uint16Flag = FlagTyped[uint16]

type Uint16SliceFlag

type Uint16SliceFlag = FlagTyped[[]uint16]

type Uint32Arg

type Uint32Arg = ArgumentTyped[uint32]

type Uint32Flag

type Uint32Flag = FlagTyped[uint32]

type Uint32SliceFlag

type Uint32SliceFlag = FlagTyped[[]uint32]

type Uint64Arg

type Uint64Arg = ArgumentTyped[uint64]

type Uint64Flag

type Uint64Flag = FlagTyped[uint64]

type Uint64SliceFlag

type Uint64SliceFlag = FlagTyped[[]uint64]

type Uint8Arg

type Uint8Arg = ArgumentTyped[uint8]

type Uint8Flag

type Uint8Flag = FlagTyped[uint8]

type Uint8SliceFlag

type Uint8SliceFlag = FlagTyped[[]uint8]

type UintArg

type UintArg = ArgumentTyped[uint]

type UintFlag

type UintFlag = FlagTyped[uint]

type UintSliceFlag

type UintSliceFlag = FlagTyped[[]uint]

Directories

Path Synopsis
examples
basic command
file_watch command

Jump to

Keyboard shortcuts

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