tinyflags

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2025 License: Apache-2.0 Imports: 11 Imported by: 1

README

tinyflags

Go Reference

tinyflags is a minimal, fast, and extensible CLI flag parsing library for Go, heavily inspired by pflag and kingpin. It supports advanced features like environment overrides, validation, required flags, shorthand syntax, and flexible usage formatting -- all while staying light and dependency-free.

Features

  • 🧩 Short and long flags (-d, --debug)
  • 🧪 Boolean flags with optional --no-flag strict parsing (--no-flag=true)
  • 🌲 Environment variable support (per-flag and global prefix)
  • 🧯 Required flags and deprecation notices
  • 🧵 Support for []T slice flags with custom delimiters
  • ⚠️ Choices and validation
  • 🧑‍🤝‍🧑 Mutual exclusion groups
  • 🔒 Disable environment lookups per flag
  • 🎛 Custom metavars for help
  • 🆘 Rich help output with wrapping and alignment
  • ✅ Direct value assignment via pointer
  • 🛠 Fully type-safe API with generics

Install

go get github.com/containeroo/tinyflags

Example

package main

import (
	"fmt"
	"os"

	"github.com/containeroo/tinyflags"
)

func main() {
	// Usually you would parse args from os.Args[1:]
	// but for this example we'll just hard-code them.
	args := []string{
		"--port=9000",
		"--host=example.com",
		"-vtrue",
	}

	fs := tinyflags.NewFlagSet("app", tinyflags.ExitOnError)
	fs.Version("v1.0")    // optional, enables -v, --version
	fs.EnvPrefix("MYAPP") // optional, enables --env-key for all flags

	host := fs.String("host", "localhost", "host to use").
		Required().
		Value()

	port := fs.Int("port", 8080, "port to listen on").
		Env("MYAPP_CUSTOM_PORT"). // overrides default env key (otherwise "MYAPP_PORT")
		Required().
		Value()

	debug := fs.BoolP("debug", "d", false, "enable debug mode").
		Strict().
		Value()

	tags := fs.StringSlice("tag", []string{}, "list of tags").
		Value()

	loglevel := fs.String("log-level", "info", "log level to use").
		Choices("debug", "info", "warn", "error").
		Value()

	if err := fs.Parse(args); err != nil {
		if tinyflags.IsHelpRequested(err) || tinyflags.IsVersionRequested(err) {
			fmt.Fprint(os.Stdout, err.Error()+"\n") // nolint:errcheck
			os.Exit(0)
		}
		fmt.Fprintln(os.Stderr, err.Error()+"\n") //nolint:errcheck
		os.Exit(1)
	}

	fmt.Println("Host:", host)
	fmt.Println("Port:", port)
	fmt.Println("Debug:", debug)
	fmt.Println("Tags:", tags)
	fmt.Println("Loglevel:", loglevel)
}

Help output looks like this:

Usage: test.exe -d -i -v <true|false>
      --port PORT                             port to use (Default: 8080) (Env: MYAPP_CUSTOM_PORT) (Required)
      --host HOST                             host to use (Default: localhost) (Env: MYAPP_HOST) (Required)
      --host-ip HOST-IP                       host ip to use. Must be in range 10.0.10.0/32
                                              (Default: 10.0.10.8) (Env: MYAPP_HOST_IP)
      --log-level <debug|info|warn|error>     log level to use (Allowed: debug, info, warn, error)
                                              (Default: info) (Env: MYAPP_LOG_LEVEL)
  -d, --debug                                 debug mode (Env: MYAPP_DEBUG)
  -i, --insecure                              insecure mode (Env: MYAPP_INSECURE)
  -v, --verbose <true|false>                  verbose mode (Default: false) (Env: MYAPP_VERBOSE)
      --version                               show version

Environment Variables

You can override flags via environment variables:

MYAPP_PORT=9090 ./myapp --debug

To control this behavior globally:

fs.EnvPrefix("MYAPP")

To disable env lookup for a specific flag:

fs.Bool("internal-flag", false, "something internal").
   DisableEnv()

Help Output

Usage: myapp [flags] // tinyflags.PrintUsage()

