tinyflags

package module
v0.0.24 Latest Latest
Warning

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

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

README

tinyflags

Go Reference

A minimal, fast, and extensible CLI flag-parsing library for Go. Zero dependencies. Full generics support. Rich usage output.

Features

  • Short & long flags (-d, --debug)
  • Boolean strict mode (--flag=true/false, --no-flag)
  • Environment variable overrides (EnvPrefix, per-flag opt-out)
  • Required, deprecated, and grouped flags
  • Slice flags ([]T) with custom delimiters
  • Allowed choices & validation
  • Mutual-exclusion groups
  • Custom placeholders & help sections
  • Dynamic flags (--group.id.field=value)
  • Typed values (*os.File, *net.TCPAddr, url.URL, time.Duration, etc.)

Install

go get github.com/containeroo/tinyflags

Quickstart

package main

import (
	"fmt"
	"os"
	"github.com/containeroo/tinyflags"
)

func main() {
	fs := tinyflags.NewFlagSet("app", tinyflags.ExitOnError)
	fs.EnvPrefix("MYAPP")
	fs.Version("v1.2.3")

	host := fs.String("host", "localhost", "Server hostname").Required().Value()
	port := fs.Int("port", 8080, "Port to bind").Short("p").Value()
	debug := fs.Bool("debug", false, "Enable debug logging").Short("d").Value()
	tags  := fs.StringSlice("tag", nil, "Optional tags").Value()

	if err := fs.Parse(os.Args[1:]); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

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

Environment Variables

MYAPP_HOST=example.com MYAPP_PORT=9090 ./app --debug

You can disable env binding per-flag:

fs.Bool("internal", false, "internal use only").DisableEnv()

Dynamic Flags

package main

import (
	"fmt"
	"os"
	"github.com/containeroo/tinyflags"
)

func main() {
	fs := tinyflags.NewFlagSet("app", tinyflags.ExitOnError)
	http := fs.DynamicGroup("http")

	port    := http.Int("port", "Backend port")
	timeout := http.Duration("timeout", "Request timeout")

	if err := fs.Parse(os.Args[1:]); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

	for _, id := range http.Instances() {
		p, _ := port.Get(id)
		t, _ := timeout.Get(id)
		fmt.Printf("%s: port=%d, timeout=%s\n", id, p, t)
	}
}
./app --http.a.port=8080 --http.a.timeout=30s \
      --http.b.port=9090 --http.b.timeout=1m
a: port=8080, timeout=30s
b: port=9090, timeout=1m

Help Output

Usage: app [flags]

Flags:
  --host HOST         Server hostname (Default: localhost) (Env: MYAPP_HOST) (Required)
  -p, --port PORT     Port to bind (Default: 8080) (Env: MYAPP_PORT)
  -d, --debug         Enable debug logging (Env: MYAPP_DEBUG)
      --tag TAG...    Optional tags
  -v, --version       Show version

Supported Types

Type Methods
bool Bool, BoolVar
int Int, IntVar
string String, StringVar
[]string StringSlice, StringSliceVar
counter Counter, CounterVar (auto-increment)
time.Duration Duration, DurationVar
net.IP IP, IPVar
[]net.IP IPSlice, IPSliceVar
*net.TCPAddr TCPAddr, TCPAddrVar
url.URL URL, URLVar
*os.File File, FileVar

Slice flags accept repeated use or custom-delimited strings.

FlagSet API

Core Methods
Method Description
NewFlagSet(name, mode) Create new flag set
Parse(args) Parse CLI args + env
Usage func() Custom usage handler
Version(s) Set --version string
DisableHelp() Disable --help
DisableVersion() Disable --version
Help & Output
Method Description
SetOutput(io.Writer) Set help output writer
Output() Get current output writer
Title(s) Set usage title
Authors(s) Set author section
Description(s) Set help description
Note(s) Set help footer
PrintUsage(w, mode) Print Usage: line
PrintTitle(w) Print title header
PrintAuthors(w) Print authors
PrintDescription(w, indent, width) Print description block
PrintNotes(w, indent, width) Print footer block
PrintStaticDefaults(w, indent, startCol, width) Static flag help
PrintDynamicDefaults(w, indent, startCol, width) Dynamic flag help
Help Formatting
Method Description
SetDescIndent(n) Indent description lines
SetDescWidth(n) Max description width
SetNoteIndent(n) Indent for footer
SetNoteWidth(n) Width for footer
SetUsageIndent(n) Left padding for all flags
SetUsageColumn(n) Column where description starts
SetUsageWidth(n) Max flag help line width
StaticAutoUsageColumn(pad) Auto-calculate static col
DynamicAutoUsageColumn(pad) Auto-calculate dynamic col
Environment
Method Description
EnvPrefix(s) Prefix for all env vars
IgnoreInvalidEnv(true) Skip unknown envs
SetGetEnvFn(fn) Custom os.Getenv
Globaldelimiter(s) Slice delimiter (default: ",")
DefaultDelimiter() Get current delimiter
Positional & Groups
Method Description
RequirePositional(n) Require at least N args
Args() Get all args
Arg(i) Get i-th arg
GetGroup(name) Create or get mutex group
Groups() List all groups
AttachToGroup(flag, name) Assign flag to group
Dynamic Flags
Method Description
DynamicGroup(name) Define a dynamic flag group
DynamicGroups() Get all registered groups

Also exposed:

GetDynamic[T any](group, id, flag string) (T, error)
MustGetDynamic[T any](group, id, flag string) T
GetOrDefaultDynamic[T any](group, id, flag string) T

License

Apache 2.0 — see LICENSE

Documentation

Overview

Package tinyflags provides a high-level API for defining and parsing CLI flags with support for dynamic groups, custom types, and rich usage output.

Index

Constants

View Source
const (
	ContinueOnError = engine.ContinueOnError // Continue and return error
	ExitOnError     = engine.ExitOnError     // Exit with error message
	PanicOnError    = engine.PanicOnError    // Panic on error
)
View Source
const (
	PrintNone  = engine.PrintNone  // Omits usage line entirely
	PrintFlags = engine.PrintFlags // Prints: [flags]
	PrintShort = engine.PrintShort // Prints: -v
	PrintLong  = engine.PrintLong  // Prints: --verbose
	PrintBoth  = engine.PrintBoth  // Prints: -v|--verbose
)

Variables

View Source
var (
	IsHelpRequested    = engine.IsHelpRequested
	IsVersionRequested = engine.IsVersionRequested
	RequestHelp        = engine.RequestHelp
	RequestVersion     = engine.RequestVersion
)

Functions

func GetDynamic added in v0.0.10

func GetDynamic[T any](group *dynamic.Group, id, flag string) (T, error)

GetDynamic retrieves the value for a dynamic flag by group, id, and field name.

func GetOrDefaultDynamic added in v0.0.14

func GetOrDefaultDynamic[T any](group *dynamic.Group, id, flag string) T

GetOrDefaultDynamic returns the value for a dynamic flag or its default.

func MustGetDynamic added in v0.0.10

func MustGetDynamic[T any](group *dynamic.Group, id, flag string) T

MustGetDynamic retrieves the value for a dynamic flag or panics.

Types

type DynamicGroup added in v0.0.23

type DynamicGroup = dynamic.Group // For accessing .Instances(), .Flags(), .NoteText(), etc.

type ErrorHandling

type ErrorHandling = engine.ErrorHandling

ErrorHandling defines how parsing errors are handled.

type FlagPrintMode

type FlagPrintMode = engine.FlagPrintMode

FlagPrintMode controls how the usage line is rendered.

type FlagSet

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

FlagSet is the user-facing flag parser and usage configurator.

func NewFlagSet

func NewFlagSet(name string, handling ErrorHandling) *FlagSet

NewFlagSet creates a new flag set with the given name and error handling mode.

func (*FlagSet) Arg

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

Arg returns the i-th positional argument and whether it exists.

func (*FlagSet) Args

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

Args returns all leftover positional arguments.

func (*FlagSet) AttachToGroup added in v0.0.19

func (f *FlagSet) AttachToGroup(flag *core.BaseFlag, group string)

AttachToGroup attaches a static flag to a mutual exclusion group.

func (*FlagSet) Authors added in v0.0.8

func (f *FlagSet) Authors(s string)

Authors sets the list of authors printed in help output.

func (*FlagSet) Bool

func (f *FlagSet) Bool(name string, def bool, usage string) *scalar.BoolFlag

Bool defines a bool flag. If Strict() is enabled, it must be set explicitly (--flag=true/false).

func (*FlagSet) BoolVar

func (f *FlagSet) BoolVar(ptr *bool, name, short string, def bool, usage string) *scalar.BoolFlag

BoolVar defines a bool flag and binds it to the given pointer. If Strict() is enabled, it must be set explicitly (--flag=true/false).

func (*FlagSet) Bytes added in v0.0.8

func (f *FlagSet) Bytes(name string, def uint64, usage string) *scalar.ScalarFlag[uint64]

Bytes defines a uint64 flag that parses sizes (e.g., "10MB") and returns its handle.

func (*FlagSet) BytesSlice added in v0.0.8

func (f *FlagSet) BytesSlice(name string, def []uint64, usage string) *slice.SliceFlag[uint64]

BytesSlice defines a []uint64 “bytes” flag and returns its handle.

func (*FlagSet) BytesSliceVar added in v0.0.8

func (f *FlagSet) BytesSliceVar(ptr *[]uint64, name string, def []uint64, usage string) *slice.SliceFlag[uint64]

BytesSliceVar defines a []uint64 flag that parses human-readable sizes and binds it to the given pointer.

func (*FlagSet) BytesVar added in v0.0.8

func (f *FlagSet) BytesVar(ptr *uint64, name string, def uint64, usage string) *scalar.ScalarFlag[uint64]

BytesVar defines a uint64 flag with byte parsing and binds it to the given pointer.

func (*FlagSet) Counter added in v0.0.8

func (f *FlagSet) Counter(name string, def int, usage string) *scalar.CounterFlag

Counter defines a counter flag that increments with each occurrence.

func (*FlagSet) CounterVar added in v0.0.8

func (f *FlagSet) CounterVar(ptr *int, name string, def int, usage string) *scalar.CounterFlag

CounterVar defines a counter flag and binds it to the given pointer.

func (*FlagSet) DefaultDelimiter added in v0.0.8

func (f *FlagSet) DefaultDelimiter() string

DefaultDelimiter returns the delimiter used for slice flags.

func (*FlagSet) DescIndent added in v0.0.23

func (f *FlagSet) DescIndent() int

DescIndent returns the left indent for the description block.

func (*FlagSet) DescWidth added in v0.0.23

func (f *FlagSet) DescWidth() int

DescWidth returns the maximum line width for the description.

func (*FlagSet) Description

func (f *FlagSet) Description(s string)

Description sets the top description section of the help output.

func (*FlagSet) DisableHelp

func (f *FlagSet) DisableHelp()

DisableHelp disables the automatic --help flag.

func (*FlagSet) DisableVersion

func (f *FlagSet) DisableVersion()

DisableVersion disables the automatic --version flag.

func (*FlagSet) Duration

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

Duration defines a time.Duration flag and returns its handle.

func (*FlagSet) DurationSlice

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

DurationSlice defines a []time.Duration flag and returns its handle.

func (*FlagSet) DurationSliceVar

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

DurationSliceVar defines a []time.Duration flag and binds it to the given pointer.

func (*FlagSet) DurationVar

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

DurationVar defines a time.Duration flag and binds it to the given pointer.

func (*FlagSet) DynamicAutoUsageColumn added in v0.0.23

func (f *FlagSet) DynamicAutoUsageColumn(padding int) int

DynamicAutoUsageColumn calculates the recommended usage column for dynamic flags.

func (*FlagSet) DynamicGroup added in v0.0.8

func (f *FlagSet) DynamicGroup(name string) *dynamic.Group

DynamicGroup registers or retrieves a dynamic group by name.

func (*FlagSet) DynamicGroups added in v0.0.9

func (f *FlagSet) DynamicGroups() []*dynamic.Group

DynamicGroups returns all dynamic groups in registration order.

func (*FlagSet) DynamicUsageNote added in v0.0.23

func (f *FlagSet) DynamicUsageNote() string

DynamicUsageNote returns the dynamic usage note text.

func (*FlagSet) EnvPrefix

func (f *FlagSet) EnvPrefix(s string)

EnvPrefix sets a prefix for all environment variables.

func (*FlagSet) File

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

File defines an *os.File flag and returns its handle.

func (*FlagSet) FileSlice

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

FileSlice defines a []*os.File flag and returns its handle.

func (*FlagSet) FileSliceVar

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

FileSliceVar defines a []*os.File flag and binds it to the given pointer.

func (*FlagSet) FileVar

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

FileVar defines an *os.File flag and binds it to the given pointer.

func (*FlagSet) Float32

func (f *FlagSet) Float32(name string, def float32, usage string) *scalar.ScalarFlag[float32]

Float32 defines a float32 flag and returns its handle.

func (*FlagSet) Float32Slice

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

Float32Slice defines a []float32 flag and returns its handle.

func (*FlagSet) Float32SliceVar

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

Float32SliceVar defines a []float32 flag and binds it to the given pointer.

func (*FlagSet) Float32Var

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

Float32Var defines a float32 flag and binds it to the given pointer.

func (*FlagSet) Float64

func (f *FlagSet) Float64(name string, def float64, usage string) *scalar.ScalarFlag[float64]

Float64 defines a float64 flag and returns its handle.

func (*FlagSet) Float64Slice

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

Float64Slice defines a []float64 flag and returns its handle.

func (*FlagSet) Float64SliceVar

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

Float64SliceVar defines a []float64 flag and binds it to the given pointer.

func (*FlagSet) Float64Var

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

Float64Var defines a float64 flag and binds it to the given pointer.

func (*FlagSet) GetGroup added in v0.0.8

func (f *FlagSet) GetGroup(name string) *core.MutualGroup

GetGroup retrieves or creates a named mutual exclusion group.

func (*FlagSet) Globaldelimiter

func (f *FlagSet) Globaldelimiter(s string)

Globaldelimiter sets the delimiter used for all slice flags.

func (*FlagSet) Groups added in v0.0.8

func (f *FlagSet) Groups() []*core.MutualGroup

Groups returns all registered mutual exclusion groups.

func (*FlagSet) HideEnvs added in v0.0.23

func (f *FlagSet) HideEnvs()

HideEnvs hides all environment variable info in help output.

func (*FlagSet) IP

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

IP defines a net.IP flag and returns its handle.

func (*FlagSet) IPMask

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

IPMask defines a net.IPMask flag and returns its handle.

func (*FlagSet) IPMaskSlice

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

IPMaskSlice defines a []net.IPMask flag and returns its handle.

func (*FlagSet) IPMaskSliceVar

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

IPMaskSliceVar defines a []net.IPMask flag and binds it to the given pointer.

func (*FlagSet) IPSlice

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

IPSlice defines a []net.IP flag and returns its handle.

func (*FlagSet) IPSliceVar

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

IPSliceVar defines a []net.IP flag and binds it to the given pointer.

func (*FlagSet) IPVar

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

IPVar defines a net.IP flag and binds it to the given pointer.

func (*FlagSet) IPv4MaskVar added in v0.0.8

func (f *FlagSet) IPv4MaskVar(ptr *net.IPMask, name string, def net.IPMask, usage string) *scalar.ScalarFlag[net.IPMask]

IPv4MaskVar defines a net.IPMask flag and binds it to the given pointer.

func (*FlagSet) IgnoreInvalidEnv

func (f *FlagSet) IgnoreInvalidEnv(b bool)

IgnoreInvalidEnv disables errors for unrecognized environment values.

func (*FlagSet) Int

func (f *FlagSet) Int(name string, def int, usage string) *scalar.ScalarFlag[int]

Int defines an int flag and returns its handle.

func (*FlagSet) IntSlice

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

IntSlice defines a []int flag and returns its handle.

func (*FlagSet) IntSliceVar

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

IntSliceVar defines a []int flag and binds it to the given pointer.

func (*FlagSet) IntVar

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

IntVar defines an int flag and binds it to the given pointer.

func (*FlagSet) LookupFlag added in v0.0.19

func (f *FlagSet) LookupFlag(name string) *core.BaseFlag

LookupFlag retrieves a static flag by name.

func (*FlagSet) Name

func (f *FlagSet) Name() string

Name returns the flag set's name.

func (*FlagSet) Note

func (f *FlagSet) Note(s string)

Note sets the bottom note section of the help output.

func (*FlagSet) NoteIndent added in v0.0.23

func (f *FlagSet) NoteIndent() int

NoteIndent returns the left indent for the note block.

func (*FlagSet) NoteWidth added in v0.0.23

func (f *FlagSet) NoteWidth() int

NoteWidth returns the maximum width for the note block.

func (*FlagSet) Output

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

Output returns the current output writer.

func (*FlagSet) Parse

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

Parse processes the given CLI args and populates all registered flags.

func (*FlagSet) PrintAuthors added in v0.0.8

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

PrintAuthors renders the author line if set.

func (*FlagSet) PrintDescription

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

PrintDescription renders the full description block.

func (*FlagSet) PrintDynamicDefaults added in v0.0.23

func (f *FlagSet) PrintDynamicDefaults(w io.Writer, indent, col, width int)

PrintDynamicDefaults renders all dynamic flag usage lines.

func (*FlagSet) PrintNotes

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

PrintNotes renders the notes section, if configured.

func (*FlagSet) PrintStaticDefaults added in v0.0.23

func (f *FlagSet) PrintStaticDefaults(w io.Writer, indent, col, width int)

PrintStaticDefaults renders all static flag usage lines.

func (*FlagSet) PrintTitle

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

PrintTitle renders the title above all help content.

func (*FlagSet) PrintUsage

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

PrintUsage renders the top usage line.

func (*FlagSet) RequirePositional

func (f *FlagSet) RequirePositional(n int)

RequirePositional sets how many positional arguments must be present.

func (*FlagSet) SetDescIndent added in v0.0.23

func (f *FlagSet) SetDescIndent(n int)

SetDescIndent sets the left indent for the description block.

func (*FlagSet) SetDescWidth added in v0.0.23

func (f *FlagSet) SetDescWidth(n int)

SetDescWidth sets the maximum line width for the description.

func (*FlagSet) SetDynamicUsageNote added in v0.0.23

func (f *FlagSet) SetDynamicUsageNote(s string)

SetDynamicUsageNote sets an optional note for the dynamic usage section.

func (*FlagSet) SetGetEnvFn

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

SetGetEnvFn overrides the function used to look up environment variables.

func (*FlagSet) SetNoteIndent added in v0.0.23

func (f *FlagSet) SetNoteIndent(n int)

SetNoteIndent sets the left indent for the note block.

func (*FlagSet) SetNoteWidth added in v0.0.23

func (f *FlagSet) SetNoteWidth(n int)

SetNoteWidth sets the maximum width for the note block.

func (*FlagSet) SetOutput

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

SetOutput changes the destination writer for usage and error messages.

func (*FlagSet) SetStaticUsageNote added in v0.0.23

func (f *FlagSet) SetStaticUsageNote(s string)

SetStaticUsageNote sets an optional note for the static usage section.

func (*FlagSet) SetUsageColumn added in v0.0.23

func (f *FlagSet) SetUsageColumn(col int)

SetUsageColumn sets the column where descriptions start.

func (*FlagSet) SetUsageIndent added in v0.0.23

func (f *FlagSet) SetUsageIndent(n int)

SetUsageIndent sets the left indent for usage lines.

func (*FlagSet) SetUsageWidth added in v0.0.23

func (f *FlagSet) SetUsageWidth(n int)

SetUsageWidth sets the maximum line width for usage output.

func (*FlagSet) SortedFlags added in v0.0.20

func (f *FlagSet) SortedFlags()

SortedFlags enables sorted help output for static flags.

func (*FlagSet) SortedGroups added in v0.0.20

func (f *FlagSet) SortedGroups()

SortedGroups enables sorted help output for dynamic groups.

func (*FlagSet) StaticAutoUsageColumn added in v0.0.23

func (f *FlagSet) StaticAutoUsageColumn(padding int) int

StaticAutoUsageColumn calculates the recommended usage column for static flags.

func (*FlagSet) StaticUsageNote added in v0.0.23

func (f *FlagSet) StaticUsageNote() string

StaticUsageNote returns the static usage note text.

func (*FlagSet) String

func (f *FlagSet) String(name string, def string, usage string) *scalar.ScalarFlag[string]

String defines a string flag and returns its handle.

func (*FlagSet) StringSlice

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

StringSlice defines a []string flag and returns its handle.

func (*FlagSet) StringSliceVar

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

StringSliceVar defines a []string flag and binds it to the given pointer.

func (*FlagSet) StringVar

func (f *FlagSet) StringVar(ptr *string, name string, def string, usage string) *scalar.ScalarFlag[string]

StringVar defines a string flag and binds it to the given pointer.

func (*FlagSet) TCPAddr added in v0.0.8

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

TCPAddr defines a *net.TCPAddr flag and returns its handle.

func (*FlagSet) TCPAddrSlice added in v0.0.8

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

TCPAddrSlice defines a []*net.TCPAddr flag and returns its handle.

func (*FlagSet) TCPAddrSliceVar added in v0.0.8

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

TCPAddrSliceVar defines a []*net.TCPAddr flag and binds it to the given pointer.

func (*FlagSet) TCPAddrVar added in v0.0.8

func (f *FlagSet) TCPAddrVar(ptr **net.TCPAddr, name string, def *net.TCPAddr, usage string) *scalar.ScalarFlag[*net.TCPAddr]

TCPAddrVar defines a *net.TCPAddr flag and binds it to the given pointer.

func (*FlagSet) Time added in v0.0.8

func (f *FlagSet) Time(name string, def time.Time, usage string) *scalar.ScalarFlag[time.Time]

Time defines a time.Time flag and returns its handle.

func (*FlagSet) TimeSlice added in v0.0.8

func (f *FlagSet) TimeSlice(name string, def []time.Time, usage string) *slice.SliceFlag[time.Time]

TimeSlice defines a []time.Time flag and returns its handle.

func (*FlagSet) TimeSliceVar added in v0.0.8

func (f *FlagSet) TimeSliceVar(ptr *[]time.Time, name string, def []time.Time, usage string) *slice.SliceFlag[time.Time]

TimeSliceVar defines a []time.Time flag and binds it to the given pointer.

func (*FlagSet) TimeVar added in v0.0.8

func (f *FlagSet) TimeVar(ptr *time.Time, name string, def time.Time, usage string) *scalar.ScalarFlag[time.Time]

TimeVar defines a time.Time flag and binds it to the given pointer.

func (*FlagSet) Title

func (f *FlagSet) Title(s string)

Title sets the main title shown in usage output.

func (*FlagSet) URL

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

URL defines a *url.URL flag and returns its handle.

func (*FlagSet) URLSlice

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

URLSlice defines a []*url.URL flag and returns its handle.

func (*FlagSet) URLSliceVar

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

URLSliceVar defines a []*url.URL flag and binds it to the given pointer.

func (*FlagSet) URLVar

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

URLVar defines a *url.URL flag and binds it to the given pointer.

func (*FlagSet) UsageColumn added in v0.0.23

func (f *FlagSet) UsageColumn() int

UsageColumn returns the column where descriptions start.

func (*FlagSet) UsageIndent added in v0.0.23

func (f *FlagSet) UsageIndent() int

UsageIndent returns the left indent for usage lines.

func (*FlagSet) UsageWidth added in v0.0.23

func (f *FlagSet) UsageWidth() int

UsageWidth returns the maximum line width for usage output.

func (*FlagSet) Version

func (f *FlagSet) Version(s string)

Version sets the --version string.

type HelpRequested

type HelpRequested = engine.HelpRequested

Common user-triggered exit conditions.

type StaticFlag added in v0.0.23

type StaticFlag = core.BaseFlag // For help renderers, custom GUIs, etc.)

type VersionRequested

type VersionRequested = engine.VersionRequested

Common user-triggered exit conditions.

Directories

Path Synopsis
examples
advanced command
dynamic command
simple command
internal
dynamic
Package dynamic implements dynamic flag types that support multiple per-identifier values (e.g.
Package dynamic implements dynamic flag types that support multiple per-identifier values (e.g.

Jump to

Keyboard shortcuts

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