My Title (tinyFlags.Title("My Title")

Some Description (tinyFlags.Description("Some Description")

      --port PORT       port to listen on (Default: 8080) (Env: MYAPP_PORT) (Required)
  -d, --debug           enable debug mode (Env: MYAPP_DEBUG)
      --tag TAG...      list of tags (Env: MYAPP_TAG)

Note (tinyFlags.Note("Text")

Supports aligned columns, wrapped descriptions, and positional arguments.

📦 Flag Types

Go Type Flag Methods (shorthand versions use *P suffix) Notes
bool Bool, BoolP, BoolVar, BoolVarP
int Int, IntP, IntVar, IntVarP
string String, StringP, StringVar, StringVarP
float64 Float64, Float64P, Float64Var, Float64VarP
time.Duration Duration, DurationP, DurationVar, DurationVarP
[]string Strings, StringsP, StringsVar, StringsVarP Also supports delimiter
[]int Ints, IntsP, IntsVar, IntsVarP
[]float64 Float64s, Float64sP, Float64sVar, Float64sVarP
[]time.Duration Durations, DurationsP, DurationsVar, DurationsVarP
net.IP IP, IPP, IPVar, IPVarP
[]net.IP IPSlice, IPSliceP, IPSliceVar, IPSliceVarP
net.IPMask IPMask, IPMaskP, IPMaskVar, IPMaskVarP IPv4 mask only
[]net.IPMask IPMaskSlice, IPMaskSliceP, IPMaskSliceVar, IPMaskSliceVarP
*net.TCPAddr ListenAddr, ListenAddrP, ListenAddrVar, ListenAddrVarP Parsed using net.ResolveTCPAddr("tcp", ...)
[]*net.TCPAddr ListenAddrSlice, ListenAddrSliceP, ListenAddrSliceVar, ListenAddrSliceVarP
*os.File File, FileP, FileVar, FileVarP Opened for reading (os.Open)
[]*os.File FileSlice, FileSliceP, FileSliceVar, FileSliceVarP All files opened
url.URL URL, URLP, URLVar, URLVarP Parsed using url.Parse
[]url.URL URLSlice, URLSliceP, URLSliceVar, URLSliceVarP
string (custom) SchemaHostPort, SchemaHostPortP, SchemaHostPortVar, SchemaHostPortVarP Requires format scheme://host:port

💡 All slice types support configurable delimiters (e.g., --ips=1.1.1.1,8.8.8.8) and repeated usage (e.g., --ips=1.1.1.1 --ips=8.8.8.8).

All flags return a flag with methods:

Builder Methods
Method Description
.Env("KEY") Set a custom environment variable
.Required() Mark the flag as required
.Deprecated("...") Mark the flag as deprecated
.Group("name") Place flag in a mutual exclusion group
.Choices(...) Allow only specific values (auto-formatted in help)
.Validator(func) Add a custom validation function
.Metavar("FOO") Customize the metavar name in help
.Strict() (bool) For bool flags, require explicit --flag=true/false, also supports --no-flag
.Delimiter(",") (slice) For slice flags, split using delimiter
.DisableEnv() Prevent the flag from being set via environment variable
.Value() Get a pointer to the parsed flag value

Mutual Exclusion Groups

fs.String("file", "", "use a file").Group("input")
fs.String("url", "", "fetch from url").Group("input")

Only one of --file or --url can be set.

Positional Arguments

fs.RequirePositional(1) // Require at least 1 positional

Use fs.Args() to access them.

Advanced Output Customization

fs.DescriptionIndent(50)
fs.DescriptionMaxLen(100)
fs.UsagePrintMode(tinyflags.PrintShort)
fs.PrintUsage()
fs.PrintTitle("My awsome App")
fs.PrintDescription("MyApp is a simple tool...")
fs.PrintDefaults() // show all flags with their current values

Behavior

  • Unrecognized flags return an error.
  • Positional arguments begin after -- or after the first non-flag arg.
  • Bools default to false, or true if present (unless Strict() is used).
  • Slice flags can be repeated like --flag=a --flag=b --flag=c or --flag=a,b,c
  • Short flags can be combined like -abc or -a -b -c.
  • Short flags can be like -p 8080 or -p=8080.

Nice to know

Use fs.Args() to access all positional arguments. Use IsHelpRequested(err) and IsVersionRequested(err) to check for help/version flags.

License

This project is licensed under the Apache 2.0 License. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAs

func GetAs[T any](fs *FlagSet, name string) (T, error)

GetAs returns the typed value for a flag or an error.

func IsHelpRequested

func IsHelpRequested(err error) bool

IsHelpRequested checks if the error is a HelpRequested sentinel.

func IsVersionRequested

func IsVersionRequested(err error) bool

IsVersionRequested checks if the error is a VersionRequested sentinel

func RequestHelp

func RequestHelp(msg string) error

RequestHelp returns an error with type HelpRequested and the given message.

func RequestVersion

func RequestVersion(msg string) error

RequestVersion returns an error with type VersionRequested and the given message.

Types

type BoolValue

type BoolValue struct {
	*FlagItem[bool]
	// contains filtered or unexported fields
}

BoolValue wraps BaseValue[bool] and implements StrictBool.

func (*BoolValue) IsStrictBool

func (b *BoolValue) IsStrictBool() bool

IsStrictBool reports true if the flag must be passed explicitly as true/false.

type ErrorHandling

type ErrorHandling int
const (
	// ContinueOnError will return an err from Parse() if an error is found
	ContinueOnError ErrorHandling = iota
	// ExitOnError will call os.Exit(2) if an error is found when parsing
	ExitOnError
	// PanicOnError will panic() if an error is found when parsing flags
	PanicOnError
)

type Flag

type Flag[T any] struct {
	// contains filtered or unexported fields
}

Flag is a generic type for defining scalar.

func (*Flag[T]) Choices

func (b *Flag[T]) Choices(allowed ...T) *Flag[T]

Choices restricts the allowed values for this flag to a predefined set.

func (*Flag[T]) Deprecated

func (b *Flag[T]) Deprecated(reason string) *Flag[T]

Deprecated marks the flag as deprecated, and the provided reason is shown in help output.

func (*Flag[T]) DisableEnv

func (b *Flag[T]) DisableEnv() *Flag[T]

DisableEnv disables reading from environment variables for this flag, even if a global prefix is configured via the FlagSet.

func (*Flag[T]) Env

func (b *Flag[T]) Env(key string) *Flag[T]

Env sets the environment variable name that can override this flag. If not set explicitly, a default name is generated based on the flag name.

func (*Flag[T]) Group

func (b *Flag[T]) Group(name string) *Flag[T]

Group assigns this flag to a mutual exclusion group. Flags in the same group are mutually exclusive and cannot be used together.

func (*Flag[T]) Hidden

func (b *Flag[T]) Hidden() *Flag[T]

Hidden marks the flag as hidden, and it will not be shown in help output.

func (*Flag[T]) Metavar

func (b *Flag[T]) Metavar(s string) *Flag[T]

Metavar sets the placeholder name shown in help output for the flag value. If not set, it defaults to the uppercase flag name.

func (*Flag[T]) Required

func (b *Flag[T]) Required() *Flag[T]

Required marks this flag as required. Parsing will fail if it is not provided.

func (*Flag[T]) Validator

func (b *Flag[T]) Validator(fn func(T) error) *Flag[T]

Validator adds a custom validation function for the flag value.

func (*Flag[T]) Value

func (b *Flag[T]) Value() T

Value returns a pointer to the underlying parsed value.

type FlagItem

type FlagItem[T any] struct {
	// contains filtered or unexported fields
}

FlagItem is a generic flag value holder for scalar types. It implements the Value interface and tracks the parsed value, default value, and whether the value has been changed.

func NewFlagItem

func NewFlagItem[T any](ptr *T, def T, parse func(string) (T, error), format func(T) string) *FlagItem[T]

NewFlagItem constructs a new BaseValue for scalar flags. The parse and format functions must be provided to convert values to/from strings.

func (*FlagItem[T]) Default

func (v *FlagItem[T]) Default() string

Default returns the default value formatted as a string.

func (*FlagItem[T]) Get

func (v *FlagItem[T]) Get() any

Get returns the current value stored in the pointer.

func (*FlagItem[T]) IsChanged

func (v *FlagItem[T]) IsChanged() bool

IsChanged reports whether the value was explicitly set.

func (*FlagItem[T]) Set

func (v *FlagItem[T]) Set(s string) error

Set parses and sets the value from the given string.

func (*FlagItem[T]) SetValidator

func (v *FlagItem[T]) SetValidator(fn func(T) error, allowed []T)

SetValidator sets a validation callback for this flag.

type FlagPrintMode

type FlagPrintMode int

FlagPrintMode defines how flags are displayed in usage.

const (
	PrintShort FlagPrintMode = iota // Show only short flags: -x
	PrintLong                       // Show only long flags: --xyz
	PrintBoth                       // Show both: -x|--xyz
	PrintFlags                      // Prints "Flags"
	PrintNone                       // Hide all flags
)

type FlagSet

type FlagSet struct {
	Usage func() // custom usage printer
	// contains filtered or unexported fields
}

FlagSet stores configuration and registered flags for parsing.

func NewFlagSet

func NewFlagSet(name string, errorHandling ErrorHandling) *FlagSet

NewFlagSet creates a new FlagSet with a name and error behavior.

func (*FlagSet) Arg

func (f *FlagSet) Arg(i int) (string, bool)

Arg returns the i-th positional argument.

func (*FlagSet) Args

func (f *FlagSet) Args() []string

Args returns all captured positional arguments.

func (*FlagSet) Bool

func (f *FlagSet) Bool(name string, def bool, usage string) *boolFlag

Bool defines a bool flag with the specified name, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) BoolP

func (f *FlagSet) BoolP(name, short string, def bool, usage string) *boolFlag

BoolP defines a bool flag with the specified name, shorthand, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) BoolSlice

func (f *FlagSet) BoolSlice(name string, def []bool, usage string) *SliceFlag[[]bool]

BoolSlice defines a bool slice flag with the specified name, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) BoolSliceP

func (f *FlagSet) BoolSliceP(name, short string, def []bool, usage string) *SliceFlag[[]bool]

func (*FlagSet) BoolSliceVar

func (f *FlagSet) BoolSliceVar(ptr *[]bool, name string, def []bool, usage string) *SliceFlag[[]bool]

BoolSlice defines a bool slice flag with the specified name, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) BoolSliceVarP

func (f *FlagSet) BoolSliceVarP(ptr *[]bool, name, short string, def []bool, usage string) *SliceFlag[[]bool]

BoolSliceP defines a bool flag with the specified name, shorthand, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) BoolVar

func (f *FlagSet) BoolVar(ptr *bool, name string, def bool, usage string) *boolFlag

BoolVar defines a bool flag with the specified name, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) BoolVarP

func (f *FlagSet) BoolVarP(ptr *bool, name, short string, def bool, usage string) *boolFlag

BoolVarP defines a bool flag with the specified name, shorthand, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) Description

func (f *FlagSet) Description(s string)

Description sets optional text before usage help.

func (*FlagSet) DescriptionIndent

func (f *FlagSet) DescriptionIndent(indent int)

DescriptionIndent sets the indentation for descriptions.

func (*FlagSet) DescriptionMaxLen

func (f *FlagSet) DescriptionMaxLen(line int)

DescriptionMaxLen sets the max line length for descriptions.

func (*FlagSet) DisableHelp

func (f *FlagSet) DisableHelp()

DisableHelp disables automatic help flag registration.

func (*FlagSet) DisableVersion

func (f *FlagSet) DisableVersion()

DisableVersion disables automatic version flag registration.

func (*FlagSet) Duration

func (f *FlagSet) Duration(name string, def time.Duration, usage string) *Flag[time.Duration]

Duration defines a duration flag with the specified name, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) DurationP

func (f *FlagSet) DurationP(name, short string, def time.Duration, usage string) *Flag[time.Duration]

DurationP defines a duration flag with the specified name, shorthand, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) DurationSlice

func (f *FlagSet) DurationSlice(name string, def []time.Duration, usage string) *SliceFlag[[]time.Duration]

DurationSlice defines a duration slice flag with the specified name, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) DurationSliceP

func (f *FlagSet) DurationSliceP(name, short string, def []time.Duration, usage string) *SliceFlag[[]time.Duration]

DurationSliceP defines a duration flag with the specified name, shorthand, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) DurationSliceVar

func (f *FlagSet) DurationSliceVar(ptr *[]time.Duration, name string, def []time.Duration, usage string) *SliceFlag[[]time.Duration]

DurationSliceVar defines a duration slice flag with the specified name, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().// The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) DurationSliceVarP

func (f *FlagSet) DurationSliceVarP(ptr *[]time.Duration, name, short string, def []time.Duration, usage string) *SliceFlag[[]time.Duration]

DurationSliceVarP defines a duration slice flag with the specified name, shorthand, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) DurationVar

func (f *FlagSet) DurationVar(ptr *time.Duration, name string, def time.Duration, usage string) *Flag[time.Duration]

DurationVar defines a duration flag with the specified name, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) DurationVarP

func (f *FlagSet) DurationVarP(ptr *time.Duration, name, short string, def time.Duration, usage string) *Flag[time.Duration]

DurationVarP defines a duration flag with the specified name, shorthand, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) EnvPrefix

func (f *FlagSet) EnvPrefix(prefix string)

EnvPrefix sets the environment prefix for all flags.

func (*FlagSet) File

func (f *FlagSet) File(name string, def *os.File, usage string) *Flag[*os.File]

File defines a file flag with the specified name, default value, and usage string. Each input string is interpreted as a file path and opened using os.Open. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) FileP

func (f *FlagSet) FileP(name, short string, def *os.File, usage string) *Flag[*os.File]

FileP defines a file flag with the specified name, shorthand, default value, and usage string. Each input string is interpreted as a file path and opened using os.Open. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) FileSlice

func (f *FlagSet) FileSlice(name string, def []*os.File, usage string) *SliceFlag[[]*os.File]

FileSlice defines a file slice flag with the specified name, default value, and usage string. Each input string is interpreted as a file path and opened using os.Open. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) FileSliceP

func (f *FlagSet) FileSliceP(name, short string, def []*os.File, usage string) *SliceFlag[[]*os.File]

FileSliceP defines a file slice flag with the specified name, shorthand, default value, and usage string. Each input string is interpreted as a file path and opened using os.Open. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) FileSliceVar

func (f *FlagSet) FileSliceVar(ptr *[]*os.File, name string, def []*os.File, usage string) *SliceFlag[[]*os.File]

FileSliceVar defines a file slice flag with the specified name, default value, and usage string. Each input string is interpreted as a file path and opened using os.Open. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) FileSliceVarP

func (f *FlagSet) FileSliceVarP(ptr *[]*os.File, name, short string, def []*os.File, usage string) *SliceFlag[[]*os.File]

FileSliceVarP defines a file slice flag with the specified name, shorthand, default value, and usage string. Each input string is interpreted as a file path and opened using os.Open. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) FileVar

func (f *FlagSet) FileVar(ptr **os.File, name string, def *os.File, usage string) *Flag[*os.File]

FileVar defines a file flag with the specified name, default value, and usage string. Each input string is interpreted as a file path and opened using os.Open. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) FileVarP

func (f *FlagSet) FileVarP(ptr **os.File, name, short string, def *os.File, usage string) *Flag[*os.File]

FileVarP defines a file flag with the specified name, shorthand, default value, and usage string. Each input string is interpreted as a file path and opened using os.Open. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) Float32

func (f *FlagSet) Float32(name string, def float32, usage string) *Flag[float32]

Float32 defines a float32 flag with the specified name, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) Float32P

func (f *FlagSet) Float32P(name, short string, def float32, usage string) *Flag[float32]

Float32P defines a float32 flag with the specified name, shorthand, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) Float32Slice

func (f *FlagSet) Float32Slice(name string, def []float32, usage string) *SliceFlag[[]float32]

Float32Slice defines a float32 slice flag with the specified name, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) Float32SliceP

func (f *FlagSet) Float32SliceP(name, short string, def []float32, usage string) *SliceFlag[[]float32]

Float32SliceP defines a float32 slice flag with the specified name, shorthand, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) Float32SliceVar

func (f *FlagSet) Float32SliceVar(ptr *[]float32, name string, def []float32, usage string) *SliceFlag[[]float32]

Float32SliceVar defines a float32 slice flag with the specified name, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) Float32SliceVarP

func (f *FlagSet) Float32SliceVarP(ptr *[]float32, name, short string, def []float32, usage string) *SliceFlag[[]float32]

Float32SliceVarP defines a float32 slice flag with the specified name, shorthand, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) Float32Var

func (f *FlagSet) Float32Var(ptr *float32, name string, def float32, usage string) *Flag[float32]

Float32Var defines a float32 flag with the specified name, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) Float32VarP

func (f *FlagSet) Float32VarP(ptr *float32, name, short string, def float32, usage string) *Flag[float32]

Float32VarP defines a float32 flag with the specified name, shorthand, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) Float64

func (f *FlagSet) Float64(name string, def float64, usage string) *Flag[float64]

Float64 defines a float64 flag with the specified name, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) Float64P

func (f *FlagSet) Float64P(name, short string, def float64, usage string) *Flag[float64]

Float64P defines a float64 flag with the specified name, shorthand, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) Float64Slice

func (f *FlagSet) Float64Slice(name string, def []float64, usage string) *SliceFlag[[]float64]

Float64Slice defines a float64 slice flag with the specified name, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) Float64SliceP

func (f *FlagSet) Float64SliceP(name, short string, def []float64, usage string) *SliceFlag[[]float64]

Float64SliceP defines a float64 slice flag with the specified name, shorthand, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) Float64SliceVar

func (f *FlagSet) Float64SliceVar(ptr *[]float64, name string, def []float64, usage string) *SliceFlag[[]float64]

Float64SliceVar defines a float64 slice flag with the specified name, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) Float64SliceVarP

func (f *FlagSet) Float64SliceVarP(ptr *[]float64, name, short string, def []float64, usage string) *SliceFlag[[]float64]

Float64SliceVarP defines a float64 slice flag with the specified name, shorthand, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) Float64Var

func (f *FlagSet) Float64Var(ptr *float64, name string, def float64, usage string) *Flag[float64]

Float64Var defines a float64 flag with the specified name, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) Float64VarP

func (f *FlagSet) Float64VarP(ptr *float64, name, short string, def float64, usage string) *Flag[float64]

Float64VarP defines a float64 flag with the specified name, shorthand, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) Get

func (f *FlagSet) Get(name string) (any, error)

Get returns the parsed value for a named flag.

func (*FlagSet) Globaldelimiter

func (f *FlagSet) Globaldelimiter(s string)

Globaldelimiter sets the default delimiter for slice flags.

func (*FlagSet) Group

func (f *FlagSet) Group(name string, flag *baseFlag)

Group adds a flag to a named mutual exclusion group.

func (*FlagSet) HostPort

func (f *FlagSet) HostPort(name, def string, usage string) *Flag[string]

HostPort defines a string flag that must represent a valid host:port pair, with the specified name, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) HostPortP

func (f *FlagSet) HostPortP(name, short, def string, usage string) *Flag[string]

HostPortP defines a string flag that must represent a valid host:port pair, with the specified name, shorthand, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) HostPortSlice

func (f *FlagSet) HostPortSlice(name string, def []string, usage string) *SliceFlag[[]string]

HostPortSlice defines a string slice flag where each element must be a valid host:port pair, with the specified name, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) HostPortSliceP

func (f *FlagSet) HostPortSliceP(name, short string, def []string, usage string) *SliceFlag[[]string]

HostPortSliceP defines a string slice flag where each element must be a valid host:port pair, with the specified name, shorthand, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) HostPortSliceVar

func (f *FlagSet) HostPortSliceVar(ptr *[]string, name string, def []string, usage string) *SliceFlag[[]string]

HostPortSliceVar defines a string slice flag where each element must be a valid host:port pair, with the specified name, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) HostPortSliceVarP

func (f *FlagSet) HostPortSliceVarP(ptr *[]string, name, short string, def []string, usage string) *SliceFlag[[]string]

HostPortSliceVarP defines a string slice flag where each element must be a valid host:port pair, with the specified name, shorthand, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) HostPortVar

func (f *FlagSet) HostPortVar(ptr *string, name string, def string, usage string) *Flag[string]

HostPortVar defines a string flag that must represent a valid host:port pair, with the specified name, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) HostPortVarP

func (f *FlagSet) HostPortVarP(ptr *string, name, short string, def string, usage string) *Flag[string]

HostPortVarP defines a string flag that must represent a valid host:port pair, with the specified name, shorthand, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) IP

func (f *FlagSet) IP(name string, def net.IP, usage string) *Flag[net.IP]

IP defines a net.IP flag with the specified name, default value, and usage. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) IPMask

func (f *FlagSet) IPMask(name string, def net.IPMask, usage string) *Flag[net.IPMask]

IPMask defines a net.IPMask flag with name, default value, and usage string. The input must be in dotted decimal format (e.g., "255.255.255.0"). Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) IPMaskP

func (f *FlagSet) IPMaskP(name, short string, def net.IPMask, usage string) *Flag[net.IPMask]

IPMaskP defines a net.IPMask flag with name, shorthand, default value, and usage string. The input must be in dotted decimal format (e.g., "255.255.255.0"). Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) IPMaskSlice

func (f *FlagSet) IPMaskSlice(name string, def []net.IPMask, usage string) *SliceFlag[[]net.IPMask]

IPMaskSlice defines a []net.IPMask slice flag with name, default value, and usage string. Each element must be in dotted decimal format (e.g., "255.255.255.0"). Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) IPMaskSliceP

func (f *FlagSet) IPMaskSliceP(name, short string, def []net.IPMask, usage string) *SliceFlag[[]net.IPMask]

IPMaskSliceP defines a []net.IPMask slice flag with name, shorthand, default value, and usage string. Each element must be in dotted decimal format (e.g., "255.255.255.0"). Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) IPMaskSliceVar

func (f *FlagSet) IPMaskSliceVar(ptr *[]net.IPMask, name string, def []net.IPMask, usage string) *SliceFlag[[]net.IPMask]

IPMaskSliceVar defines a []net.IPMask slice flag with name, default value, and usage string. Each element must be in dotted decimal format (e.g., "255.255.255.0"). The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) IPMaskSliceVarP

func (f *FlagSet) IPMaskSliceVarP(ptr *[]net.IPMask, name, short string, def []net.IPMask, usage string) *SliceFlag[[]net.IPMask]

IPMaskSliceVarP defines a []net.IPMask slice flag with name, shorthand, default value, and usage string. Each element must be in dotted decimal format (e.g., "255.255.255.0"). The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) IPMaskVar

func (f *FlagSet) IPMaskVar(ptr *net.IPMask, name string, def net.IPMask, usage string) *Flag[net.IPMask]

IPMaskVar defines a net.IPMask flag with name, default value, and usage string. The input must be in dotted decimal format (e.g., "255.255.255.0"). The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) IPMaskVarP

func (f *FlagSet) IPMaskVarP(ptr *net.IPMask, name, short string, def net.IPMask, usage string) *Flag[net.IPMask]

IPMaskVarP defines a net.IPMask flag with name, shorthand, default value, and usage string. The input must be in dotted decimal format (e.g., "255.255.255.0"). The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) IPP

func (f *FlagSet) IPP(name, short string, def net.IP, usage string) *Flag[net.IP]

IPP defines a net.IP flag with the specified name, shorthand, default value, and usage. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) IPSlice

func (f *FlagSet) IPSlice(name string, def []net.IP, usage string) *SliceFlag[[]net.IP]

IPSlice defines a []net.IP slice flag with name, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) IPSliceP

func (f *FlagSet) IPSliceP(name, short string, def []net.IP, usage string) *SliceFlag[[]net.IP]

IPSliceP defines a []net.IP slice flag with name, shorthand, default value, and usage string. It returns the slice flag for chaining.

func (*FlagSet) IPSliceVar

func (f *FlagSet) IPSliceVar(ptr *[]net.IP, name string, def []net.IP, usage string) *SliceFlag[[]net.IP]

IPSliceVar defines a []net.IP slice flag with name, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) IPSliceVarP

func (f *FlagSet) IPSliceVarP(ptr *[]net.IP, name, short string, def []net.IP, usage string) *SliceFlag[[]net.IP]

IPSliceVarP defines a []net.IP slice flag with name, shorthand, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) IPVar

func (f *FlagSet) IPVar(ptr *net.IP, name string, def net.IP, usage string) *Flag[net.IP]

IPVar defines a net.IP flag with the specified name, default value, and usage. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) IPVarP

func (f *FlagSet) IPVarP(ptr *net.IP, name, short string, def net.IP, usage string) *Flag[net.IP]

IPVarP defines a net.IP flag with the specified name, shorthand, default value, and usage. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) IgnoreInvalidEnv

func (f *FlagSet) IgnoreInvalidEnv(enable bool)

IgnoreInvalidEnv skips env vars that cannot be parsed.

func (*FlagSet) Int

func (f *FlagSet) Int(name string, def int, usage string) *Flag[int]

Int defines an int flag with specified name, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) IntP

func (f *FlagSet) IntP(name, short string, def int, usage string) *Flag[int]

IntP defines an int flag with specified name, shorthand, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) IntSlice

func (f *FlagSet) IntSlice(name string, def []int, usage string) *SliceFlag[[]int]

IntSlice defines a []int slice flag with the specified name, default value, and usage. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) IntSliceP

func (f *FlagSet) IntSliceP(name, short string, def []int, usage string) *SliceFlag[[]int]

IntSliceP defines a []int slice flag with the specified name, shorthand, default value, and usage. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) IntSliceVar

func (f *FlagSet) IntSliceVar(ptr *[]int, name string, def []int, usage string) *SliceFlag[[]int]

IntSliceVar defines a []int slice flag with the specified name, default value, and usage. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) IntSliceVarP

func (f *FlagSet) IntSliceVarP(ptr *[]int, name, short string, def []int, usage string) *SliceFlag[[]int]

IntSliceVarP defines a []int slice flag with the specified name, shorthand, default value, and usage. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) IntVar

func (f *FlagSet) IntVar(ptr *int, name string, def int, usage string) *Flag[int]

IntVar defines an int flag with specified name, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) IntVarP

func (f *FlagSet) IntVarP(ptr *int, name, short string, def int, usage string) *Flag[int]

IntVarP defines an int flag with specified name, shorthand, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) ListenAddr

func (f *FlagSet) ListenAddr(name string, def *net.TCPAddr, usage string) *Flag[*net.TCPAddr]

func (*FlagSet) ListenAddrP

func (f *FlagSet) ListenAddrP(name, short string, def *net.TCPAddr, usage string) *Flag[*net.TCPAddr]

ListenAddrP defines a *net.TCPAddr flag with the specified name, shorthand, default value, and usage string. The value is parsed using net.ResolveTCPAddr with "tcp" as the network. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) ListenAddrSlice

func (f *FlagSet) ListenAddrSlice(name string, def []*net.TCPAddr, usage string) *SliceFlag[[]*net.TCPAddr]

ListenAddrSlice defines a []*net.TCPAddr slice flag without a shorthand. Each element is parsed using net.ResolveTCPAddr with "tcp" as the network. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) ListenAddrSliceP

func (f *FlagSet) ListenAddrSliceP(name, short string, def []*net.TCPAddr, usage string) *SliceFlag[[]*net.TCPAddr]

ListenAddrSliceP defines a []*net.TCPAddr slice flag with a name, shorthand, default value, and usage string. Each element is parsed using net.ResolveTCPAddr with "tcp" as the network. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) ListenAddrSliceVar

func (f *FlagSet) ListenAddrSliceVar(ptr *[]*net.TCPAddr, name string, def []*net.TCPAddr, usage string) *SliceFlag[[]*net.TCPAddr]

ListenAddrSliceVar defines a []*net.TCPAddr slice flag without a shorthand. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) ListenAddrSliceVarP

func (f *FlagSet) ListenAddrSliceVarP(ptr *[]*net.TCPAddr, name, short string, def []*net.TCPAddr, usage string) *SliceFlag[[]*net.TCPAddr]

ListenAddrSliceVarP defines a []*net.TCPAddr slice flag with a name, shorthand, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) ListenAddrVar

func (f *FlagSet) ListenAddrVar(ptr **net.TCPAddr, name string, def *net.TCPAddr, usage string) *Flag[*net.TCPAddr]

func (*FlagSet) ListenAddrVarP

func (f *FlagSet) ListenAddrVarP(ptr **net.TCPAddr, name, short string, def *net.TCPAddr, usage string) *Flag[*net.TCPAddr]

func (*FlagSet) MustGet

func (f *FlagSet) MustGet(name string) any

MustGet is like Get but panics if the flag is missing.

func (*FlagSet) Name

func (f *FlagSet) Name() string

Name returns the program name.

func (*FlagSet) Note

func (f *FlagSet) Note(s string)

Note sets optional text after usage help.

func (*FlagSet) Output

func (f *FlagSet) Output() io.Writer

Output returns the writer for usage and error output.

func (*FlagSet) Parse

func (f *FlagSet) Parse(args []string) error

Parse parses CLI arguments, env vars, built-in help/version, and validations.

func (*FlagSet) PrintDefaults

func (f *FlagSet) PrintDefaults()

PrintDefaults prints the detailed help for all flags.

func (*FlagSet) PrintDescription

func (f *FlagSet) PrintDescription(w io.Writer, width int)

PrintDescription prints prolog text above the flags.

func (*FlagSet) PrintNotes

func (f *FlagSet) PrintNotes(w io.Writer, width int)

PrintNotes prints epilog text below the usage block.

func (*FlagSet) PrintTitle

func (f *FlagSet) PrintTitle(w io.Writer)

PrintTitle prints the configured title above the usage.

func (*FlagSet) PrintUsage

func (f *FlagSet) PrintUsage(w io.Writer, mode FlagPrintMode)

PrintUsage prints the one-line usage header based on mode.

func (*FlagSet) RequirePositional

func (f *FlagSet) RequirePositional(n int)

RequirePositional sets the number of required positional args.

func (*FlagSet) SchemaHostPort

func (f *FlagSet) SchemaHostPort(name, def string, usage string) *Flag[string]

SchemaHostPort defines a string flag that must match scheme://host:port format, with the specified name, shorthand, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) SchemaHostPortP

func (f *FlagSet) SchemaHostPortP(name, short, def string, usage string) *Flag[string]

SchemaHostPortP defines a string flag that must match scheme://host:port format, with a shorthand, default value, and usage string. The value is parsed with url.Parse and must include a scheme and host. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) SchemaHostPortSlice

func (f *FlagSet) SchemaHostPortSlice(name string, def []string, usage string) *SliceFlag[[]string]

SchemaHostPortSlice defines a string slice flag that must represent a valid schema://host:port pair, with the specified name, shorthand, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) SchemaHostPortSliceP

func (f *FlagSet) SchemaHostPortSliceP(name, short string, def []string, usage string) *SliceFlag[[]string]

SchemaHostPortSliceP defines a string flag that must represent a valid schema://host:port pair, with the specified name, shorthand, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) SchemaHostPortSliceVar

func (f *FlagSet) SchemaHostPortSliceVar(ptr *[]string, name string, def []string, usage string) *SliceFlag[[]string]

SchemaHostPortSliceVar defines a string flag that must represent a valid schema://host:port pair, with the specified name, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value

func (*FlagSet) SchemaHostPortSliceVarP

func (f *FlagSet) SchemaHostPortSliceVarP(ptr *[]string, name, short string, def []string, usage string) *SliceFlag[[]string]

SchemaHostPortSliceVarP defines a string flag that must represent a valid schema://host:port pair, with the specified name, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value

func (*FlagSet) SchemaHostPortVar

func (f *FlagSet) SchemaHostPortVar(ptr *string, name string, def string, usage string) *Flag[string]

SchemaHostPortVar defines a string flag that must match scheme://host:port format, with the specified name, shorthand, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) SchemaHostPortVarP

func (f *FlagSet) SchemaHostPortVarP(ptr *string, name, short string, def string, usage string) *Flag[string]

SchemaHostPortVarP defines a string flag that must match scheme://host:port format, with the specified name, shorthand, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) SetGetEnvFn

func (f *FlagSet) SetGetEnvFn(fn func(string) string)

SetGetEnvFn overrides the env lookup function.

func (*FlagSet) SetOutput

func (f *FlagSet) SetOutput(w io.Writer)

SetOutput sets the writer for help and usage messages.

func (*FlagSet) Sorted

func (f *FlagSet) Sorted(enable bool)

Sorted enables or disables sorting of flag help output.

func (*FlagSet) String

func (f *FlagSet) String(name string, def string, usage string) *Flag[string]

String defines a string flag with the specified name, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) StringP

func (f *FlagSet) StringP(name, short string, def string, usage string) *Flag[string]

StringP defines a string flag with the specified name, shorthand, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) StringSlice

func (f *FlagSet) StringSlice(name string, def []string, usage string) *SliceFlag[[]string]

StringSlice defines a string slice flag with the specified name, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) StringSliceP

func (f *FlagSet) StringSliceP(name, short string, def []string, usage string) *SliceFlag[[]string]

StringSliceP defines a string slice flag with the specified name, shorthand, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) StringSliceVar

func (f *FlagSet) StringSliceVar(ptr *[]string, name string, def []string, usage string) *SliceFlag[[]string]

StringSlice defines a string slice flag with the specified name, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) StringSliceVarP

func (f *FlagSet) StringSliceVarP(ptr *[]string, name, short string, def []string, usage string) *SliceFlag[[]string]

StringSliceP defines a string flag with the specified name, shorthand, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) StringVar

func (f *FlagSet) StringVar(ptr *string, name string, def string, usage string) *Flag[string]

StringVar defines a string flag with the specified name, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) StringVarP

func (f *FlagSet) StringVarP(ptr *string, name, short string, def string, usage string) *Flag[string]

StringVarP defines a string flag with the specified name, shorthand, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) Title

func (f *FlagSet) Title(s string)

Title sets the optional title for usage output.

func (*FlagSet) URL

func (f *FlagSet) URL(name string, def *url.URL, usage string) *Flag[*url.URL]

URL defines a *url.URL flag with the specified name, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) URLP

func (f *FlagSet) URLP(name, short string, def *url.URL, usage string) *Flag[*url.URL]

URLP defines a *url.URL flag with the specified name, shorthand, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) URLSlice

func (f *FlagSet) URLSlice(name string, def []*url.URL, usage string) *SliceFlag[[]*url.URL]

URLSlice defines a *url.URL slice flag with the specified name, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) URLSliceP

func (f *FlagSet) URLSliceP(name, short string, def []*url.URL, usage string) *SliceFlag[[]*url.URL]

URLSliceP defines a *url.URL slice flag with the specified name, shorthand, default value, and usage string. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) URLSliceVar

func (f *FlagSet) URLSliceVar(ptr *[]*url.URL, name string, def []*url.URL, usage string) *SliceFlag[[]*url.URL]

URLSlice defines a *url.URL slice flag with the specified name, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) URLSliceVarP

func (f *FlagSet) URLSliceVarP(ptr *[]*url.URL, name, short string, def []*url.URL, usage string) *SliceFlag[[]*url.URL]

URLSliceP defines a *url.URL flag with the specified name, shorthand, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) URLVar

func (f *FlagSet) URLVar(ptr **url.URL, name string, def *url.URL, usage string) *Flag[*url.URL]

URLVar defines a *url.URL flag with the specified name, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) URLVarP

func (f *FlagSet) URLVarP(ptr **url.URL, name, short string, def *url.URL, usage string) *Flag[*url.URL]

URLVarP defines a *url.URL flag with the specified name, shorthand, default value, and usage string. The parsed value is stored in the provided pointer. Returns the flag for chaining. Retrieve the parsed value with .Value().

func (*FlagSet) UsagePrintMode

func (f *FlagSet) UsagePrintMode(mode FlagPrintMode)

UsagePrintMode sets the mode for printing usage.

func (*FlagSet) Version

func (f *FlagSet) Version(s string)

Version enables the version flag with the given string.

type HasDelimiter

type HasDelimiter interface {
	SetDelimiter(string) // Updates the delimiter used during Set()
}

HasDelimiter is implemented by slice flag types that allow custom delimiters for splitting input strings into elements.

type HelpRequested

type HelpRequested struct {
	Message string // The full help message to show the user
}

HelpRequested is returned when the built-in help flag (-h or --help) is triggered.

func (*HelpRequested) Error

func (e *HelpRequested) Error() string

Error returns the help message, satisfying the error interface.

type SliceFlag

type SliceFlag[T any] struct {
	Flag[T] // Inherits all scalar flag methods
}

SliceFlag is a specialized builder for slice-type flags. It embeds FlagBuilder and provides an additional Delimiter method to control how multiple values are split from a single argument.

func (*SliceFlag[T]) Delimiter

func (b *SliceFlag[T]) Delimiter(sep string) *SliceFlag[T]

Delimiter sets the separator for slice values (e.g., "," or ":").

type SliceFlagItem

type SliceFlagItem[T any] struct {
	// contains filtered or unexported fields
}

SliceFlagItem is a generic flag value holder for slice types. It implements the Value interface for flags that accept multiple values, optionally split by a custom delimiter.

func NewSliceItem

func NewSliceItem[T any](
	ptr *[]T,
	def []T,
	parse func(string) (T, error),
	format func(T) string,
	delimiter string,
) *SliceFlagItem[T]

NewSliceItem constructs a new BaseSliceValue. The default value is defensively copied into the target pointer.

func (*SliceFlagItem[T]) Default

func (v *SliceFlagItem[T]) Default() string

Default returns the default slice as a single string, joined by the delimiter.

func (*SliceFlagItem[T]) Get

func (v *SliceFlagItem[T]) Get() any

Get returns the current slice value.

func (*SliceFlagItem[T]) IsChanged

func (v *SliceFlagItem[T]) IsChanged() bool

IsChanged reports whether the slice value was explicitly set.

func (*SliceFlagItem[T]) Set

func (v *SliceFlagItem[T]) Set(s string) error

Set splits the input string by the delimiter and parses each item.

func (*SliceFlagItem[T]) SetDelimiter

func (v *SliceFlagItem[T]) SetDelimiter(d string)

SetDelimiter sets the delimiter used for splitting input strings into slice elements.

func (*SliceFlagItem[T]) SetValidator

func (v *SliceFlagItem[T]) SetValidator(fn func(T) bool, allowed []T)

SetValidator sets a validation callback for this flag.

type SliceMarker

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

SliceMarker is a marker interface for slice-type flags. It is used internally to distinguish scalar vs. slice values.

type StrictBool

type StrictBool interface {
	IsStrictBool() bool
}

StrictBool is an optional interface implemented by flags that can be used without an explicit value (e.g. --verbose sets to true).

type Value

type Value interface {
	Set(string) error // Parses and sets the value from a string input
	Get() any         // Returns the current value as interface{}
	Default() string  // Returns the default value as a string
	IsChanged() bool  // Reports whether the flag value was explicitly set
}

Value is the interface implemented by all flag value types. It provides a way to parse and retrieve values from strings.

type VersionRequested

type VersionRequested struct {
	Version string // The version string to show the user
}

VersionRequested is returned when the built-in version flag (--version) is triggered.

func (*VersionRequested) Error

func (e *VersionRequested) Error() string

Error returns the version string, satisfying the error interface.

Directories

Path Synopsis
examples
advanced command
simple command

Jump to

Keyboard shortcuts

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