cli

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2023 License: Apache-2.0 Imports: 13 Imported by: 8

README

cli

godoc coverage

A novel experience for building application entrypoint.

Features

  • POSIX & GNU style flag parsing, typed and customizable. (flag*.go)
  • Commands and sub-commands, nothing hidden. (cmd*.go)
  • Shell completions made straightforward. (comp*.go, scripts/*)
    • Use CompCmdShells to provide shell completion support for bash, zsh and pwsh (powershell).
  • From mostly static to highly dynamic, choices available for zero-allocation* and productivity preferences.
    • Choose ReflectIndexer for productivity, choose FuncIndexer for zero-allocation. (see Core Concepts and module document)
  • Solid & decoupled utilities comes with sane abstractions. (vp*.go, rules*.go)
    • VP implementations for both concrete types and reflection types.

*zero-allocation can be achieved by adding proper buffering in ParseOptions and CmdOptions.

Examples

see package examples

Known Limitations

  1. Flags having implicit value cannot be followed by value prefixed with hyphen (-) if the flag accepts that value (e.g. --IntSum -1). To workaround, choose any of following methods:

    • (Method 1) use = to assign flag value explicitly (e.g. --IntSum=-1)
    • (Method 2) set ParseOptions.HandleParseError to handle error of type *ErrAmbiguousArgs.
  2. Limitations to standalone dash (--)

    • Cannot be a flag value (e.g. given --sep --, then --sep gets nothing). To wrokaround, use = to assign dash value (e.g. --sep=--)
    • Can never be a positional arg. To workaround, check if dashArgs == nil is true, and if it is ture, then there is no standalone dash.
    • Due to limitations mentioned above, you cannot use a hyphen (-) as a flag shorthand.

Core Concepts

  • A FlagFinder implementation is capable of searching flags known to it by flag name or shorthand, so it represents a set of flags.
  • FlagIndexer extends the ability of FlagFinder with iteration support (FlagIter).
    • MapIndexer: register flags just like old days. (see Motivation)
    • FuncIndexer: provide ad-hoc flag indexing logic.
    • LevelIndexer: build flag hierarchies.
    • ReflectIndexer: lazily produce flags on request.
    • MultiIndexer: collect indexers as one.
    • ... or implement your own FlagIndexer/FlagFinder for you own use cases.
  • A root command is the receiver of a (*Cmd).Exec(...) function call.
  • A Route is a collection of all *Cmds from the root command to the target command.

Terminology

Illustration without sub-commands:

                        dash
                          |
      posArg  flag name   |
         |        |       |
$ ./foo xxx -i --join bar -- other args
            |          |    [ all args after the dash are dashArgs]
            |          |
            |      flag value
            |
 flag shorthand, with implicit value
  • args: all strings provided to a cmd.
    • For a root command in real world, it usually is os.Args[1:]
  • flags: before the first dash, strings interpreted as flag names and flag values.
    • flag (long) name: a string consists of more than one unicode characters.
    • flag shorthand: a string consists of exactly one unicode character and not a hyphen (-).
  • subcmds (sub-commands): before the first dash, ignore flag names and their values, consecutive args matching a serial of Cmd.Pattern.
    • In the above illustration, if there is a Cmd in root command's Children whose .Pattern is xxx, then the posArg xxx becomes subcmd xxx.
  • posArgs (positional args): before the first dash, strings that are not flags and subcmds.
  • dashArgs: all strings after the first dash.

Motivation

Most existing command-line libraies forces you to register your flags to some central registries to get things going, these registrations happen at runtime and often involves dynamic memory allocation, even the often highly praised Rust crate clap works this way, but under the guise of procedural macros.

While we acknowledge the fact flag registration works fine in most cases, it is obvious to us that larger applications with a fair amount of sub-commands and flags often suffer from such method due to the central builder forcing the application to write a lot of boilerplate code just to work around its own workflow and restrictions, and we definitely want something more flexible.

Hint: You may obtain (almost) the same experience of traditional flag registration from this module by using MapIndexer and predefined flag types.

The Bigger Picture - an alternative std

We are building a no-GC, zero-allocation, FFI-friendly, well-structured std module (inside primecitizens/pcz) for Golang, exposing all lower bits of the runtime, and compatible with the official go1.21+ toolchain (go tool compile/link/asm).

This cli module serves as a showcase how we redesign fundamental components in a standard library.

Roadmap

  • Completion support for fish
  • Add more Helper interfaces in addition to HelperTerminal.
    • HelperMarkdown
    • HelperMandoc
    • HelperYAML
  • Define a new interface (Command) as abstraction of Cmd to allow custom implementation.
  • Add cli tool cligen to generate flag indexer implementations for struct types.

LICENSE

Copyright 2023 The Prime Citizens

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Documentation

Overview

Package cli supports POSIX & GNU style cli flag parsing and command running.

Terminology

  • `args`: all strings provided to a cmd. For a root command in real world, it usually is `os.Args[1:]`
  • `flags`: before the first dash, strings interpreted as flag names and flag values by POSIX and GNU style guide.
  • `subcmds` (sub-commands): before the first dash, consecutive args matching a serial of `Cmd.Pattern`. In the below illustration, if there is a `Cmd` in root command's `Children []*Cmd` field whose `Cmd.Pattern` matches `xxx`, then the posArg `xxx` becomes subcmd `xxx`.
  • `posArgs` (positional args): before the first dash, strings that are not flags and subcmds.
  • `dashArgs`: all strings after the dash.

Illustration without subcmds:

                      dash
                        |
    posArg  flag name   |
       |        |       |
./foo xxx -i --join bar -- other args
          |          |    [ all args after the dash are dashArgs]
          |          |
          |      flag value
          |
  flag shorthand, with implicit value

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssignFlagsDefaultValue

func AssignFlagsDefaultValue(flags FlagIndexer, opts *ParseOptions) (err error)

AssignFlagsDefaultValue iterates through all flags and call Flag.Decode on flags with default value (indicated by FlagInfo.DefaultValue) but without FlagStateValueChanged set (indicated by both FlagInfo.State and Flag.State()).

func FormatRoute

func FormatRoute(w io.Writer, route Route, sep string) (n int, err error)

FormatRoute writes all Cmd.Name() in the route with sep in between.

For the last Cmd in route (the target), it writes the complete Cmd.Pattern.

func HandleArgErrorAsHelpRequest

func HandleArgErrorAsHelpRequest(
	opts *CmdOptions, route Route, args []string, badArgAt int, cmdErr error,
) error

HandleArgErrorAsHelpRequest prints the error and usage text of the target command to stderr, it tries to cast Cmd.Extra and Flag.Extra() as TerminalHelper to write messages.

func HandleHelpRequest

func HandleHelpRequest(
	opts *CmdOptions, route Route, args []string, helpArgAt int,
) error

HandleHelpRequest calls HandleArgErrorAsHelpRequest with nil error.

func IsShorthand

func IsShorthand(s string) bool

IsShorthand returns true if s is a single rune string and is not a hyphen.

func ParseFlags

func ParseFlags(args []string, flags FlagFinder, opts *ParseOptions) (posArgs, dashArgs []string, err error)

ParseFlags parses args with options, where args are usually the os.Args[1:].

Return value posArgs are positional args, dashArgs are args after the first dash (`--`).

Known limitations:

  • Flags allow implicit value cannot accept valid standalone value prefixed with hyphen (`-`) due to ambiguity. e.g. `--foo -1` where flag `foo` is of type IntSum. To workaround, use `--foo=-1`.

  • Standalone dash (`--`) can never become flag value or positional arg. To workaround for flag value, use `--flag=--`. There is no workaround to make `--` as a posArg.

func ParseFlagsLowLevel

func ParseFlagsLowLevel(
	args []string,
	flags FlagFinder,
	opts *ParseOptions,
	offset int,
	appendPosArgs bool,
	stopAtFirstPosArg bool,
	setFlagValue bool,
	posArgsBuf []string,
) (
	nParsed int,
	posDash int,
	foundPosArg bool,
	posArgs []string,
	helpArgAt int,
	err error,
)

ParseFlagsLowLevel is the low-level version of ParseFlags with more options for flag parsing control.

If appendPosArgs is false, this function doesn't append positional args to posArgs, so the return value posArgs will be exactly the same a posArgsBuf.

If stopAtFirstPosArg is true, this function returns on reaching the first positional arg (before the dash), that arg is not added to nParsed.

If len(opts.HelpArgs) > 0, this function returns on reaching the first flag that matches any of help flags, in which case, the return value helpArgAt is expected to be greater or equal to zero, and args[helpArgAt] is the arg triggered this return.

If setFlagValue is false, this function calls Flag.Decode() with set = false.

The return value nParsed is the count of args parsed, which includes the bad flag on error return (in which case there are nParsed-1 known good args).

The return value posDash is the index into args, when posDash >= 0, args[posDash] = "--" and args[posDash+1:] is dashArgs.

func RuleContainsAny

func RuleContainsAny[R Rule](rule R, keys ...string) bool

func RuleRequiresAny

func RuleRequiresAny[R Rule](rule R, keys ...string) bool

func WriteShellCompScriptBash

func WriteShellCompScriptBash(out io.Writer, rootCmdName, completionCmdName string) (int, error)

WriteShellCompScriptBash writes the bash completion script to out.

func WriteShellCompScriptPwsh

func WriteShellCompScriptPwsh(out io.Writer, rootCmdName, completionCmdName string) (int, error)

WriteShellCompScriptBash writes the powershell completion script to out.

func WriteShellCompScriptZsh

func WriteShellCompScriptZsh(out io.Writer, rootCmdName, completionCmdName string) (int, error)

WriteShellCompScriptBash writes the zsh completion script to out.

func WriteShellCompUsageBash

func WriteShellCompUsageBash(out io.Writer, rootCmdName, completionCmdName string) (int, error)

WriteShellCompScriptBash writes the usage of bash completion script to out.

func WriteShellCompUsagePwsh

func WriteShellCompUsagePwsh(out io.Writer, rootCmdName, completionCmdName string) (int, error)

WriteShellCompScriptBash writes the usage of powershell completion script to out.

func WriteShellCompUsageZsh

func WriteShellCompUsageZsh(out io.Writer, rootCmdName, completionCmdName string) (int, error)

WriteShellCompScriptBash writes the usage of zsh completion script to out.

Types

type AnyMaybeCompActionAndHelperTerminal

type AnyMaybeCompActionAndHelperTerminal = any

AnyMaybeCompActionAndHelperTerminal is an alias of `any` and indicates some component may try to cast the value as a CompAction, HelperTerminal.

type AnyMaybeHelperTerminal

type AnyMaybeHelperTerminal = any

AnyMaybeHelperTerminal is an alias of `any` and indicates some component will try to cast the value as a HelperTerminal.

type ArgErrorHandleFunc

type ArgErrorHandleFunc = func(
	opts *CmdOptions, route Route, args []string, badArgAt int, argErr error,
) error

ArgErrorHandleFunc for args error.

route is the Cmd route from the root to the last known good Cmd.

args are the same args passed to Cmd.ResolveTarget

when badArgAt >= 0, it is where argErr happened, and args[badArgAt] is the bad arg.

Return nil to ignore the error.

type Bool

type Bool = FlagBase[bool, VPBool[bool]]

predefined flag types for scalar values from command line.

type BoolSlice

type BoolSlice = FlagBase[[]bool, VPSlice[bool, VPBool[bool]]]

predefined flag types for slice values from command line.

type BoolSliceV

type BoolSliceV = FlagBaseV[[]bool, VPSlice[bool, VPBool[bool]]]

predefined flag types for slice values from command line.

type BoolV

type BoolV = FlagBaseV[bool, VPBool[bool]]

predefined flag types for scalar values from command line.

type Cmd

type Cmd struct {
	// Pattern is supposed to be a one-line usage pattern of the command.
	//
	// Text before the first space is used for matching args in order to pick
	// this Cmd as sub-command, multiple names can be provided by joining with
	// pipe sign ('|').
	//
	// As of the text after the first space, here is the recommended syntax:
	//
	//	- `[ ]` to define an optional argument.
	//	- `...` to allow multiple values for the previous arg.
	//	- `|` to provide mutually exclusive options.
	//	- `{ }` to define a group of mutually exclusive args.
	//
	// Example (where foo is the command name):
	//
	//	foo|f [-F file | -D dir]... [-f {text|audio}] profile
	//
	// In the above example, `foo` is the command name and `f` is its alias.
	Pattern string

	// BriefUsage introduces the command briefly.
	BriefUsage string

	// Flags are flags accessible from both this Cmd and all its children.
	Flags FlagFinderMaybeIter

	// LocalFlags are flags only accessible from this Cmd.
	//
	// It is preferred to Flags for flag looking up.
	LocalFlags FlagFinderMaybeIter

	// FlagRule enforces certain rule to flags.
	FlagRule Rule

	// PreRun hook, see the type alias definition for parameter details.
	//
	// In Cmd.Exec, it is called from the root Cmd down to the target Cmd
	// before calling Run (even if the target Cmd's Run may be nil).
	PreRun PreRunFunc

	// Run, see the type alias definition for parameter details.
	//
	// In Cmd.Exec, it is called only when the owner Cmd is the target Cmd.
	Run RunFunc

	// PostRun hook, see the type alias definition for parameter details.
	//
	// In Cmd.Exec, it is called from that target Cmd up to the root Cmd after
	// the Run function returned.
	PostRun PostRunFunc

	// Help provides command specific help request handling.
	//
	// If not nil, it is called on help request for this command, otherwise
	// fallback to CmdOptions.HandleHelpRequest.
	Help HelpHandleFunc

	// Completion is the shell completion helper to suggest args for the
	// command.
	Completion CompAction

	// Extra stores application specific custom data.
	Extra AnyMaybeHelperTerminal

	// Children are sub-commands beloning to this Cmd.
	Children []*Cmd

	// State is Cmd's current state.
	State CmdState
}

A Cmd represents a command.

TODO: define Command interface.

Example (CustomHelpArg)
package main

import (
	"errors"
	"os"
	"regexp"
	"time"

	"github.com/primecitizens/cli"
)

type Config struct {
	Subject string                `cli:"s|subject,hide,#a simple string flag"`
	Dur     *time.Duration        `cli:"d|duration,value=dur,#example duration flag"`
	Size    uint64                `cli:"size,value=size,def=32G,#size accepting common units"`
	Entries *[]string             `cli:"e|entry,#log entries"`
	Metrics map[time.Duration]int `cli:"m|metric,key=dur,value=sum,#metrics summary"`
	Pattern []*regexp.Regexp      `cli:"p|pattern,value=regexp,def=.*,def=^p,#regexp patterns"`
}

func main() {
	opts := &cli.CmdOptions{
		ParseOptions: &cli.ParseOptions{
			// define custom args can initiate help request.
			HelpArgs: []string{"-?", "why not?"},
		},
		Stderr: os.Stdout, // override stderr to work with golang example test
		// You can provide your own HelpHandleFunc, but here we use the one comes with
		// the library.
		HandleHelpRequest: cli.HandleHelpRequest,
	}

	root := cli.Cmd{
		Pattern:    "example -?",
		BriefUsage: "Just like all other indexers, terminal help also works with the ReflectIndexer",
		Flags: cli.NewReflectIndexer(cli.DefaultReflectVPFactory{}, &Config{
			Subject: "Some default value deduced from flag state",
		}),
	}

	err := root.Exec(opts, "-?")
	if err != nil && !errors.Is(err, cli.ErrHelpHandled{}) {
		panic(err)
	}

}
Output:

example -?

Just like all other indexers, terminal help also works with the ReflectIndexer

Flags:
  -s --subject str          (hidden) a simple string flag (default: Some default value deduced from flag state)
  -d --duration dur         example duration flag
     --size size            size accepting common units (default: 32G)
  -e --entry []str          log entries
  -m --metric map[dur]isum  metrics summary
  -p --pattern []regexp     regexp patterns (default: [.*, ^p])
Example (MapIndexer)
package main

import (
	"fmt"

	"github.com/primecitizens/cli"
)

func main() {
	var (
		str string

		flagB cli.BoolV
		flagI cli.IntV
		flagS = cli.String{
			Value: &str,
		}
	)

	root := &cli.Cmd{
		Pattern:    "example {print-flag-values|help|completion}",
		BriefUsage: "Using MapIndexer feels the same as a builder (but way more decentralized).",
		Flags: cli.NewMapIndexer().
			Add(&flagB, "bool", "B").
			Add(&flagI, "int", "I").
			Add(&flagS, "string", "S"),
		LocalFlags: nil,
		FlagRule:   cli.AllOf("bool", "int"),
		Completion: cli.CompActionFiles{},
		Children: []*cli.Cmd{
			{
				Pattern: "print-flag-values",
				Run: func(opts *cli.CmdOptions, route cli.Route, posArgs, dashArgs []string) error {
					fmt.Println("bool:", flagB.Value)
					fmt.Println("int:", flagI.Value)
					fmt.Println("string:", str)
					fmt.Println("posArgs:", posArgs)
					fmt.Println("dashArgs:", dashArgs)
					return nil
				},
			},
			(&cli.CompCmdShells{}).Setup("", -1, false),
		},
	}

	err := root.Exec(&cli.CmdOptions{
		HandleArgError:    cli.HandleArgErrorAsHelpRequest,
		HandleHelpRequest: cli.HandleHelpRequest,
	},
		"print-flag-values", "-BI", "10", "--string", "str", "pos1", "--", "dd1",
	)
	if err != nil {
		panic(err)
	}

}
Output:

bool: true
int: 10
string: str
posArgs: [pos1]
dashArgs: [dd1]
Example (ReflectIndexer)
package main

import (
	"fmt"
	"regexp"
	"sort"
	"strings"
	"time"

	"github.com/primecitizens/cli"
)

type Config struct {
	Subject string                `cli:"s|subject,hide,#a simple string flag"`
	Dur     *time.Duration        `cli:"d|duration,value=dur,#example duration flag"`
	Size    uint64                `cli:"size,value=size,def=32G,#size accepting common units"`
	Entries *[]string             `cli:"e|entry,#log entries"`
	Metrics map[time.Duration]int `cli:"m|metric,key=dur,value=sum,#metrics summary"`
	Pattern []*regexp.Regexp      `cli:"p|pattern,value=regexp,def=.*,def=^p,#regexp patterns"`
}

func run(opts *cli.CmdOptions, route cli.Route, posArgs, dashArgs []string) error {
	config := route.Root().Extra.(*Config)

	fmt.Println("After", config.Dur.Hours(), "hours,",
		config.Subject, "would have", config.Size, "bytes of data")
	fmt.Println("Some of the entries will be like:")
	fmt.Println(strings.Join(*config.Entries, "\n"))
	fmt.Println("Some of the metrics will be like:")
	var keys []time.Duration
	for k := range config.Metrics {
		keys = append(keys, k)
	}
	sort.Slice(keys, func(i, j int) bool { return keys[i] < keys[j] })
	for _, k := range keys {
		fmt.Println("[metric]", k.String(), "=", config.Metrics[k])
	}
	return nil
}

func main() {
	var cfg Config
	root := cli.Cmd{
		Pattern: "example",
		Flags:   cli.NewReflectIndexer(cli.DefaultReflectVPFactory{}, &cfg),
		Run:     run,
		Extra:   &cfg, // run func will find this
	}

	err := root.Exec(nil,
		"-d", "32.5d", "--subject", "log file", "--size", "10T",
		"-e", "[app] err", "-e", "[app] fatal",
		"-m", "10s=2", "--metric", "10s=5",
	)
	if err != nil {
		panic(err)
	}

}
Output:

After 780 hours, log file would have 10995116277760 bytes of data
Some of the entries will be like:
[app] err
[app] fatal
Some of the metrics will be like:
[metric] 10s = 7

func (*Cmd) Exec

func (c *Cmd) Exec(opts *CmdOptions, args ...string) (err error)

Exec tries to find and run the Cmd with longest matching Cmd.Pattern in args.

When called, this Cmd assumes itself as the root command.

func (*Cmd) Is

func (c *Cmd) Is(s string) bool

Is returns true if s is considered a name of this Cmd.

func (*Cmd) Name

func (c *Cmd) Name() (name string)

Name returns the first name in Pattern of this Cmd.

func (*Cmd) ResolveTarget

func (c *Cmd) ResolveTarget(opts *CmdOptions, args ...string) (
	route Route, posArgs, dashArgs []string, err error,
)

ResolveTarget walks the Cmd tree from c to the target Cmd by parsing args.

On a successful return, the `route` leads to the target Cmd with this Cmd being the first entry.

type CmdHelp

type CmdHelp struct {
	// Example lists some typical use cases of the command.
	//
	// DO NOT include prefix like `Example: `
	Example string

	// LongDescription is the detailed description of the command.
	LongDescription string

	// Experimental explains why the command is Experimental.
	//
	// Only use this field to note the reason of being experimental, and
	// DO NOT include prefix like `Experimental: `
	Experimental string

	// Deprecation is the deprecation message of the command.
	//
	// Only use this message to note the reason of deprecation, and
	// DO NOT include prefix like `Deprecated: `
	Deprecation string

	// Changelog may contain upgrade notice of the command.
	//
	// DO NOT include prefix like `Changelog: `
	Changelog string

	// Extra custom data
	Extra any
}

CmdHelp contains commonly used metadata for a cli command.

To produce consistent content, all values SHOULD NOT contain leading or trailling whitespaces.

Hint: use Cmd.Extra to hold *CmdHelp for documentation purpose.

func (*CmdHelp) HelplnCmdTerminal

func (m *CmdHelp) HelplnCmdTerminal(out io.Writer, route Route, linePrefix string) (n int, err error)

HelplnCmdTerminal implements [TerminalHelper].

func (*CmdHelp) HelplnFlagTerminal

func (h *CmdHelp) HelplnFlagTerminal(
	out io.Writer, route Route, linePrefix string,
	indent int, flag FlagInfo, groupHasShorthand bool,
) (int, error)

HelplnFlagTerminal implements [TerminalHelper].

type CmdOptions

type CmdOptions struct {
	ParseOptions *ParseOptions

	// RouteBuf is the buffer for building the Cmd route.
	RouteBuf Route

	// Stdin is the stdin of the cmd.
	//
	// Defaults to nil.
	Stdin io.Reader

	// Stdout is the stdout of the cmd.
	//
	// Defaults to nil.
	Stdout io.Writer

	// Stderr is the stderr of the cmd.
	//
	// Defaults to nil.
	Stderr io.Writer

	// HandleArgError is the function get called to handle errors happened
	// during target resolving.
	HandleArgError ArgErrorHandleFunc

	// HandleHelpRequest is the fallback help request handle func.
	//
	// In a Cmd.Exec call, if both target Cmd.Help func and
	// CmdOptions.HandleHelpRequest are nil, no help will be provided.
	HandleHelpRequest HelpHandleFunc

	// Extra custom data.
	Extra any

	// SkipPostRun skips the Cmd.PostRun when set to true.
	SkipPostRun bool

	// DoNotSetFlags skips setting flag values.
	DoNotSetFlags bool
}

CmdOptions are options for Cmd execution.

func (*CmdOptions) PickStderr

func (c *CmdOptions) PickStderr(def ...io.Writer) io.Writer

PickStderr returns def if c.Stderr is nil.

func (*CmdOptions) PickStdin

func (c *CmdOptions) PickStdin(def ...io.Reader) io.Reader

PickStdin returns def if c.Stdin is nil.

func (*CmdOptions) PickStdout

func (c *CmdOptions) PickStdout(def ...io.Writer) io.Writer

PickStdout returns def if c.Stdout is nil.

type CmdState

type CmdState uint32
const (
	// CmdStateHidden hides the cmd from completion when set.
	CmdStateHidden CmdState = 1 << iota
	// CmdStatePreRunOnce to require the PreRun only gets called once.
	CmdStatePreRunOnce
	CmdStatePreRunCalled

	// CmdStatePostRunOnce to require the PostRun only gets called once.
	CmdStatePostRunOnce
	CmdStatePostRunCalled
)

func (CmdState) Hidden

func (s CmdState) Hidden() bool

func (CmdState) PostRunCalled

func (s CmdState) PostRunCalled() bool

func (CmdState) PostRunOnce

func (s CmdState) PostRunOnce() bool

func (CmdState) PreRunCalled

func (s CmdState) PreRunCalled() bool

func (CmdState) PreRunOnce

func (s CmdState) PreRunOnce() bool

type CompAction

type CompAction interface {
	// Suggest adds possible CompItems according to CompTask.
	Suggest(tsk *CompTask) (added int, state CompState)
}

CompAction defines the interface for a completion action.

type CompActionDirs

type CompActionDirs struct{}

CompActionDirs adds a CompItem to request dir completion.

func (CompActionDirs) Suggest

func (CompActionDirs) Suggest(tsk *CompTask) (int, CompState)

Suggest implements CompAction.

type CompActionDisable

type CompActionDisable struct{}

CompActionDisable marks the CompTask failed, so it can be used to disable the default completion behavior.

func (CompActionDisable) Suggest

func (CompActionDisable) Suggest(tsk *CompTask) (int, CompState)

Suggest implements CompAction.

type CompActionFiles

type CompActionFiles struct{}

CompActionFiles adds a CompItem to request file completion.

func (CompActionFiles) Suggest

func (CompActionFiles) Suggest(tsk *CompTask) (int, CompState)

Suggest implements CompAction.

type CompActionFunc

type CompActionFunc func(tsk *CompTask) (int, CompState)

CompActionFunc wraps a function as Completion implementation.

func (CompActionFunc) Suggest

func (fn CompActionFunc) Suggest(tsk *CompTask) (int, CompState)

Suggest implements CompAction.

type CompActionStatic

type CompActionStatic struct {
	Suggestions []CompItem
	Want, State CompState
}

CompActionStatic adds its predefined suggestions for completion request.

func (*CompActionStatic) Suggest

func (s *CompActionStatic) Suggest(tsk *CompTask) (int, CompState)

Suggest implements CompAction.

type CompCmdBash

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

CompCmdBash is a bash completion command.

func (*CompCmdBash) Setup

func (cc *CompCmdBash) Setup(opComplete *Cmd) *Cmd

Setup returns the prepared command.

opComplete is expected to be the return value of CompCmdOpComplete.Setup.

type CompCmdOpComplete

type CompCmdOpComplete struct {
	// Timeout is the time limit to one completion request.
	Timeout DurationV

	// DebugFile is the file to write debug messages.
	DebugFile StringV

	// At is the position the cursor currently At.
	//
	// for zsh, it should be ($CURRENT - 1).
	// for bash, it should be $cword
	// for pwsh, it should be arg index base on $cursorPosition
	At UintV
	// contains filtered or unexported fields
}

CompCmdOpComplete wraps the `complete` operation sub-command for type CompCmd{Bash, Zsh, Pwsh}.

It prepares the CompTask and invokes its parent Cmd to process the task.

func (*CompCmdOpComplete) FindFlag

func (cc *CompCmdOpComplete) FindFlag(name string) (Flag, bool)

FindFlag implements FlagFinder.

func (*CompCmdOpComplete) NthFlag

func (cc *CompCmdOpComplete) NthFlag(i int) (info FlagInfo, ok bool)

NthFlag implements FlagIter.

func (*CompCmdOpComplete) Setup

func (cc *CompCmdOpComplete) Setup(defaultTimeout time.Duration) *Cmd

Setup returns the initialized *Cmd.

func (*CompCmdOpComplete) Task

func (cc *CompCmdOpComplete) Task() *CompTask

Task returns the prepared CompTask.

type CompCmdPwsh

type CompCmdPwsh CompCmdBash

CompCmdPwsh is a powershell completion command.

func (*CompCmdPwsh) Setup

func (cc *CompCmdPwsh) Setup(opComplete *Cmd) *Cmd

Setup returns the prepared command.

opComplete is expected to be the return value of CompCmdOpComplete.Setup.

type CompCmdShells

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

CompCmdShells is wraps all supported shell completion commands:

  • bash {,complete}
  • zsh {,complete}
  • pwsh {,complete}

To use it, the return value of (&CompCmdShells{}).Setup(...) should be a direct child to your application's root command.

func (*CompCmdShells) Setup

func (cc *CompCmdShells) Setup(name string, defaultTimeout time.Duration, hide bool) *Cmd

Setup the shell completion command.

name will be set to "completion" if it is empty.

defaultTimeout will be 5s, if it is negative, set it to 0 to disable timeout.

type CompCmdZsh

type CompCmdZsh CompCmdBash

CompCmdZsh is a zsh completion command.

func (*CompCmdZsh) Setup

func (cc *CompCmdZsh) Setup(opComplete *Cmd) *Cmd

Setup returns the prepared command.

opComplete is expected to be the return value of CompCmdOpComplete.Setup().

type CompFmt

type CompFmt interface {
	// Format writes one CompItem each line with shell specific character
	// escaping and formatting.
	Format(out io.Writer, finishedTask *CompTask) error
}

CompFmt defines completion result formatter.

type CompFmtBash

type CompFmtBash struct {
	// Cols is supposed to be the $COLUMNS in bash completion.
	Cols int

	// CompType is the type of completion:
	//
	//  - '\t' (9) for normal completion
	//  - '?' (63) for listing completions after successive tabs
	//  - '!' (33) for listing alternatives on partial word completion
	//  - '@' (64) to list completions if the word is not unmodified
	//  - '%' (37) for menu completion
	//  - '*' (42) for insert completion
	//
	// Refs:
	//  - https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#index-COMP_005fTYPE
	CompType int
}

CompFmtBash implements CompFmt for bash.

It produces two kinds of lines:

  • ' <value>' (space prefixed) where <value> contains arguments to bash function _filedir.
  • others (without space prefix), as bash-completion COMPREPLY element.

func (*CompFmtBash) EscapeSpaces

func (fmt *CompFmtBash) EscapeSpaces(out io.Writer, s string, oneline bool) (int, error)

func (*CompFmtBash) Format

func (fmt *CompFmtBash) Format(out io.Writer, tsk *CompTask) (err error)

type CompFmtPwsh

type CompFmtPwsh struct {
	// Mods is the PowerShell completion mode, possible values are:
	//
	//  - TabCompleteNext (default windows style - on each key press the next option is displayed)
	//  - Complete (works like bash)
	//  - MenuComplete (works like zsh)
	Mode string
}

CompFmtPwsh implements CompFmt for powershell.

It produces two kinds of lines:

  • `<value> ;<description>` (note the space and unescaped semi-colon) for creating CompletionResult items.
  • `;<argument-spec>` (note the unescaped semi-colon prefix) for filesystem related completion.

func (*CompFmtPwsh) EscapeSpecialChars

func (fmt *CompFmtPwsh) EscapeSpecialChars(out io.Writer, s string, oneline bool) (int, error)

func (*CompFmtPwsh) Format

func (fmt *CompFmtPwsh) Format(out io.Writer, tsk *CompTask) (err error)

type CompFmtZsh

type CompFmtZsh struct{}

CompFmtZsh implements CompFmt for zsh.

It produces two kinds of lines:

  • `<value>:<description>` for zsh function _describe.
  • `:<argument-spec>` (note the colon prefix) for zsh function _arguments, currently only used for filename and dirname completion.

func (CompFmtZsh) EscapeColons

func (CompFmtZsh) EscapeColons(out io.Writer, s string, oneline bool) (int, error)

func (CompFmtZsh) Format

func (fmt CompFmtZsh) Format(out io.Writer, tsk *CompTask) (err error)

type CompItem

type CompItem struct {
	// Value is the suggested text arg (e.g. foo, --bar).
	//
	// When Kind is one of [Files, Dirs], it is the glob pattern
	Value string

	// Description is the help text of the value.
	Description string

	// Kind marks the completion kind.
	Kind CompKind
}

A CompItem is a completion suggestion.

type CompKind

type CompKind uint8

CompKind gives CompItem type information.

const (
	CompKindText CompKind = iota
	CompKindFlagName
	CompKindFlagValue
	CompKindFiles
	CompKindDirs
)

type CompState

type CompState uint32

CompState used by CompTask to manage completion values.

const (
	// CompStateFailed to NOT use any completion.
	CompStateFailed CompState = 1 << iota

	CompStateDone // to NOT add further CompItems.

	CompStateHasFlagNames
	CompStateHasFlagValues
	CompStateHasSubcmds
	CompStateHasFiles
	CompStateHasDirs

	CompStateOptionNospace
	CompStateOptionNosort
)

func (CompState) Done

func (c CompState) Done() bool

func (CompState) Failed

func (c CompState) Failed() bool

func (CompState) HasDirs

func (c CompState) HasDirs() bool

func (CompState) HasFiles

func (c CompState) HasFiles() bool

func (CompState) HasFlagNames

func (c CompState) HasFlagNames() bool

func (CompState) HasFlagValues

func (c CompState) HasFlagValues() bool

func (CompState) HasSubcmds

func (c CompState) HasSubcmds() bool

func (CompState) OptionNosort

func (c CompState) OptionNosort() bool

func (CompState) OptionNospace

func (c CompState) OptionNospace() bool

type CompTask

type CompTask struct {

	// ExecutablePath is the path to the executable which requested this
	// completion task.
	ExecutablePath string

	// Args are all args present on command-line, including args after the
	// one requested the completion.
	Args []string

	// At is the position of the arg to complete.
	//
	// when At == len(Args), the task is to suggest the next arg.
	// when 0 <= At <= len(Args)-1, the task is to complete the last partial arg.
	// when < len(Args)-1, the task is to complete previous partial arg.
	At int

	// ToComplete is the arg value to be compeleted.
	//
	// When completing a flag value, it is the value part of the arg, which
	// means if command-line input triggering the completion was
	// `--foo=s<tab>` and `foo` can be found in that context, then this field
	// will get `s`.
	ToComplete string

	// Route is the Cmd route up to the arg to complete.
	Route Route

	// PosArgs are all positional args found before the arg to complete.
	//
	// Depending on the position of the arg to complete, the Args field may
	// contain positional args, but this field can get nothing.
	PosArgs []string

	// DashArgs are all args found after the first dash but before the arg
	// to complete.
	//
	// If the arg to complete is before the dash, the Args may contain dash
	// but this field will get nothing.
	DashArgs []string

	// FlagMissingValue is the Flag right before the arg to complete and is
	// missing the value in arg to complete.
	FlagMissingValue Flag
	FlagValuePrefix  string
	// contains filtered or unexported fields
}

CompTask represents a completion tsk.

func (*CompTask) Add

func (tsk *CompTask) Add(force bool, items ...CompItem) (added int)

Add force adds CompItems without checking prefix match

func (*CompTask) AddDefault

func (tsk *CompTask) AddDefault() (added int)

AddDefault adds CompItems indicated by argument parsing (Init).

func (*CompTask) AddDirs

func (tsk *CompTask) AddDirs(force bool, globs ...string) (added int)

AddDirs adds requests to match filesystem dirs.

func (*CompTask) AddFiles

func (tsk *CompTask) AddFiles(force bool, globs ...string) (added int)

AddFiles adds requests to match filesystem files.

func (*CompTask) AddFlagNames

func (tsk *CompTask) AddFlagNames(force bool, flags FlagIndexer, descr bool) (added int)

AddFlagNames adds flag names, it expects tsk.ToComplete either being an empty string or containing a flag name prefix (`-`, `--`).

If the argument `flags` is nil, use the target command's flags (tsk.Route).

func (*CompTask) AddFlagValues

func (tsk *CompTask) AddFlagValues(force bool, flag Flag, def string, addDefaults bool) (added int)

AddFlagValues adds matched values from the specified flag.

It retrieves completion suggestions by trying following methods in order:

  • cast flag as CompAction.
  • cast flag.Extra() as CompAction.

If addDefaults is true:

  • add value returned by Flag.Default() if matched.
  • deduce default value by flag State() unchange and HasValue() true.

func (*CompTask) AddMatched

func (tsk *CompTask) AddMatched(force bool, items ...CompItem) (added int)

AddMatched filters CompItems and only adds those with tsk.ToComplete prefix.

func (*CompTask) AddSubcmds

func (tsk *CompTask) AddSubcmds(force bool, cmd *Cmd, descr bool) (added int)

AddSubcmds adds sub-command names of cmd.

If the argument `cmd` is nil, use the last Cmd in tsk.Route.

Set descr to true to include description.

func (*CompTask) Debug

func (tsk *CompTask) Debug(msgs ...string)

Debug writes messages to the debug output.

func (*CompTask) Done

func (tsk *CompTask) Done()

Done marks this task as finished, no CompItem can be added without setting force=false.

func (*CompTask) Fail

func (tsk *CompTask) Fail()

Fail marks this task as failed, and should not produce any completion at all.

func (*CompTask) Init

func (tsk *CompTask) Init(root *Cmd, opts *CmdOptions, at int, args ...string)

Init initializes the CompTask with command-line options.

If pos is in range [0, len(args)), args[pos] is the arg to complete.

If the args slice is not empty, args[0] is expected to be the executable path.

func (*CompTask) Nth

func (tsk *CompTask) Nth(i int) (CompItem, bool)

Nth returns the i-th CompItem has been added.

func (*CompTask) RawToComplete

func (tsk *CompTask) RawToComplete() string

RawToComplete returns the unprocessed arg value to complete.

func (*CompTask) SetDebugOutput

func (tsk *CompTask) SetDebugOutput(out io.Writer)

SetDebugOutput sets the debug output used by the Debug method.

func (*CompTask) State

func (tsk *CompTask) State() CompState

State returns the current CompState of the task.

func (*CompTask) Want

func (tsk *CompTask) Want() CompState

Want returns the CompState containing CompStateHasXxx bits indicating the expected completion result set.

These bits are set by Init() and are used by AddDefault().

type DefaultReflectVPFactory

type DefaultReflectVPFactory struct{}

DefaultReflectVPFactory is the ReflectVPFactory implementation referenced from comments of ReflectIndexer.

func (DefaultReflectVPFactory) GetVPReflectFor

func (DefaultReflectVPFactory) GetVPReflectFor(fieldType reflect.Type, keyType, valueType string) (vp VP[*reflect.Value], err error)

type Duration

predefined flag types for scalar values from command line.

type DurationSlice

predefined flag types for slice values from command line.

type DurationSliceV

predefined flag types for slice values from command line.

type DurationSum

predefined flag types for sumed scalar values from command line.

type DurationSumV

predefined flag types for sumed scalar values from command line.

type DurationV

predefined flag types for scalar values from command line.

type ErrAmbiguousArgs

type ErrAmbiguousArgs struct {
	Name  string
	Value string
	At    int
}

ErrAmbiguousArgs caused by an arg (.Value) with hyphen (`-`) prefix, and the arg before it (.Name) is a flag name having implicit value but also accepts it as value.

func (*ErrAmbiguousArgs) Error

func (err *ErrAmbiguousArgs) Error() string

type ErrCmdNotRunnable

type ErrCmdNotRunnable struct {
	Name string
}

ErrCmdNotRunnable

func (*ErrCmdNotRunnable) Error

func (err *ErrCmdNotRunnable) Error() string

type ErrDuplicateFlag

type ErrDuplicateFlag struct {
	// Name of the flag found duplicate.
	Name string
}

ErrDuplicateFlag is the panic value caused by MapIndexer found duplicate flag registration.

func (*ErrDuplicateFlag) Error

func (err *ErrDuplicateFlag) Error() string

Error implements error.

type ErrEmptyRoute

type ErrEmptyRoute struct{}

func (ErrEmptyRoute) Error

func (ErrEmptyRoute) Error() string

type ErrFlagSetAtMostOnce

type ErrFlagSetAtMostOnce struct{}

ErrFlagSetAtMostOnce for flags marked once but appeared more than once.

func (ErrFlagSetAtMostOnce) Error

func (ErrFlagSetAtMostOnce) Error() string

type ErrFlagUndefined

type ErrFlagUndefined struct {
	// Name of the missing flag.
	Name string
	// At
	//
	// When >= 0, the error occurred during flag parsing and args[At] is the
	// arg containing the flag.
	//
	// When < 0, just a flag not defined.
	At int
}

ErrFlagUndefined

func (*ErrFlagUndefined) Error

func (err *ErrFlagUndefined) Error() string

Error implements error.

type ErrFlagValueInvalid

type ErrFlagValueInvalid struct {
	// Name of the flag having invalid value.
	Name string

	// Value is the invalid value.
	Value string

	// NameAt is the arg index into the full arg list (`args`)
	//
	// args[NameAt] is the arg containing the flag name.
	NameAt int

	// ValueAt is the arg index into the full arg list (`args`)
	//
	// when >= 0, args[ValueAt] is the arg containing the flag value.
	// otherwise, the invalid value was implied by the flag.
	ValueAt int

	// Reason is the error caused this error.
	Reason error
}

ErrFlagValueInvalid

func (*ErrFlagValueInvalid) Error

func (err *ErrFlagValueInvalid) Error() string

type ErrFlagValueMissing

type ErrFlagValueMissing struct {
	// Name is a single flag name without standard hyphen prefix.
	Name string

	// At is the arg index into the full arg list.
	At int
}

ErrFlagValueMissing

func (*ErrFlagValueMissing) Error

func (err *ErrFlagValueMissing) Error() string

Error implements error.

type ErrHelpHandled

type ErrHelpHandled struct{}

ErrHelpHandled is used to notify caller the help request has been handled.

func (ErrHelpHandled) Error

func (ErrHelpHandled) Error() string

type ErrHelpPending

type ErrHelpPending struct {
	// HelpArg is the arg value that requested the help handling.
	HelpArg string
	// At is the HelpArg index into the full arg list.
	At int
}

ErrHelpPending for help but no help handle func could be found.

func (*ErrHelpPending) Error

func (err *ErrHelpPending) Error() string

type ErrInvalidValue

type ErrInvalidValue struct {
	// Type is the type or format the Value supposed to be.
	Type string

	// Value is the actual bad value.
	Value string

	// Partial When set to true, means the Value contains a invalid part,
	// and that part is meant to be a Type value.
	Partial bool
}

ErrInvalidValue

func (*ErrInvalidValue) Error

func (v *ErrInvalidValue) Error() string

Error implements error.

  • When v.Partial is true: "$v.Value contains invalid $v.Type value"
  • When v.Partial is false: "$v.Value is not a valid %v.Type value"

type ErrShorthandOfExplicitFlagInMiddle

type ErrShorthandOfExplicitFlagInMiddle struct {
	Shorthand        string
	ShorthandCluster string
	Value            string
}

ErrShorthandOfExplicitFlagInMiddle caused by a cluster of flag shorthands with explicit value assigning (e.g. -abcdefg=foo), some shorthand in middle rather than the last one requires a explicit value.

func (*ErrShorthandOfExplicitFlagInMiddle) Error

type ErrTimeout

type ErrTimeout struct{}

ErrTimeout

func (ErrTimeout) Error

func (ErrTimeout) Error() string

type ErrUnsupportedType

type ErrUnsupportedType struct {
	Type      reflect.Type
	KeyType   string
	ValueType string
}

func (*ErrUnsupportedType) Error

func (e *ErrUnsupportedType) Error() string

type Flag

type Flag interface {
	// Type returns (typename, true) if there is type information for this
	// flag.
	Type() (string, bool)

	// ImplyValue returns the text implied by the existence of the flag name.
	//
	// return ("", false) to indicate the flag doesn't have implied value.
	ImplyValue() (string, bool)

	// Decode decodes a text argument to the flag value.
	Decode(opts *ParseOptions, name, arg string, set bool) error

	// Extra returns the user defined extra data.
	Extra() AnyMaybeCompActionAndHelperTerminal

	// FlagState returns the state of the flag.
	State() FlagState

	// HasValue returns true if calling PrintValue will write some
	// value.
	HasValue() bool

	// PrintValue writes the text representation of current value of
	// the flag.
	//
	// It MAY panic if HasValue returned false.
	PrintValue(out io.Writer) (int, error)

	// Usage returns the brief usage of the flag.
	Usage() string
}

Flag defines the interface of an entry used by FlagIndexer and ParseFlag.

NOTE: In this package, a Flag's default value is provided by the FlagInfo and will only be assign to Flags inside Cmd.Exec.

func FindFlag

func FindFlag[F FlagFinder](flags F, names ...string) (name string, flag Flag, found bool)

FindFlag tries to find a Flag from the FlagFinder with a list of flag names.

On returning found = true, name is the one used to find the flag.

type FlagBase

type FlagBase[T any, P VP[*T]] struct {
	// BriefUsage is the help text for terminal user.
	BriefUsage string

	// Ext is the extra custom data for this flag.
	Ext AnyMaybeCompActionAndHelperTerminal

	// Value points to the actual variable to set.
	Value *T

	VP P

	// State_ of the flag.
	State_ FlagState
}

FlagBase holds a pointer to the actual value.

func (*FlagBase[T, P]) Decode

func (f *FlagBase[T, P]) Decode(opts *ParseOptions, name, arg string, set bool) error

func (*FlagBase[T, P]) Extra

func (f *FlagBase[T, P]) Extra() any

func (*FlagBase[T, P]) HasValue

func (f *FlagBase[T, P]) HasValue() bool

func (*FlagBase[T, P]) ImplyValue

func (f *FlagBase[T, P]) ImplyValue() (string, bool)

func (*FlagBase[T, P]) PrintValue

func (f *FlagBase[T, P]) PrintValue(out io.Writer) (int, error)

func (*FlagBase[T, P]) State

func (f *FlagBase[T, P]) State() FlagState

func (*FlagBase[T, P]) Type

func (f *FlagBase[T, P]) Type() (string, bool)

func (*FlagBase[T, P]) Usage

func (f *FlagBase[T, P]) Usage() string

type FlagBaseV

type FlagBaseV[T any, P VP[*T]] struct {
	// BriefUsage is the help text for terminal user.
	BriefUsage string

	// Ext is the extra custom data for this flag.
	Ext AnyMaybeCompActionAndHelperTerminal

	// State_ of the flag.
	State_ FlagState

	// Value of the flag.
	Value T

	VP P
}

FlagBaseV is FlagBase but with value embedded.

func (*FlagBaseV[T, P]) Decode

func (f *FlagBaseV[T, P]) Decode(opts *ParseOptions, name, arg string, set bool) error

func (*FlagBaseV[T, P]) Extra

func (f *FlagBaseV[T, P]) Extra() any

func (*FlagBaseV[T, P]) HasValue

func (f *FlagBaseV[T, P]) HasValue() bool

func (*FlagBaseV[T, P]) ImplyValue

func (f *FlagBaseV[T, P]) ImplyValue() (string, bool)

func (*FlagBaseV[T, P]) PrintValue

func (f *FlagBaseV[T, P]) PrintValue(out io.Writer) (int, error)

func (*FlagBaseV[T, P]) State

func (f *FlagBaseV[T, P]) State() FlagState

func (*FlagBaseV[T, P]) Type

func (f *FlagBaseV[T, P]) Type() (string, bool)

func (*FlagBaseV[T, P]) Usage

func (f *FlagBaseV[T, P]) Usage() string

type FlagEmptyV

type FlagEmptyV FlagBaseV[struct{}, VPNop[*struct{}]]

FlagEmptyV is a flag without value.

func (*FlagEmptyV) Decode

func (f *FlagEmptyV) Decode(opts *ParseOptions, name, arg string, set bool) error

func (*FlagEmptyV) Extra

func (f *FlagEmptyV) Extra() any

func (*FlagEmptyV) HasValue

func (f *FlagEmptyV) HasValue() bool

func (*FlagEmptyV) ImplyValue

func (f *FlagEmptyV) ImplyValue() (string, bool)

func (*FlagEmptyV) PrintValue

func (f *FlagEmptyV) PrintValue(io.Writer) (int, error)

func (*FlagEmptyV) State

func (f *FlagEmptyV) State() FlagState

func (*FlagEmptyV) Type

func (f *FlagEmptyV) Type() (string, bool)

func (*FlagEmptyV) Usage

func (f *FlagEmptyV) Usage() string

type FlagFinder

type FlagFinder interface {
	// FindFlag searches flags known to this FlagFinder by name.
	//
	// The name can be either a full flag name or a flag shorthand, and
	// doesn't contain the POSIX & GNU flag prefix (`-` and `--`).
	FindFlag(name string) (Flag, bool)
}

FlagFinder

type FlagFinderMaybeIter

type FlagFinderMaybeIter = FlagFinder

FlagFinderMaybeIter is an alias of FlagFinder but indicates the implementation may have additional FlagIter support.

type FlagHelp

type FlagHelp struct {
	// Experimental explains why the flag is Experimental.
	//
	// Only use this field to note the reason of being experimental, and
	// DO NOT include prefix like `EXPERIMENTAL: `
	Experimental string

	// Deprecation is the deprecation message of the flag.
	//
	// Only use this field to note the reason of deprecation, and
	// DO NOT include prefix like `DEPRECATED: `
	Deprecation string

	// Changelog may contain upgrade notice of the flag.
	//
	// DO NOT include prefix like `CHANGELOG: `
	Changelog string

	// Completion is the completion action to be called to add suggestions.
	Completion CompAction

	// Extra custom data.
	Extra any
}

FlagHelp defines commonly used flag metadata

Hint: use .Extra of a flag to hold FlagHelp for documentation purpose.

func (*FlagHelp) HelplnCmdTerminal

func (h *FlagHelp) HelplnCmdTerminal(out io.Writer, route Route, prefix string) (int, error)

func (*FlagHelp) HelplnFlagTerminal

func (h *FlagHelp) HelplnFlagTerminal(
	out io.Writer, route Route, prefix string, indent int, info FlagInfo, groupHasShorthand bool,
) (n int, err error)

func (*FlagHelp) Suggest

func (h *FlagHelp) Suggest(tsk *CompTask) (added int, state CompState)

Suggest implements CompAction.

type FlagIndexer

type FlagIndexer interface {
	FlagFinder
	FlagIter
}

FlagIndexer is the combination of FlagFinder and FlagIter.

type FlagInfo

type FlagInfo struct {
	// Name is the long flag name (the long one).
	Name string
	// Shorthand is the flag shorthand.
	Shorthand string

	// DefaultValue is the default value used for the flag.
	//
	// Please use following format to provide non-scalar default value:
	//	'[' + entry1 + ', ' + entry2 ... ']'
	//
	// NOTE: For non-scalar values, when default value is being assigned
	// by Cmd.Exec, it checks prefix '[' and suffix ']', and splits
	// elements by cutting around ', '.
	DefaultValue string

	// State is the current state of the flag.
	State FlagState
}

FlagInfo is a pack of the flag name, shorthand, default value and current state.

type FlagIter

type FlagIter interface {
	// NthFlag returns the i-th flag's info this iterator can find.
	//
	// The bool return value indicates whether there is i-th flag, on
	// returning false, call with any value greater than i should return
	// false as well.
	NthFlag(i int) (FlagInfo, bool)
}

FlagIter

type FlagLevel

type FlagLevel interface {
	// TrimAllLevelPrefixes tirms all prefixes belonging to each level.
	TrimAllLevelPrefixes(name string) string

	// GetFullFlagName adds all prefixes to name.
	GetFullFlagName(name string) string
}

FlagLevel

type FlagReflect

type FlagReflect struct {
	VP           VP[*reflect.Value]
	Value        reflect.Value
	BriefUsage   string
	DefaultValue string
	Comp         []string
	State_       FlagState
}

FlagReflect

It is used internally by the ReflectIndexer.

func (*FlagReflect) Decode

func (f *FlagReflect) Decode(opts *ParseOptions, name, arg string, set bool) error

func (*FlagReflect) Default

func (f *FlagReflect) Default() string

func (*FlagReflect) Extra

func (f *FlagReflect) Extra() any

func (*FlagReflect) HasValue

func (f *FlagReflect) HasValue() bool

func (*FlagReflect) ImplyValue

func (f *FlagReflect) ImplyValue() (string, bool)

func (*FlagReflect) PrintValue

func (f *FlagReflect) PrintValue(out io.Writer) (int, error)

func (*FlagReflect) State

func (f *FlagReflect) State() FlagState

func (*FlagReflect) Suggest

func (f *FlagReflect) Suggest(tsk *CompTask) (added int, _ CompState)

Suggest implements CompAction.

func (*FlagReflect) Type

func (f *FlagReflect) Type() (string, bool)

func (*FlagReflect) Usage

func (f *FlagReflect) Usage() string

type FlagState

type FlagState uint32

FlagState contains bits representing a Flag's state.

const (
	// FlagStateValueChanged marks the value of the flag is changed.
	//
	// It SHOULD only be set inside method Flag.Decode when set is true.
	FlagStateValueChanged FlagState = 1 << iota

	// FlagStateHidden marks the flag hidden.
	FlagStateHidden

	// FlagStateSetAtMostOnce marks the flag should only enjoy successful
	// decoding with set=true at most once.
	FlagStateSetAtMostOnce
)

func (FlagState) Hidden

func (m FlagState) Hidden() bool

func (FlagState) SetAtMostOnce

func (m FlagState) SetAtMostOnce() bool

func (FlagState) ValueChanged

func (m FlagState) ValueChanged() bool

type FlagViolation

type FlagViolation Violation

A FlagViolation represents a rule violation caused by flag.

func (*FlagViolation) Error

func (err *FlagViolation) Error() string

type Float32

type Float32 = FlagBase[float32, VPFloat[float32]]

predefined flag types for scalar values from command line.

type Float32Slice

type Float32Slice = FlagBase[[]float32, VPSlice[float32, VPFloat[float32]]]

predefined flag types for slice values from command line.

type Float32SliceV

type Float32SliceV = FlagBaseV[[]float32, VPSlice[float32, VPFloat[float32]]]

predefined flag types for slice values from command line.

type Float32Sum

type Float32Sum = FlagBase[float32, VPSum[float32, VPFloat[float32]]]

predefined flag types for sumed scalar values from command line.

type Float32SumV

type Float32SumV = FlagBaseV[float32, VPSum[float32, VPFloat[float32]]]

predefined flag types for sumed scalar values from command line.

type Float32V

type Float32V = FlagBaseV[float32, VPFloat[float32]]

predefined flag types for scalar values from command line.

type Float64

type Float64 = FlagBase[float64, VPFloat[float64]]

predefined flag types for scalar values from command line.

type Float64Slice

type Float64Slice = FlagBase[[]float64, VPSlice[float64, VPFloat[float64]]]

predefined flag types for slice values from command line.

type Float64SliceV

type Float64SliceV = FlagBaseV[[]float64, VPSlice[float64, VPFloat[float64]]]

predefined flag types for slice values from command line.

type Float64Sum

type Float64Sum = FlagBase[float64, VPSum[float64, VPFloat[float64]]]

predefined flag types for sumed scalar values from command line.

type Float64SumV

type Float64SumV = FlagBaseV[float64, VPSum[float64, VPFloat[float64]]]

predefined flag types for sumed scalar values from command line.

type Float64V

type Float64V = FlagBaseV[float64, VPFloat[float64]]

predefined flag types for scalar values from command line.

type FuncIndexer

type FuncIndexer func(flag string, index int) (f Flag, info FlagInfo, ok bool)

FuncIndexer wraps a function as FlagIndexer.

when index < 0, act as FlagFinder, otherwise act as FlagIter.

func (FuncIndexer) FindFlag

func (fn FuncIndexer) FindFlag(name string) (Flag, bool)

FindFlag implements FlagFinder.

func (FuncIndexer) NthFlag

func (fn FuncIndexer) NthFlag(i int) (info FlagInfo, ok bool)

NthFlag implements FlagIter.

type HelpHandleFunc

type HelpHandleFunc = func(
	opts *CmdOptions, route Route, args []string, helpArgAt int,
) error

HelpHandleFunc for handling help requests.

when helpArgAt < 0, this function was called as the fallback of ArgErrorHandleFunc, and the argErr is discarded.

when helpArgAt >= 0, args[helpArgAt] is the arg initiated the help request, in this case return nil error will be replaced with ErrHelpRequestHandled{}.

type HelperTerminal

type HelperTerminal interface {
	// HelplnCmdTerminal writes help messages for the target command
	// with a newline in the end.
	HelplnCmdTerminal(out io.Writer, route Route, linePrefix string) (int, error)

	// HelplnFlagTerminal writes help meesages for the flag with a newline
	// in the end.
	HelplnFlagTerminal(
		out io.Writer, route Route, linePrefix string,
		indent int, flag FlagInfo, groupHasShorthand bool,
	) (int, error)
}

HelperTerminal writes help messages for a terminal user.

type Inspector

type Inspector interface {
	// CheckFlagValueChanged returns ture if the flag's value has been changed.
	CheckFlagValueChanged(key string) bool
}

An Inspector is an external verifier used to check rule enforcement.

type Int

type Int = FlagBase[int, VPInt[int]]

predefined flag types for scalar values from command line.

type Int16

type Int16 = FlagBase[int16, VPInt[int16]]

predefined flag types for scalar values from command line.

type Int16Slice

type Int16Slice = FlagBase[[]int16, VPSlice[int16, VPInt[int16]]]

predefined flag types for slice values from command line.

type Int16SliceV

type Int16SliceV = FlagBaseV[[]int16, VPSlice[int16, VPInt[int16]]]

predefined flag types for slice values from command line.

type Int16Sum

type Int16Sum = FlagBase[int16, VPSum[int16, VPInt[int16]]]

predefined flag types for sumed scalar values from command line.

type Int16SumV

type Int16SumV = FlagBaseV[int16, VPSum[int16, VPInt[int16]]]

predefined flag types for sumed scalar values from command line.

type Int16V

type Int16V = FlagBaseV[int16, VPInt[int16]]

predefined flag types for scalar values from command line.

type Int32

type Int32 = FlagBase[int32, VPInt[int32]]

predefined flag types for scalar values from command line.

type Int32Slice

type Int32Slice = FlagBase[[]int32, VPSlice[int32, VPInt[int32]]]

predefined flag types for slice values from command line.

type Int32SliceV

type Int32SliceV = FlagBaseV[[]int32, VPSlice[int32, VPInt[int32]]]

predefined flag types for slice values from command line.

type Int32Sum

type Int32Sum = FlagBase[int32, VPSum[int32, VPInt[int32]]]

predefined flag types for sumed scalar values from command line.

type Int32SumV

type Int32SumV = FlagBaseV[int32, VPSum[int32, VPInt[int32]]]

predefined flag types for sumed scalar values from command line.

type Int32V

type Int32V = FlagBaseV[int32, VPInt[int32]]

predefined flag types for scalar values from command line.

type Int64

type Int64 = FlagBase[int64, VPInt[int64]]

predefined flag types for scalar values from command line.

type Int64Slice

type Int64Slice = FlagBase[[]int64, VPSlice[int64, VPInt[int64]]]

predefined flag types for slice values from command line.

type Int64SliceV

type Int64SliceV = FlagBaseV[[]int64, VPSlice[int64, VPInt[int64]]]

predefined flag types for slice values from command line.

type Int64Sum

type Int64Sum = FlagBase[int64, VPSum[int64, VPInt[int64]]]

predefined flag types for sumed scalar values from command line.

type Int64SumV

type Int64SumV = FlagBaseV[int64, VPSum[int64, VPInt[int64]]]

predefined flag types for sumed scalar values from command line.

type Int64V

type Int64V = FlagBaseV[int64, VPInt[int64]]

predefined flag types for scalar values from command line.

type Int8

type Int8 = FlagBase[int8, VPInt[int8]]

predefined flag types for scalar values from command line.

type Int8Slice

type Int8Slice = FlagBase[[]int8, VPSlice[int8, VPInt[int8]]]

predefined flag types for slice values from command line.

type Int8SliceV

type Int8SliceV = FlagBaseV[[]int8, VPSlice[int8, VPInt[int8]]]

predefined flag types for slice values from command line.

type Int8Sum

type Int8Sum = FlagBase[int8, VPSum[int8, VPInt[int8]]]

predefined flag types for sumed scalar values from command line.

type Int8SumV

type Int8SumV = FlagBaseV[int8, VPSum[int8, VPInt[int8]]]

predefined flag types for sumed scalar values from command line.

type Int8V

type Int8V = FlagBaseV[int8, VPInt[int8]]

predefined flag types for scalar values from command line.

type IntSlice

type IntSlice = FlagBase[[]int, VPSlice[int, VPInt[int]]]

predefined flag types for slice values from command line.

type IntSliceV

type IntSliceV = FlagBaseV[[]int, VPSlice[int, VPInt[int]]]

predefined flag types for slice values from command line.

type IntSum

type IntSum = FlagBase[int, VPSum[int, VPInt[int]]]

predefined flag types for sumed scalar values from command line.

type IntSumV

type IntSumV = FlagBaseV[int, VPSum[int, VPInt[int]]]

predefined flag types for sumed scalar values from command line.

type IntV

type IntV = FlagBaseV[int, VPInt[int]]

predefined flag types for scalar values from command line.

type LevelIndexer

type LevelIndexer struct {
	// Up points to the up level, if any.
	Up FlagLevel

	// Prefix is the prefix to identify this level.
	//
	// Should not be empty for non-root level.
	Prefix string

	// Flags
	Flags FlagFinderMaybeIter
	// contains filtered or unexported fields
}

LevelIndexer is a FlagFinder wrapper to build multi-level flag hierarchy.

func (*LevelIndexer) FindFlag

func (l *LevelIndexer) FindFlag(name string) (Flag, bool)

FindFlag implements FlagFinder.

func (*LevelIndexer) GetFullFlagName

func (l *LevelIndexer) GetFullFlagName(name string) string

GetFullFlagName implements FlagLevel.

func (*LevelIndexer) NthFlag

func (l *LevelIndexer) NthFlag(i int) (info FlagInfo, ok bool)

NthFlag implements FlagIter.

func (*LevelIndexer) TrimAllLevelPrefixes

func (l *LevelIndexer) TrimAllLevelPrefixes(name string) string

TrimAllLevelPrefixes implements FlagLevel.

type MapIndexer

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

MapIndexer implements FlagIndexer using built-in maps.

func NewMapIndexer

func NewMapIndexer() *MapIndexer

NewMapIndexer creates a new MapIndexer.

func (*MapIndexer) Add

func (m *MapIndexer) Add(flag Flag, names ...string) *MapIndexer

Add adds a flag with its names.

It panics when name is empty or there is flag with same name shorthand.

func (*MapIndexer) AddWithDefaultValue

func (m *MapIndexer) AddWithDefaultValue(defaultValue string, flag Flag, names ...string) *MapIndexer

AddWithDefaultValue is Add but provides default value to the flag.

func (*MapIndexer) FindFlag

func (m *MapIndexer) FindFlag(name string) (Flag, bool)

FindFlag implements FlagFinder.

func (*MapIndexer) NthFlag

func (m *MapIndexer) NthFlag(i int) (info FlagInfo, ok bool)

NthFlag implements FlagIter.

type MapIntBool

type MapIntBool = FlagBase[map[int]bool, VPMap[int, bool, VPInt[int], VPBool[bool]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntBoolSlice

type MapIntBoolSlice = FlagBase[map[int][]bool, VPMap[int, []bool, VPInt[int], VPSlice[bool, VPBool[bool]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntBoolSliceV

type MapIntBoolSliceV = FlagBase[map[int][]bool, VPMap[int, []bool, VPInt[int], VPSlice[bool, VPBool[bool]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntBoolV

type MapIntBoolV = FlagBase[map[int]bool, VPMap[int, bool, VPInt[int], VPBool[bool]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntDuration

predefined flag types for "<int>=<scalar>" from command line.

type MapIntDurationSlice

type MapIntDurationSlice = FlagBase[map[int][]time.Duration, VPMap[int, []time.Duration, VPInt[int], VPSlice[time.Duration, VPDuration[time.Duration]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntDurationSliceV

type MapIntDurationSliceV = FlagBase[map[int][]time.Duration, VPMap[int, []time.Duration, VPInt[int], VPSlice[time.Duration, VPDuration[time.Duration]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntDurationSum

predefined flag types for "<int>=<scalar>" from command line.

type MapIntDurationSumV

predefined flag types for "<int>=<scalar>" from command line.

type MapIntDurationV

type MapIntDurationV = FlagBase[map[int]time.Duration, VPMap[int, time.Duration, VPInt[int], VPDuration[time.Duration]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntFloat32

type MapIntFloat32 = FlagBase[map[int]float32, VPMap[int, float32, VPInt[int], VPFloat[float32]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntFloat32Slice

type MapIntFloat32Slice = FlagBase[map[int][]float32, VPMap[int, []float32, VPInt[int], VPSlice[float32, VPFloat[float32]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntFloat32SliceV

type MapIntFloat32SliceV = FlagBase[map[int][]float32, VPMap[int, []float32, VPInt[int], VPSlice[float32, VPFloat[float32]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntFloat32Sum

type MapIntFloat32Sum = FlagBase[map[int]float32, VPMap[int, float32, VPInt[int], VPSum[float32, VPFloat[float32]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntFloat32SumV

type MapIntFloat32SumV = FlagBase[map[int]float32, VPMap[int, float32, VPInt[int], VPSum[float32, VPFloat[float32]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntFloat32V

type MapIntFloat32V = FlagBase[map[int]float32, VPMap[int, float32, VPInt[int], VPFloat[float32]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntFloat64

type MapIntFloat64 = FlagBase[map[int]float64, VPMap[int, float64, VPInt[int], VPFloat[float64]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntFloat64Slice

type MapIntFloat64Slice = FlagBase[map[int][]float64, VPMap[int, []float64, VPInt[int], VPSlice[float64, VPFloat[float64]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntFloat64SliceV

type MapIntFloat64SliceV = FlagBase[map[int][]float64, VPMap[int, []float64, VPInt[int], VPSlice[float64, VPFloat[float64]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntFloat64Sum

type MapIntFloat64Sum = FlagBase[map[int]float64, VPMap[int, float64, VPInt[int], VPSum[float64, VPFloat[float64]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntFloat64SumV

type MapIntFloat64SumV = FlagBase[map[int]float64, VPMap[int, float64, VPInt[int], VPSum[float64, VPFloat[float64]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntFloat64V

type MapIntFloat64V = FlagBase[map[int]float64, VPMap[int, float64, VPInt[int], VPFloat[float64]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntInt

type MapIntInt = FlagBase[map[int]int, VPMap[int, int, VPInt[int], VPInt[int]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntInt16

type MapIntInt16 = FlagBase[map[int]int16, VPMap[int, int16, VPInt[int], VPInt[int16]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntInt16Slice

type MapIntInt16Slice = FlagBase[map[int][]int16, VPMap[int, []int16, VPInt[int], VPSlice[int16, VPInt[int16]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntInt16SliceV

type MapIntInt16SliceV = FlagBase[map[int][]int16, VPMap[int, []int16, VPInt[int], VPSlice[int16, VPInt[int16]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntInt16Sum

type MapIntInt16Sum = FlagBase[map[int]int16, VPMap[int, int16, VPInt[int], VPSum[int16, VPInt[int16]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntInt16SumV

type MapIntInt16SumV = FlagBase[map[int]int16, VPMap[int, int16, VPInt[int], VPSum[int16, VPInt[int16]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntInt16V

type MapIntInt16V = FlagBase[map[int]int16, VPMap[int, int16, VPInt[int], VPInt[int16]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntInt32

type MapIntInt32 = FlagBase[map[int]int32, VPMap[int, int32, VPInt[int], VPInt[int32]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntInt32Slice

type MapIntInt32Slice = FlagBase[map[int][]int32, VPMap[int, []int32, VPInt[int], VPSlice[int32, VPInt[int32]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntInt32SliceV

type MapIntInt32SliceV = FlagBase[map[int][]int32, VPMap[int, []int32, VPInt[int], VPSlice[int32, VPInt[int32]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntInt32Sum

type MapIntInt32Sum = FlagBase[map[int]int32, VPMap[int, int32, VPInt[int], VPSum[int32, VPInt[int32]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntInt32SumV

type MapIntInt32SumV = FlagBase[map[int]int32, VPMap[int, int32, VPInt[int], VPSum[int32, VPInt[int32]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntInt32V

type MapIntInt32V = FlagBase[map[int]int32, VPMap[int, int32, VPInt[int], VPInt[int32]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntInt64

type MapIntInt64 = FlagBase[map[int]int64, VPMap[int, int64, VPInt[int], VPInt[int64]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntInt64Slice

type MapIntInt64Slice = FlagBase[map[int][]int64, VPMap[int, []int64, VPInt[int], VPSlice[int64, VPInt[int64]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntInt64SliceV

type MapIntInt64SliceV = FlagBase[map[int][]int64, VPMap[int, []int64, VPInt[int], VPSlice[int64, VPInt[int64]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntInt64Sum

type MapIntInt64Sum = FlagBase[map[int]int64, VPMap[int, int64, VPInt[int], VPSum[int64, VPInt[int64]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntInt64SumV

type MapIntInt64SumV = FlagBase[map[int]int64, VPMap[int, int64, VPInt[int], VPSum[int64, VPInt[int64]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntInt64V

type MapIntInt64V = FlagBase[map[int]int64, VPMap[int, int64, VPInt[int], VPInt[int64]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntInt8

type MapIntInt8 = FlagBase[map[int]int8, VPMap[int, int8, VPInt[int], VPInt[int8]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntInt8Slice

type MapIntInt8Slice = FlagBase[map[int][]int8, VPMap[int, []int8, VPInt[int], VPSlice[int8, VPInt[int8]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntInt8SliceV

type MapIntInt8SliceV = FlagBase[map[int][]int8, VPMap[int, []int8, VPInt[int], VPSlice[int8, VPInt[int8]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntInt8Sum

type MapIntInt8Sum = FlagBase[map[int]int8, VPMap[int, int8, VPInt[int], VPSum[int8, VPInt[int8]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntInt8SumV

type MapIntInt8SumV = FlagBase[map[int]int8, VPMap[int, int8, VPInt[int], VPSum[int8, VPInt[int8]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntInt8V

type MapIntInt8V = FlagBase[map[int]int8, VPMap[int, int8, VPInt[int], VPInt[int8]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntIntSlice

type MapIntIntSlice = FlagBase[map[int][]int, VPMap[int, []int, VPInt[int], VPSlice[int, VPInt[int]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntIntSliceV

type MapIntIntSliceV = FlagBase[map[int][]int, VPMap[int, []int, VPInt[int], VPSlice[int, VPInt[int]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntIntSum

type MapIntIntSum = FlagBase[map[int]int, VPMap[int, int, VPInt[int], VPSum[int, VPInt[int]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntIntSumV

type MapIntIntSumV = FlagBase[map[int]int, VPMap[int, int, VPInt[int], VPSum[int, VPInt[int]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntIntV

type MapIntIntV = FlagBase[map[int]int, VPMap[int, int, VPInt[int], VPInt[int]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntRegexp

predefined flag types for "<int>=<scalar>" from command line.

type MapIntRegexpNocase

predefined flag types for "<int>=<scalar>" from command line.

type MapIntRegexpNocaseSlice

predefined flag types for "<int>=<scalar>" from command line.

type MapIntRegexpNocaseSliceV

predefined flag types for "<int>=<scalar>" from command line.

type MapIntRegexpNocaseV

predefined flag types for "<int>=<scalar>" from command line.

type MapIntRegexpSlice

predefined flag types for "<int>=<scalar>" from command line.

type MapIntRegexpSliceV

predefined flag types for "<int>=<scalar>" from command line.

type MapIntRegexpV

predefined flag types for "<int>=<scalar>" from command line.

type MapIntSize

type MapIntSize = FlagBase[map[int]int64, VPMap[int, int64, VPInt[int], VPSize[int64]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntSizeSlice

type MapIntSizeSlice = FlagBase[map[int][]int64, VPMap[int, []int64, VPInt[int], VPSlice[int64, VPSize[int64]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntSizeSliceV

type MapIntSizeSliceV = FlagBase[map[int][]int64, VPMap[int, []int64, VPInt[int], VPSlice[int64, VPSize[int64]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntSizeSum

type MapIntSizeSum = FlagBase[map[int]int64, VPMap[int, int64, VPInt[int], VPSum[int64, VPSize[int64]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntSizeSumV

type MapIntSizeSumV = FlagBase[map[int]int64, VPMap[int, int64, VPInt[int], VPSum[int64, VPSize[int64]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntSizeV

type MapIntSizeV = FlagBase[map[int]int64, VPMap[int, int64, VPInt[int], VPSize[int64]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntString

type MapIntString = FlagBase[map[int]string, VPMap[int, string, VPInt[int], VPString[string]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntStringSlice

type MapIntStringSlice = FlagBase[map[int][]string, VPMap[int, []string, VPInt[int], VPSlice[string, VPString[string]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntStringSliceV

type MapIntStringSliceV = FlagBase[map[int][]string, VPMap[int, []string, VPInt[int], VPSlice[string, VPString[string]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntStringV

type MapIntStringV = FlagBase[map[int]string, VPMap[int, string, VPInt[int], VPString[string]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntTime

type MapIntTime = FlagBase[map[int]time.Time, VPMap[int, time.Time, VPInt[int], VPTime[time.Time]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntTimeSlice

type MapIntTimeSlice = FlagBase[map[int][]time.Time, VPMap[int, []time.Time, VPInt[int], VPSlice[time.Time, VPTime[time.Time]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntTimeSliceV

type MapIntTimeSliceV = FlagBase[map[int][]time.Time, VPMap[int, []time.Time, VPInt[int], VPSlice[time.Time, VPTime[time.Time]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntTimeV

type MapIntTimeV = FlagBase[map[int]time.Time, VPMap[int, time.Time, VPInt[int], VPTime[time.Time]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUint

type MapIntUint = FlagBase[map[int]uint, VPMap[int, uint, VPInt[int], VPUint[uint]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUint16

type MapIntUint16 = FlagBase[map[int]uint16, VPMap[int, uint16, VPInt[int], VPUint[uint16]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUint16Slice

type MapIntUint16Slice = FlagBase[map[int][]uint16, VPMap[int, []uint16, VPInt[int], VPSlice[uint16, VPUint[uint16]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUint16SliceV

type MapIntUint16SliceV = FlagBase[map[int][]uint16, VPMap[int, []uint16, VPInt[int], VPSlice[uint16, VPUint[uint16]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUint16Sum

type MapIntUint16Sum = FlagBase[map[int]uint16, VPMap[int, uint16, VPInt[int], VPSum[uint16, VPUint[uint16]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUint16SumV

type MapIntUint16SumV = FlagBase[map[int]uint16, VPMap[int, uint16, VPInt[int], VPSum[uint16, VPUint[uint16]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUint16V

type MapIntUint16V = FlagBase[map[int]uint16, VPMap[int, uint16, VPInt[int], VPUint[uint16]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUint32

type MapIntUint32 = FlagBase[map[int]uint32, VPMap[int, uint32, VPInt[int], VPUint[uint32]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUint32Slice

type MapIntUint32Slice = FlagBase[map[int][]uint32, VPMap[int, []uint32, VPInt[int], VPSlice[uint32, VPUint[uint32]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUint32SliceV

type MapIntUint32SliceV = FlagBase[map[int][]uint32, VPMap[int, []uint32, VPInt[int], VPSlice[uint32, VPUint[uint32]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUint32Sum

type MapIntUint32Sum = FlagBase[map[int]uint32, VPMap[int, uint32, VPInt[int], VPSum[uint32, VPUint[uint32]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUint32SumV

type MapIntUint32SumV = FlagBase[map[int]uint32, VPMap[int, uint32, VPInt[int], VPSum[uint32, VPUint[uint32]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUint32V

type MapIntUint32V = FlagBase[map[int]uint32, VPMap[int, uint32, VPInt[int], VPUint[uint32]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUint64

type MapIntUint64 = FlagBase[map[int]uint64, VPMap[int, uint64, VPInt[int], VPUint[uint64]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUint64Slice

type MapIntUint64Slice = FlagBase[map[int][]uint64, VPMap[int, []uint64, VPInt[int], VPSlice[uint64, VPUint[uint64]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUint64SliceV

type MapIntUint64SliceV = FlagBase[map[int][]uint64, VPMap[int, []uint64, VPInt[int], VPSlice[uint64, VPUint[uint64]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUint64Sum

type MapIntUint64Sum = FlagBase[map[int]uint64, VPMap[int, uint64, VPInt[int], VPSum[uint64, VPUint[uint64]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUint64SumV

type MapIntUint64SumV = FlagBase[map[int]uint64, VPMap[int, uint64, VPInt[int], VPSum[uint64, VPUint[uint64]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUint64V

type MapIntUint64V = FlagBase[map[int]uint64, VPMap[int, uint64, VPInt[int], VPUint[uint64]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUint8

type MapIntUint8 = FlagBase[map[int]uint8, VPMap[int, uint8, VPInt[int], VPUint[uint8]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUint8Slice

type MapIntUint8Slice = FlagBase[map[int][]uint8, VPMap[int, []uint8, VPInt[int], VPSlice[uint8, VPUint[uint8]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUint8SliceV

type MapIntUint8SliceV = FlagBase[map[int][]uint8, VPMap[int, []uint8, VPInt[int], VPSlice[uint8, VPUint[uint8]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUint8Sum

type MapIntUint8Sum = FlagBase[map[int]uint8, VPMap[int, uint8, VPInt[int], VPSum[uint8, VPUint[uint8]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUint8SumV

type MapIntUint8SumV = FlagBase[map[int]uint8, VPMap[int, uint8, VPInt[int], VPSum[uint8, VPUint[uint8]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUint8V

type MapIntUint8V = FlagBase[map[int]uint8, VPMap[int, uint8, VPInt[int], VPUint[uint8]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUintSlice

type MapIntUintSlice = FlagBase[map[int][]uint, VPMap[int, []uint, VPInt[int], VPSlice[uint, VPUint[uint]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUintSliceV

type MapIntUintSliceV = FlagBase[map[int][]uint, VPMap[int, []uint, VPInt[int], VPSlice[uint, VPUint[uint]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUintSum

type MapIntUintSum = FlagBase[map[int]uint, VPMap[int, uint, VPInt[int], VPSum[uint, VPUint[uint]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUintSumV

type MapIntUintSumV = FlagBase[map[int]uint, VPMap[int, uint, VPInt[int], VPSum[uint, VPUint[uint]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUintV

type MapIntUintV = FlagBase[map[int]uint, VPMap[int, uint, VPInt[int], VPUint[uint]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUintptr

type MapIntUintptr = FlagBase[map[int]uintptr, VPMap[int, uintptr, VPInt[int], VPUint[uintptr]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUintptrSlice

type MapIntUintptrSlice = FlagBase[map[int][]uintptr, VPMap[int, []uintptr, VPInt[int], VPSlice[uintptr, VPUint[uintptr]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUintptrSliceV

type MapIntUintptrSliceV = FlagBase[map[int][]uintptr, VPMap[int, []uintptr, VPInt[int], VPSlice[uintptr, VPUint[uintptr]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUintptrSum

type MapIntUintptrSum = FlagBase[map[int]uintptr, VPMap[int, uintptr, VPInt[int], VPSum[uintptr, VPUint[uintptr]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUintptrSumV

type MapIntUintptrSumV = FlagBase[map[int]uintptr, VPMap[int, uintptr, VPInt[int], VPSum[uintptr, VPUint[uintptr]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUintptrV

type MapIntUintptrV = FlagBase[map[int]uintptr, VPMap[int, uintptr, VPInt[int], VPUint[uintptr]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUnixMicro

type MapIntUnixMicro = FlagBase[map[int]int64, VPMap[int, int64, VPInt[int], VPUnixMicro[int64]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUnixMicroSlice

type MapIntUnixMicroSlice = FlagBase[map[int][]int64, VPMap[int, []int64, VPInt[int], VPSlice[int64, VPUnixMicro[int64]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUnixMicroSliceV

type MapIntUnixMicroSliceV = FlagBase[map[int][]int64, VPMap[int, []int64, VPInt[int], VPSlice[int64, VPUnixMicro[int64]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUnixMicroV

type MapIntUnixMicroV = FlagBase[map[int]int64, VPMap[int, int64, VPInt[int], VPUnixMicro[int64]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUnixMilli

type MapIntUnixMilli = FlagBase[map[int]int64, VPMap[int, int64, VPInt[int], VPUnixMilli[int64]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUnixMilliSlice

type MapIntUnixMilliSlice = FlagBase[map[int][]int64, VPMap[int, []int64, VPInt[int], VPSlice[int64, VPUnixMilli[int64]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUnixMilliSliceV

type MapIntUnixMilliSliceV = FlagBase[map[int][]int64, VPMap[int, []int64, VPInt[int], VPSlice[int64, VPUnixMilli[int64]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUnixMilliV

type MapIntUnixMilliV = FlagBase[map[int]int64, VPMap[int, int64, VPInt[int], VPUnixMilli[int64]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUnixNano

type MapIntUnixNano = FlagBase[map[int]int64, VPMap[int, int64, VPInt[int], VPUnixNano[int64]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUnixNanoSlice

type MapIntUnixNanoSlice = FlagBase[map[int][]int64, VPMap[int, []int64, VPInt[int], VPSlice[int64, VPUnixNano[int64]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUnixNanoSliceV

type MapIntUnixNanoSliceV = FlagBase[map[int][]int64, VPMap[int, []int64, VPInt[int], VPSlice[int64, VPUnixNano[int64]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUnixNanoV

type MapIntUnixNanoV = FlagBase[map[int]int64, VPMap[int, int64, VPInt[int], VPUnixNano[int64]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUnixSec

type MapIntUnixSec = FlagBase[map[int]int64, VPMap[int, int64, VPInt[int], VPUnixSec[int64]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUnixSecSlice

type MapIntUnixSecSlice = FlagBase[map[int][]int64, VPMap[int, []int64, VPInt[int], VPSlice[int64, VPUnixSec[int64]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUnixSecSliceV

type MapIntUnixSecSliceV = FlagBase[map[int][]int64, VPMap[int, []int64, VPInt[int], VPSlice[int64, VPUnixSec[int64]]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapIntUnixSecV

type MapIntUnixSecV = FlagBase[map[int]int64, VPMap[int, int64, VPInt[int], VPUnixSec[int64]]]

predefined flag types for "<int>=<scalar>" from command line.

type MapStringBool

type MapStringBool = FlagBase[map[string]bool, VPMap[string, bool, VPString[string], VPBool[bool]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringBoolSlice

type MapStringBoolSlice = FlagBase[map[string][]bool, VPMap[string, []bool, VPString[string], VPSlice[bool, VPBool[bool]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringBoolSliceV

type MapStringBoolSliceV = FlagBaseV[map[string][]bool, VPMap[string, []bool, VPString[string], VPSlice[bool, VPBool[bool]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringBoolV

type MapStringBoolV = FlagBaseV[map[string]bool, VPMap[string, bool, VPString[string], VPBool[bool]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringDuration

predefined flag types for "<string>=<scalar>" from command line.

type MapStringDurationSlice

predefined flag types for "<string>=<scalar>" from command line.

type MapStringDurationSliceV

predefined flag types for "<string>=<scalar>" from command line.

type MapStringDurationSum

predefined flag types for "<string>=<scalar>" from command line.

type MapStringDurationSumV

predefined flag types for "<string>=<scalar>" from command line.

type MapStringDurationV

predefined flag types for "<string>=<scalar>" from command line.

type MapStringFloat32

type MapStringFloat32 = FlagBase[map[string]float32, VPMap[string, float32, VPString[string], VPFloat[float32]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringFloat32Slice

type MapStringFloat32Slice = FlagBase[map[string][]float32, VPMap[string, []float32, VPString[string], VPSlice[float32, VPFloat[float32]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringFloat32SliceV

type MapStringFloat32SliceV = FlagBaseV[map[string][]float32, VPMap[string, []float32, VPString[string], VPSlice[float32, VPFloat[float32]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringFloat32Sum

type MapStringFloat32Sum = FlagBase[map[string]float32, VPMap[string, float32, VPString[string], VPSum[float32, VPFloat[float32]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringFloat32SumV

type MapStringFloat32SumV = FlagBaseV[map[string]float32, VPMap[string, float32, VPString[string], VPSum[float32, VPFloat[float32]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringFloat32V

type MapStringFloat32V = FlagBaseV[map[string]float32, VPMap[string, float32, VPString[string], VPFloat[float32]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringFloat64

type MapStringFloat64 = FlagBase[map[string]float64, VPMap[string, float64, VPString[string], VPFloat[float64]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringFloat64Slice

type MapStringFloat64Slice = FlagBase[map[string][]float64, VPMap[string, []float64, VPString[string], VPSlice[float64, VPFloat[float64]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringFloat64SliceV

type MapStringFloat64SliceV = FlagBaseV[map[string][]float64, VPMap[string, []float64, VPString[string], VPSlice[float64, VPFloat[float64]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringFloat64Sum

type MapStringFloat64Sum = FlagBase[map[string]float64, VPMap[string, float64, VPString[string], VPSum[float64, VPFloat[float64]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringFloat64SumV

type MapStringFloat64SumV = FlagBaseV[map[string]float64, VPMap[string, float64, VPString[string], VPSum[float64, VPFloat[float64]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringFloat64V

type MapStringFloat64V = FlagBaseV[map[string]float64, VPMap[string, float64, VPString[string], VPFloat[float64]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringInt

type MapStringInt = FlagBase[map[string]int, VPMap[string, int, VPString[string], VPInt[int]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringInt16

type MapStringInt16 = FlagBase[map[string]int16, VPMap[string, int16, VPString[string], VPInt[int16]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringInt16Slice

type MapStringInt16Slice = FlagBase[map[string][]int16, VPMap[string, []int16, VPString[string], VPSlice[int16, VPInt[int16]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringInt16SliceV

type MapStringInt16SliceV = FlagBaseV[map[string][]int16, VPMap[string, []int16, VPString[string], VPSlice[int16, VPInt[int16]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringInt16Sum

type MapStringInt16Sum = FlagBase[map[string]int16, VPMap[string, int16, VPString[string], VPSum[int16, VPInt[int16]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringInt16SumV

type MapStringInt16SumV = FlagBaseV[map[string]int16, VPMap[string, int16, VPString[string], VPSum[int16, VPInt[int16]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringInt16V

type MapStringInt16V = FlagBaseV[map[string]int16, VPMap[string, int16, VPString[string], VPInt[int16]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringInt32

type MapStringInt32 = FlagBase[map[string]int32, VPMap[string, int32, VPString[string], VPInt[int32]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringInt32Slice

type MapStringInt32Slice = FlagBase[map[string][]int32, VPMap[string, []int32, VPString[string], VPSlice[int32, VPInt[int32]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringInt32SliceV

type MapStringInt32SliceV = FlagBaseV[map[string][]int32, VPMap[string, []int32, VPString[string], VPSlice[int32, VPInt[int32]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringInt32Sum

type MapStringInt32Sum = FlagBase[map[string]int32, VPMap[string, int32, VPString[string], VPSum[int32, VPInt[int32]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringInt32SumV

type MapStringInt32SumV = FlagBaseV[map[string]int32, VPMap[string, int32, VPString[string], VPSum[int32, VPInt[int32]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringInt32V

type MapStringInt32V = FlagBaseV[map[string]int32, VPMap[string, int32, VPString[string], VPInt[int32]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringInt64

type MapStringInt64 = FlagBase[map[string]int64, VPMap[string, int64, VPString[string], VPInt[int64]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringInt64Slice

type MapStringInt64Slice = FlagBase[map[string][]int64, VPMap[string, []int64, VPString[string], VPSlice[int64, VPInt[int64]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringInt64SliceV

type MapStringInt64SliceV = FlagBaseV[map[string][]int64, VPMap[string, []int64, VPString[string], VPSlice[int64, VPInt[int64]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringInt64Sum

type MapStringInt64Sum = FlagBase[map[string]int64, VPMap[string, int64, VPString[string], VPSum[int64, VPInt[int64]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringInt64SumV

type MapStringInt64SumV = FlagBaseV[map[string]int64, VPMap[string, int64, VPString[string], VPSum[int64, VPInt[int64]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringInt64V

type MapStringInt64V = FlagBaseV[map[string]int64, VPMap[string, int64, VPString[string], VPInt[int64]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringInt8

type MapStringInt8 = FlagBase[map[string]int8, VPMap[string, int8, VPString[string], VPInt[int8]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringInt8Slice

type MapStringInt8Slice = FlagBase[map[string][]int8, VPMap[string, []int8, VPString[string], VPSlice[int8, VPInt[int8]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringInt8SliceV

type MapStringInt8SliceV = FlagBaseV[map[string][]int8, VPMap[string, []int8, VPString[string], VPSlice[int8, VPInt[int8]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringInt8Sum

type MapStringInt8Sum = FlagBase[map[string]int8, VPMap[string, int8, VPString[string], VPSum[int8, VPInt[int8]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringInt8SumV

type MapStringInt8SumV = FlagBaseV[map[string]int8, VPMap[string, int8, VPString[string], VPSum[int8, VPInt[int8]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringInt8V

type MapStringInt8V = FlagBaseV[map[string]int8, VPMap[string, int8, VPString[string], VPInt[int8]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringIntSlice

type MapStringIntSlice = FlagBase[map[string][]int, VPMap[string, []int, VPString[string], VPSlice[int, VPInt[int]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringIntSliceV

type MapStringIntSliceV = FlagBaseV[map[string][]int, VPMap[string, []int, VPString[string], VPSlice[int, VPInt[int]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringIntSum

type MapStringIntSum = FlagBase[map[string]int, VPMap[string, int, VPString[string], VPSum[int, VPInt[int]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringIntSumV

type MapStringIntSumV = FlagBaseV[map[string]int, VPMap[string, int, VPString[string], VPSum[int, VPInt[int]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringIntV

type MapStringIntV = FlagBaseV[map[string]int, VPMap[string, int, VPString[string], VPInt[int]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringRegexp

predefined flag types for "<string>=<scalar>" from command line.

type MapStringRegexpNocase

predefined flag types for "<string>=<scalar>" from command line.

type MapStringRegexpNocaseSlice

predefined flag types for "<string>=<scalar>" from command line.

type MapStringRegexpNocaseSliceV

predefined flag types for "<string>=<scalar>" from command line.

type MapStringRegexpNocaseV

predefined flag types for "<string>=<scalar>" from command line.

type MapStringRegexpSlice

predefined flag types for "<string>=<scalar>" from command line.

type MapStringRegexpSliceV

predefined flag types for "<string>=<scalar>" from command line.

type MapStringRegexpV

predefined flag types for "<string>=<scalar>" from command line.

type MapStringSize

type MapStringSize = FlagBase[map[string]int64, VPMap[string, int64, VPString[string], VPSize[int64]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringSizeSlice

type MapStringSizeSlice = FlagBase[map[string][]int64, VPMap[string, []int64, VPString[string], VPSlice[int64, VPSize[int64]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringSizeSliceV

type MapStringSizeSliceV = FlagBaseV[map[string][]int64, VPMap[string, []int64, VPString[string], VPSlice[int64, VPSize[int64]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringSizeSum

type MapStringSizeSum = FlagBase[map[string]int64, VPMap[string, int64, VPString[string], VPSum[int64, VPSize[int64]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringSizeSumV

type MapStringSizeSumV = FlagBaseV[map[string]int64, VPMap[string, int64, VPString[string], VPSum[int64, VPSize[int64]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringSizeV

type MapStringSizeV = FlagBaseV[map[string]int64, VPMap[string, int64, VPString[string], VPSize[int64]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringString

type MapStringString = FlagBase[map[string]string, VPMap[string, string, VPString[string], VPString[string]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringStringSlice

type MapStringStringSlice = FlagBase[map[string][]string, VPMap[string, []string, VPString[string], VPSlice[string, VPString[string]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringStringSliceV

type MapStringStringSliceV = FlagBaseV[map[string][]string, VPMap[string, []string, VPString[string], VPSlice[string, VPString[string]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringStringV

type MapStringStringV = FlagBaseV[map[string]string, VPMap[string, string, VPString[string], VPString[string]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringTime

type MapStringTime = FlagBase[map[string]time.Time, VPMap[string, time.Time, VPString[string], VPTime[time.Time]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringTimeSlice

type MapStringTimeSlice = FlagBase[map[string][]time.Time, VPMap[string, []time.Time, VPString[string], VPSlice[time.Time, VPTime[time.Time]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringTimeSliceV

type MapStringTimeSliceV = FlagBaseV[map[string][]time.Time, VPMap[string, []time.Time, VPString[string], VPSlice[time.Time, VPTime[time.Time]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringTimeV

type MapStringTimeV = FlagBaseV[map[string]time.Time, VPMap[string, time.Time, VPString[string], VPTime[time.Time]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUint

type MapStringUint = FlagBase[map[string]uint, VPMap[string, uint, VPString[string], VPUint[uint]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUint16

type MapStringUint16 = FlagBase[map[string]uint16, VPMap[string, uint16, VPString[string], VPUint[uint16]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUint16Slice

type MapStringUint16Slice = FlagBase[map[string][]uint16, VPMap[string, []uint16, VPString[string], VPSlice[uint16, VPUint[uint16]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUint16SliceV

type MapStringUint16SliceV = FlagBaseV[map[string][]uint16, VPMap[string, []uint16, VPString[string], VPSlice[uint16, VPUint[uint16]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUint16Sum

type MapStringUint16Sum = FlagBase[map[string]uint16, VPMap[string, uint16, VPString[string], VPSum[uint16, VPUint[uint16]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUint16SumV

type MapStringUint16SumV = FlagBaseV[map[string]uint16, VPMap[string, uint16, VPString[string], VPSum[uint16, VPUint[uint16]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUint16V

type MapStringUint16V = FlagBaseV[map[string]uint16, VPMap[string, uint16, VPString[string], VPUint[uint16]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUint32

type MapStringUint32 = FlagBase[map[string]uint32, VPMap[string, uint32, VPString[string], VPUint[uint32]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUint32Slice

type MapStringUint32Slice = FlagBase[map[string][]uint32, VPMap[string, []uint32, VPString[string], VPSlice[uint32, VPUint[uint32]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUint32SliceV

type MapStringUint32SliceV = FlagBaseV[map[string][]uint32, VPMap[string, []uint32, VPString[string], VPSlice[uint32, VPUint[uint32]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUint32Sum

type MapStringUint32Sum = FlagBase[map[string]uint32, VPMap[string, uint32, VPString[string], VPSum[uint32, VPUint[uint32]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUint32SumV

type MapStringUint32SumV = FlagBaseV[map[string]uint32, VPMap[string, uint32, VPString[string], VPSum[uint32, VPUint[uint32]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUint32V

type MapStringUint32V = FlagBaseV[map[string]uint32, VPMap[string, uint32, VPString[string], VPUint[uint32]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUint64

type MapStringUint64 = FlagBase[map[string]uint64, VPMap[string, uint64, VPString[string], VPUint[uint64]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUint64Slice

type MapStringUint64Slice = FlagBase[map[string][]uint64, VPMap[string, []uint64, VPString[string], VPSlice[uint64, VPUint[uint64]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUint64SliceV

type MapStringUint64SliceV = FlagBaseV[map[string][]uint64, VPMap[string, []uint64, VPString[string], VPSlice[uint64, VPUint[uint64]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUint64Sum

type MapStringUint64Sum = FlagBase[map[string]uint64, VPMap[string, uint64, VPString[string], VPSum[uint64, VPUint[uint64]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUint64SumV

type MapStringUint64SumV = FlagBaseV[map[string]uint64, VPMap[string, uint64, VPString[string], VPSum[uint64, VPUint[uint64]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUint64V

type MapStringUint64V = FlagBaseV[map[string]uint64, VPMap[string, uint64, VPString[string], VPUint[uint64]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUint8

type MapStringUint8 = FlagBase[map[string]uint8, VPMap[string, uint8, VPString[string], VPUint[uint8]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUint8Slice

type MapStringUint8Slice = FlagBase[map[string][]uint8, VPMap[string, []uint8, VPString[string], VPSlice[uint8, VPUint[uint8]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUint8SliceV

type MapStringUint8SliceV = FlagBaseV[map[string][]uint8, VPMap[string, []uint8, VPString[string], VPSlice[uint8, VPUint[uint8]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUint8Sum

type MapStringUint8Sum = FlagBase[map[string]uint8, VPMap[string, uint8, VPString[string], VPSum[uint8, VPUint[uint8]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUint8SumV

type MapStringUint8SumV = FlagBaseV[map[string]uint8, VPMap[string, uint8, VPString[string], VPSum[uint8, VPUint[uint8]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUint8V

type MapStringUint8V = FlagBaseV[map[string]uint8, VPMap[string, uint8, VPString[string], VPUint[uint8]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUintSlice

type MapStringUintSlice = FlagBase[map[string][]uint, VPMap[string, []uint, VPString[string], VPSlice[uint, VPUint[uint]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUintSliceV

type MapStringUintSliceV = FlagBaseV[map[string][]uint, VPMap[string, []uint, VPString[string], VPSlice[uint, VPUint[uint]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUintSum

type MapStringUintSum = FlagBase[map[string]uint, VPMap[string, uint, VPString[string], VPSum[uint, VPUint[uint]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUintSumV

type MapStringUintSumV = FlagBaseV[map[string]uint, VPMap[string, uint, VPString[string], VPSum[uint, VPUint[uint]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUintV

type MapStringUintV = FlagBaseV[map[string]uint, VPMap[string, uint, VPString[string], VPUint[uint]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUintptr

type MapStringUintptr = FlagBase[map[string]uintptr, VPMap[string, uintptr, VPString[string], VPUint[uintptr]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUintptrSlice

type MapStringUintptrSlice = FlagBase[map[string][]uintptr, VPMap[string, []uintptr, VPString[string], VPSlice[uintptr, VPUint[uintptr]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUintptrSliceV

type MapStringUintptrSliceV = FlagBaseV[map[string][]uintptr, VPMap[string, []uintptr, VPString[string], VPSlice[uintptr, VPUint[uintptr]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUintptrSum

type MapStringUintptrSum = FlagBase[map[string]uintptr, VPMap[string, uintptr, VPString[string], VPSum[uintptr, VPUint[uintptr]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUintptrSumV

type MapStringUintptrSumV = FlagBaseV[map[string]uintptr, VPMap[string, uintptr, VPString[string], VPSum[uintptr, VPUint[uintptr]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUintptrV

type MapStringUintptrV = FlagBaseV[map[string]uintptr, VPMap[string, uintptr, VPString[string], VPUint[uintptr]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUnixMicro

type MapStringUnixMicro = FlagBase[map[string]int64, VPMap[string, int64, VPString[string], VPUnixMicro[int64]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUnixMicroSlice

type MapStringUnixMicroSlice = FlagBase[map[string][]int64, VPMap[string, []int64, VPString[string], VPSlice[int64, VPUnixMicro[int64]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUnixMicroSliceV

type MapStringUnixMicroSliceV = FlagBaseV[map[string][]int64, VPMap[string, []int64, VPString[string], VPSlice[int64, VPUnixMicro[int64]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUnixMicroV

type MapStringUnixMicroV = FlagBaseV[map[string]int64, VPMap[string, int64, VPString[string], VPUnixMicro[int64]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUnixMilli

type MapStringUnixMilli = FlagBase[map[string]int64, VPMap[string, int64, VPString[string], VPUnixMilli[int64]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUnixMilliSlice

type MapStringUnixMilliSlice = FlagBase[map[string][]int64, VPMap[string, []int64, VPString[string], VPSlice[int64, VPUnixMilli[int64]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUnixMilliSliceV

type MapStringUnixMilliSliceV = FlagBaseV[map[string][]int64, VPMap[string, []int64, VPString[string], VPSlice[int64, VPUnixMilli[int64]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUnixMilliV

type MapStringUnixMilliV = FlagBaseV[map[string]int64, VPMap[string, int64, VPString[string], VPUnixMilli[int64]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUnixNano

type MapStringUnixNano = FlagBase[map[string]int64, VPMap[string, int64, VPString[string], VPUnixNano[int64]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUnixNanoSlice

type MapStringUnixNanoSlice = FlagBase[map[string][]int64, VPMap[string, []int64, VPString[string], VPSlice[int64, VPUnixNano[int64]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUnixNanoSliceV

type MapStringUnixNanoSliceV = FlagBaseV[map[string][]int64, VPMap[string, []int64, VPString[string], VPSlice[int64, VPUnixNano[int64]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUnixNanoV

type MapStringUnixNanoV = FlagBaseV[map[string]int64, VPMap[string, int64, VPString[string], VPUnixNano[int64]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUnixSec

type MapStringUnixSec = FlagBase[map[string]int64, VPMap[string, int64, VPString[string], VPUnixSec[int64]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUnixSecSlice

type MapStringUnixSecSlice = FlagBase[map[string][]int64, VPMap[string, []int64, VPString[string], VPSlice[int64, VPUnixSec[int64]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUnixSecSliceV

type MapStringUnixSecSliceV = FlagBaseV[map[string][]int64, VPMap[string, []int64, VPString[string], VPSlice[int64, VPUnixSec[int64]]]]

predefined flag types for "<string>=<scalar>" from command line.

type MapStringUnixSecV

type MapStringUnixSecV = FlagBaseV[map[string]int64, VPMap[string, int64, VPString[string], VPUnixSec[int64]]]

predefined flag types for "<string>=<scalar>" from command line.

type MultiIndexer

type MultiIndexer struct {
	Flags []FlagFinderMaybeIter
}

MultiIndexer combines multiple FlagFinders into one.

func (*MultiIndexer) FindFlag

func (m *MultiIndexer) FindFlag(name string) (f Flag, ok bool)

FindFlag implements FlagFinder.

func (*MultiIndexer) NthFlag

func (m *MultiIndexer) NthFlag(i int) (info FlagInfo, ok bool)

NthFlag implements FlagIter.

type MultiRule

type MultiRule struct {
	Rules []Rule
}

MultiRule

func (*MultiRule) Contains

func (r *MultiRule) Contains(key string) bool

func (*MultiRule) NthEx

func (r *MultiRule) NthEx(f Inspector, i int) (Violation, bool)

NthEx implements Rule.

func (*MultiRule) Requires

func (r *MultiRule) Requires(key string) bool

func (*MultiRule) WriteFlagRule

func (r *MultiRule) WriteFlagRule(out io.Writer, keys ...string) (n int, err error)

type ParseErrorHandleFunc

type ParseErrorHandleFunc = func(opts *ParseOptions, args []string, posErrArg int, parseErr error) (err error)

ParseErrorHandleFunc handles the parseErr when parsing args[posErrArg].

Return nil to ignore the parseErr and continue parsing.

type ParseOptions

type ParseOptions struct {
	// StartTime is assumed to be the time of parsing start.
	StartTime time.Time

	// HandleParseError is the function to handle flag parsing errors.
	HandleParseError ParseErrorHandleFunc

	// PosArgsBuf is the buffer used by ParseFlags{,LowLevel} for appending
	// positional args.
	PosArgsBuf []string

	// HelpArgs are arg values can initiate help request.
	//
	//	- HelpArgs = nil, is equivalent to HelpArgs = []string{"--help", "-h", "help"}.
	//	- HelpArgs = []string{} will disable the help system.
	//	- otherwise, use the supplied HelpArgs to match args.
	HelpArgs []string

	// Extra custom data.
	Extra any
}

ParseOptions are options for flag parsing.

func (*ParseOptions) IsHelpArg

func (c *ParseOptions) IsHelpArg(x string) bool

IsHelpArg returns true if x is supposed to be an arg requesting help.

type PostRunFunc

type PostRunFunc = func(opts *CmdOptions, route Route, postrunAt int, runErr error) error

PostRunFunc

route is the full Cmd route leading to the target, and route[postrunAt] is the Cmd that owns this PostRun.

runErr is the error returned by the Run func and can only be non-nil when passed to the first PostRun (not necessarily the one from the target Cmd).

Returning an error cancels all subsequent PostRun call and the error will be returned by Cmd.Exec.

type PreRunFunc

type PreRunFunc = func(opts *CmdOptions, route Route, prerunAt int, posArgs, dashArgs []string) error

PreRunFunc

route is the full Cmd route leading to the target, and route[prerunAt] is the Cmd that owns this PreRun.

posArgs and dashArgs are meant for the target Cmd.

Return an error to cancel all subsequent PreRun calls and the error will be returned by Cmd.Exec.

type ReflectFlagRef

type ReflectFlagRef struct {
	Field   int
	Options string
	Flag    *FlagReflect
	Info    FlagInfo
}

type ReflectIndexer

type ReflectIndexer struct {
	// StructV is the reflect value of the addressable struct.
	StructV reflect.Value

	// Factory handles creation of VP[*reflect.Value]
	Factory ReflectVPFactory

	// Names maps name to index into Refs
	Names map[string]int

	// Refs are cached flags in struct field order
	Refs []ReflectFlagRef

	// TotalFlags is the count of flags in StructV
	//
	// When = 0: count unknown
	// When < 0: no flag
	// When > 0: n flags, len(Refs) = TotalFlags
	TotalFlags int
}

A ReflectIndexer creates and caches flags on request using reflection.

Under most circumstances, an application runs with no more than 15 args but can have way more flags available, when dynamic allocation and reflection (binary size) is not a concern, a ReflectIndexer can speedup both your development and application startup.

Struct field tag specification

`cli:"<long name>|<shorthand>[,comp=<completion>][,value=<type>][,key=<type>][,def=<default>][,hide][,once][,#<brief usage>]"`

Text before the first comma (',') is interpreted as flag name section, it SHOULD contain at most two names (one long name and one shorthand), use pipe ('|') to separate names.

Text after the first comma and before the sharp ('#') is interpreted as flag options, currently there are six options available:

  • comp=<completion>
  • value=<type>
  • key=<type>
  • def=<value>
  • hide
  • once

Option `comp` defines completion values, multiple `comp` option creates multiple CompItems, for example:

type Example struct{
    Foo string `cli:"foo,comp=value1,comp=value2"`
}

The ReflectIndexer will produce two CompItems for field Foo's command-line flag `--foo`:

  • value1
  • value2

Option `value` is used to change the method used to decode text arg and can have one of following `<type>` values when using DefaultReflectVPFactory:

  • size (size value, example command-line arg: "1TB", "1g1M")
  • dur (duration value, example command-line arg: "1yr", "1m10s")
  • sum (sums numeric values)
  • ssum (sums size values)
  • dsum (sums duration values)
  • regexp
  • regexp-nocase
  • time (decode time string, example command-line arg: "15:00", "21")
  • unix-ts (decode time string to seconds since the unix epoch)
  • unix-ms (decode time string to milliseconds since the unix epoch)
  • unix-us (decode time string to microseconds since the unix epoch)
  • unix-ns (decode time string to nanoseconds since the unix epoch)

Option `value`'s meaning varies depending on the field type:

  • scalar field: for that scalar field (e.g. `value=dur` for int64)
  • slice field: for slice element type (e.g. `value=unix-ts` for uint64 in []uint64)
  • map field: for map value type (e.g. `value=regexp` for *regexp.Regexp in map[K]*regexp.Regexp)

Option `key` is meant for map key, and works the same way as `value`. It can have one of following values when using DefaultReflectVPFactory:

  • size
  • dur
  • time
  • unix-ts
  • unix-ms
  • unix-us
  • unix-ns

Both option `value` and option `key` can present at most once in the tag value.

Option `def` defines a default value for the flag when flag is not set. There can be multiple `def` options.

Option `hide` marks the FlagState with FlagStateHidden. There can be no more than one `hide` option.

Option `once` marks the FlagState with FlagStateSetAtMostOnce. There can be no more than one `once` option.

The remaining text after the sharp sign ('#') after the first comma, is interpreted as the brief usage of the flag.

NOTE: Unexported fields and fields without a `cli` tag value are ignored.

func NewReflectIndexer

func NewReflectIndexer(factory ReflectVPFactory, pStruct any) *ReflectIndexer

NewReflectIndexer creates a new ReflectIndexer for the pointer to struct.

func (*ReflectIndexer) FindFlag

func (r *ReflectIndexer) FindFlag(s string) (Flag, bool)

func (*ReflectIndexer) NthFlag

func (r *ReflectIndexer) NthFlag(i int) (FlagInfo, bool)

type ReflectVPFactory

type ReflectVPFactory interface {
	GetVPReflectFor(fieldType reflect.Type, keyType, valueType string) (VP[*reflect.Value], error)
}

ReflectVPFactory handles creation of VP[*reflect.Value] for struct fields.

type Regexp

predefined flag types for scalar values from command line.

type RegexpNocase

predefined flag types for scalar values from command line.

type RegexpNocaseSlice

predefined flag types for slice values from command line.

type RegexpNocaseSliceV

predefined flag types for slice values from command line.

type RegexpNocaseV

predefined flag types for scalar values from command line.

type RegexpSlice

predefined flag types for slice values from command line.

type RegexpSliceV

predefined flag types for slice values from command line.

type RegexpV

predefined flag types for scalar values from command line.

type Route

type Route []*Cmd

Route contains the route leading from the root Cmd to the target Cmd.

func (*Route) CheckFlagValueChanged

func (p *Route) CheckFlagValueChanged(name string) bool

CheckFlagValueChanged implements Inspector.

func (*Route) FindFlag

func (p *Route) FindFlag(name string) (f Flag, ok bool)

FindFlag implements FlagFinder.

func (*Route) NthFlag

func (p *Route) NthFlag(i int) (info FlagInfo, ok bool)

NthFlag implements FlagIter

func (Route) Push

func (p Route) Push(cmd *Cmd) Route

Push appends a cmd to the route.

func (Route) Root

func (p Route) Root() *Cmd

Root returns the first entry in the route.

It returns nil if it is empty.

func (Route) Target

func (p Route) Target() *Cmd

Target returns the last *Cmd in route.

It returns nil if it is empty.

func (Route) Up

func (p Route) Up() Route

Up returns a Route containing all but the last *Cmd.

It returns nil if it is empty.

type Rule

type Rule interface {
	// Requires returns true if this rule requires Inspector.CheckFlagValueChanged() to
	// return true for this key to avoid violation.
	Requires(key string) bool

	// Contains returns true if the rule has something to do with the key.
	Contains(key string) bool

	// NthEx returns (i-th violation, true), if any, otherwise (_, false).
	NthEx(f Inspector, i int) (Violation, bool)

	// WriteFlagRule writes text representation of the rule.
	//
	// If len(keys) > 0, only add rule applies to at least one of the keys,
	// otherwise add all.
	WriteFlagRule(out io.Writer, keys ...string) (int, error)
}

Rule

func MergeFlagRules

func MergeFlagRules(rules ...Rule) Rule

MergeFlagRules merges multiple Rules into one.

type RuleAllOf

type RuleAllOf struct {
	Keys []string
}

func AllOf

func AllOf(keys ...string) *RuleAllOf

AllOf creates a *RuleAllOf from provided keys.

func (*RuleAllOf) Contains

func (r *RuleAllOf) Contains(key string) bool

func (*RuleAllOf) NthEx

func (r *RuleAllOf) NthEx(f Inspector, i int) (Violation, bool)

NthEx implements Rule.

func (*RuleAllOf) Requires

func (r *RuleAllOf) Requires(key string) bool

func (*RuleAllOf) WriteFlagRule

func (r *RuleAllOf) WriteFlagRule(out io.Writer, keys ...string) (n int, err error)

type RuleAllOrNone

type RuleAllOrNone struct {
	Keys []string
}

RuleAllOrNone represents a group of keys MUST either all set or all not set.

func AllOrNone

func AllOrNone(keys ...string) *RuleAllOrNone

AllOrNone creates a *RuleAllOrNone from provided keys.

func (*RuleAllOrNone) Contains

func (r *RuleAllOrNone) Contains(key string) bool

func (*RuleAllOrNone) NthEx

func (r *RuleAllOrNone) NthEx(f Inspector, i int) (Violation, bool)

NthEx implements Rule.

func (*RuleAllOrNone) Requires

func (r *RuleAllOrNone) Requires(key string) bool

func (*RuleAllOrNone) WriteFlagRule

func (r *RuleAllOrNone) WriteFlagRule(out io.Writer, keys ...string) (int, error)

type RuleAny

type RuleAny struct{}

RuleAny

func (RuleAny) Contains

func (RuleAny) Contains(key string) bool

func (RuleAny) NthEx

func (RuleAny) NthEx(Inspector, int) (Violation, bool)

func (RuleAny) Requires

func (RuleAny) Requires(key string) bool

func (RuleAny) WriteFlagRule

func (RuleAny) WriteFlagRule(io.Writer, ...string) (int, error)

type RuleAnyOf

type RuleAnyOf struct {
	Keys []string
}

RuleAnyOf represents a group of flags that at least one MUST present.

func AnyOf

func AnyOf(keys ...string) *RuleAnyOf

AnyOf creates a *RuleAnyOf from provided keys.

func (*RuleAnyOf) Contains

func (r *RuleAnyOf) Contains(key string) bool

func (*RuleAnyOf) NthEx

func (r *RuleAnyOf) NthEx(f Inspector, i int) (Violation, bool)

NthEx implements Rule.

func (*RuleAnyOf) Requires

func (r *RuleAnyOf) Requires(key string) bool

func (*RuleAnyOf) WriteFlagRule

func (r *RuleAnyOf) WriteFlagRule(out io.Writer, keys ...string) (int, error)

type RuleDepends

type RuleDepends[X, Y, Z Rule] struct {
	// If rules in `If` produces no violation, `Then` is used to decide
	// this rule has been satisfied if `Then` produces no violation.
	//
	// `Else` is used as `Then` if `If` produced violation.
	//
	// It is valid that `If` contains no rule.
	If   X
	Then Y
	Else Z
}

RuleDepends represents a group of flags required only when dependent rules are met.

func DependOn

func DependOn[X, Y, Z Rule](ifX X, thenY Y, elseZ Z) *RuleDepends[X, Y, Z]

DependOn creates a *RuleDepends from the given condition and branches.

func (*RuleDepends[X, Y, Z]) Contains

func (r *RuleDepends[X, Y, Z]) Contains(key string) bool

func (*RuleDepends[X, Y, Z]) NthEx

func (r *RuleDepends[X, Y, Z]) NthEx(f Inspector, i int) (p Violation, ok bool)

NthEx implements Rule.

func (*RuleDepends[X, Y, Z]) Requires

func (r *RuleDepends[X, Y, Z]) Requires(key string) bool

func (*RuleDepends[X, Y, Z]) WriteFlagRule

func (r *RuleDepends[X, Y, Z]) WriteFlagRule(out io.Writer, keys ...string) (n int, err error)

type RuleOneOf

type RuleOneOf struct {
	Keys []string
}

RuleOneOf defines a group of mutually exclusive flags.

func OneOf

func OneOf(keys ...string) *RuleOneOf

OneOf creates a *RuleOneOf from provided keys.

func (*RuleOneOf) Contains

func (r *RuleOneOf) Contains(key string) bool

func (*RuleOneOf) NthEx

func (r *RuleOneOf) NthEx(f Inspector, i int) (Violation, bool)

NthEx implements Rule.

func (*RuleOneOf) Requires

func (r *RuleOneOf) Requires(key string) bool

func (*RuleOneOf) WriteFlagRule

func (r *RuleOneOf) WriteFlagRule(out io.Writer, keys ...string) (int, error)

type RunFunc

type RunFunc = func(opts *CmdOptions, route Route, posArgs, dashArgs []string) error

RunFunc

function parameters' definition is the same as PreRun.

type Size

type Size = FlagBase[int64, VPSize[int64]]

predefined flag types for scalar values from command line.

type SizeSlice

type SizeSlice = FlagBase[[]int64, VPSlice[int64, VPSize[int64]]]

predefined flag types for slice values from command line.

type SizeSliceV

type SizeSliceV = FlagBaseV[[]int64, VPSlice[int64, VPSize[int64]]]

predefined flag types for slice values from command line.

type SizeSum

type SizeSum = FlagBase[int64, VPSum[int64, VPSize[int64]]]

predefined flag types for sumed scalar values from command line.

type SizeSumV

type SizeSumV = FlagBaseV[int64, VPSum[int64, VPSize[int64]]]

predefined flag types for sumed scalar values from command line.

type SizeV

type SizeV = FlagBaseV[int64, VPSize[int64]]

predefined flag types for scalar values from command line.

type String

type String = FlagBase[string, VPString[string]]

predefined flag types for scalar values from command line.

type StringSlice

type StringSlice = FlagBase[[]string, VPSlice[string, VPString[string]]]

predefined flag types for slice values from command line.

type StringSliceV

type StringSliceV = FlagBaseV[[]string, VPSlice[string, VPString[string]]]

predefined flag types for slice values from command line.

type StringV

type StringV = FlagBaseV[string, VPString[string]]

predefined flag types for scalar values from command line.

type Time

type Time = FlagBase[time.Time, VPTime[time.Time]]

predefined flag types for scalar values from command line.

type TimeSlice

type TimeSlice = FlagBase[[]time.Time, VPSlice[time.Time, VPTime[time.Time]]]

predefined flag types for slice values from command line.

type TimeSliceV

type TimeSliceV = FlagBaseV[[]time.Time, VPSlice[time.Time, VPTime[time.Time]]]

predefined flag types for slice values from command line.

type TimeV

type TimeV = FlagBaseV[time.Time, VPTime[time.Time]]

predefined flag types for scalar values from command line.

type Uint

type Uint = FlagBase[uint, VPUint[uint]]

predefined flag types for scalar values from command line.

type Uint16

type Uint16 = FlagBase[uint16, VPUint[uint16]]

predefined flag types for scalar values from command line.

type Uint16Slice

type Uint16Slice = FlagBase[[]uint16, VPSlice[uint16, VPUint[uint16]]]

predefined flag types for slice values from command line.

type Uint16SliceV

type Uint16SliceV = FlagBaseV[[]uint16, VPSlice[uint16, VPUint[uint16]]]

predefined flag types for slice values from command line.

type Uint16Sum

type Uint16Sum = FlagBase[uint16, VPSum[uint16, VPUint[uint16]]]

predefined flag types for sumed scalar values from command line.

type Uint16SumV

type Uint16SumV = FlagBaseV[uint16, VPSum[uint16, VPUint[uint16]]]

predefined flag types for sumed scalar values from command line.

type Uint16V

type Uint16V = FlagBaseV[uint16, VPUint[uint16]]

predefined flag types for scalar values from command line.

type Uint32

type Uint32 = FlagBase[uint32, VPUint[uint32]]

predefined flag types for scalar values from command line.

type Uint32Slice

type Uint32Slice = FlagBase[[]uint32, VPSlice[uint32, VPUint[uint32]]]

predefined flag types for slice values from command line.

type Uint32SliceV

type Uint32SliceV = FlagBaseV[[]uint32, VPSlice[uint32, VPUint[uint32]]]

predefined flag types for slice values from command line.

type Uint32Sum

type Uint32Sum = FlagBase[uint32, VPSum[uint32, VPUint[uint32]]]

predefined flag types for sumed scalar values from command line.

type Uint32SumV

type Uint32SumV = FlagBaseV[uint32, VPSum[uint32, VPUint[uint32]]]

predefined flag types for sumed scalar values from command line.

type Uint32V

type Uint32V = FlagBaseV[uint32, VPUint[uint32]]

predefined flag types for scalar values from command line.

type Uint64

type Uint64 = FlagBase[uint64, VPUint[uint64]]

predefined flag types for scalar values from command line.

type Uint64Slice

type Uint64Slice = FlagBase[[]uint64, VPSlice[uint64, VPUint[uint64]]]

predefined flag types for slice values from command line.

type Uint64SliceV

type Uint64SliceV = FlagBaseV[[]uint64, VPSlice[uint64, VPUint[uint64]]]

predefined flag types for slice values from command line.

type Uint64Sum

type Uint64Sum = FlagBase[uint64, VPSum[uint64, VPUint[uint64]]]

predefined flag types for sumed scalar values from command line.

type Uint64SumV

type Uint64SumV = FlagBaseV[uint64, VPSum[uint64, VPUint[uint64]]]

predefined flag types for sumed scalar values from command line.

type Uint64V

type Uint64V = FlagBaseV[uint64, VPUint[uint64]]

predefined flag types for scalar values from command line.

type Uint8

type Uint8 = FlagBase[uint8, VPUint[uint8]]

predefined flag types for scalar values from command line.

type Uint8Slice

type Uint8Slice = FlagBase[[]uint8, VPSlice[uint8, VPUint[uint8]]]

predefined flag types for slice values from command line.

type Uint8SliceV

type Uint8SliceV = FlagBaseV[[]uint8, VPSlice[uint8, VPUint[uint8]]]

predefined flag types for slice values from command line.

type Uint8Sum

type Uint8Sum = FlagBase[uint8, VPSum[uint8, VPUint[uint8]]]

predefined flag types for sumed scalar values from command line.

type Uint8SumV

type Uint8SumV = FlagBaseV[uint8, VPSum[uint8, VPUint[uint8]]]

predefined flag types for sumed scalar values from command line.

type Uint8V

type Uint8V = FlagBaseV[uint8, VPUint[uint8]]

predefined flag types for scalar values from command line.

type UintSlice

type UintSlice = FlagBase[[]uint, VPSlice[uint, VPUint[uint]]]

predefined flag types for slice values from command line.

type UintSliceV

type UintSliceV = FlagBaseV[[]uint, VPSlice[uint, VPUint[uint]]]

predefined flag types for slice values from command line.

type UintSum

type UintSum = FlagBase[uint, VPSum[uint, VPUint[uint]]]

predefined flag types for sumed scalar values from command line.

type UintSumV

type UintSumV = FlagBaseV[uint, VPSum[uint, VPUint[uint]]]

predefined flag types for sumed scalar values from command line.

type UintV

type UintV = FlagBaseV[uint, VPUint[uint]]

predefined flag types for scalar values from command line.

type Uintptr

type Uintptr = FlagBase[uintptr, VPUint[uintptr]]

predefined flag types for scalar values from command line.

type UintptrSlice

type UintptrSlice = FlagBase[[]uintptr, VPSlice[uintptr, VPUint[uintptr]]]

predefined flag types for slice values from command line.

type UintptrSliceV

type UintptrSliceV = FlagBaseV[[]uintptr, VPSlice[uintptr, VPUint[uintptr]]]

predefined flag types for slice values from command line.

type UintptrSum

type UintptrSum = FlagBase[uintptr, VPSum[uintptr, VPUint[uintptr]]]

predefined flag types for sumed scalar values from command line.

type UintptrSumV

type UintptrSumV = FlagBaseV[uintptr, VPSum[uintptr, VPUint[uintptr]]]

predefined flag types for sumed scalar values from command line.

type UintptrV

type UintptrV = FlagBaseV[uintptr, VPUint[uintptr]]

predefined flag types for scalar values from command line.

type UnixMicro

type UnixMicro = FlagBase[int64, VPUnixMicro[int64]]

predefined flag types for scalar values from command line.

type UnixMicroSlice

type UnixMicroSlice = FlagBase[[]int64, VPSlice[int64, VPUnixMicro[int64]]]

predefined flag types for slice values from command line.

type UnixMicroSliceV

type UnixMicroSliceV = FlagBaseV[[]int64, VPSlice[int64, VPUnixMicro[int64]]]

predefined flag types for slice values from command line.

type UnixMicroV

type UnixMicroV = FlagBaseV[int64, VPUnixMicro[int64]]

predefined flag types for scalar values from command line.

type UnixMilli

type UnixMilli = FlagBase[int64, VPUnixMilli[int64]]

predefined flag types for scalar values from command line.

type UnixMilliSlice

type UnixMilliSlice = FlagBase[[]int64, VPSlice[int64, VPUnixMilli[int64]]]

predefined flag types for slice values from command line.

type UnixMilliSliceV

type UnixMilliSliceV = FlagBaseV[[]int64, VPSlice[int64, VPUnixMilli[int64]]]

predefined flag types for slice values from command line.

type UnixMilliV

type UnixMilliV = FlagBaseV[int64, VPUnixMilli[int64]]

predefined flag types for scalar values from command line.

type UnixNano

type UnixNano = FlagBase[int64, VPUnixNano[int64]]

predefined flag types for scalar values from command line.

type UnixNanoSlice

type UnixNanoSlice = FlagBase[[]int64, VPSlice[int64, VPUnixNano[int64]]]

predefined flag types for slice values from command line.

type UnixNanoSliceV

type UnixNanoSliceV = FlagBaseV[[]int64, VPSlice[int64, VPUnixNano[int64]]]

predefined flag types for slice values from command line.

type UnixNanoV

type UnixNanoV = FlagBaseV[int64, VPUnixNano[int64]]

predefined flag types for scalar values from command line.

type UnixSec

type UnixSec = FlagBase[int64, VPUnixSec[int64]]

predefined flag types for scalar values from command line.

type UnixSecSlice

type UnixSecSlice = FlagBase[[]int64, VPSlice[int64, VPUnixSec[int64]]]

predefined flag types for slice values from command line.

type UnixSecSliceV

type UnixSecSliceV = FlagBaseV[[]int64, VPSlice[int64, VPUnixSec[int64]]]

predefined flag types for slice values from command line.

type UnixSecV

type UnixSecV = FlagBaseV[int64, VPUnixSec[int64]]

predefined flag types for scalar values from command line.

type VP

type VP[T any] interface {
	// Type returns the VPType handled by the VP.
	//
	// NOTE: It SHOULD return VPTypeUnkown for types cannot represented by
	// VPType, see definition of VPType for more details.
	Type() VPType

	// HasValue returns true if v is considered having value.
	HasValue(v T) bool

	// ParseValue parses an arg string as value of type T.
	//
	// NOTE: Implementation MUST handle nil ParseOptions.
	ParseValue(opts *ParseOptions, arg string, out T, set bool) error

	// PrintValue writes text representation of v to out.
	PrintValue(out io.Writer, value T) (int, error)
}

VP is the acronym for ValuePeeker, ValueParser and ValuePrinter.

type VPBool

type VPBool[T ~bool] struct{}

VPBool for types compatible with bool.

These args are considered true: "true", "yes", "y", "on", "1"

These args are considered false: "false", "no", "n", "off", "0"

All other values are invalid.

func (VPBool[T]) HasValue

func (VPBool[T]) HasValue(v *T) bool

func (VPBool[T]) ParseValue

func (VPBool[T]) ParseValue(opts *ParseOptions, arg string, out *T, set bool) error

func (VPBool[T]) PrintValue

func (VPBool[T]) PrintValue(out io.Writer, v *T) (int, error)

func (VPBool[T]) Type

func (VPBool[T]) Type() VPType

type VPDuration

type VPDuration[T integer] struct{}

VPDuration decoding duration values to nanoseconds integer. Only decimal numbers are supported, other number format may cause silent error.

Supported units:

  • `ns` (nanoseconds)
  • `us` (microseconds)
  • `ms` (milliseconds)
  • `s` (seconds)
  • `m` (minutes)
  • `h` or `hr` (hours)
  • `d` (days)
  • `w` (weeks)
  • `M` or `mt` (months)
  • `y` or `yr` (years)

For example:

1000ns, 200us, 100ms, 1s, 2m, 3h, 4d, 5w, 6M, 6y, 1d2h, 5w3d

NOTE: Months and years MUST be integer values, they are non-deterministic and are based on the time from opts.StartTime or time.Now(). All other units are deterministic.

func (VPDuration[T]) HasValue

func (VPDuration[T]) HasValue(v *T) bool

func (VPDuration[T]) ParseValue

func (VPDuration[T]) ParseValue(opts *ParseOptions, arg string, out *T, set bool) (err error)

func (VPDuration[T]) PrintValue

func (VPDuration[T]) PrintValue(out io.Writer, v *T) (int, error)

func (VPDuration[T]) Type

func (VPDuration[T]) Type() VPType

type VPFloat

type VPFloat[T float] struct{}

VPFloat for types compatible with float{32, 64}.

It uses strconv.ParseFloat to parse args.

func (VPFloat[T]) HasValue

func (VPFloat[T]) HasValue(v *T) bool

func (VPFloat[T]) ParseValue

func (VPFloat[T]) ParseValue(opts *ParseOptions, arg string, out *T, set bool) error

func (VPFloat[T]) PrintValue

func (VPFloat[T]) PrintValue(out io.Writer, value *T) (int, error)

func (VPFloat[T]) Type

func (VPFloat[T]) Type() VPType

type VPInt

type VPInt[T sinteger] struct{}

VPInt for types compatible with int{, 8, 16, 32, 64}.

It uses strconv.ParseInt to parse args.

func (VPInt[T]) HasValue

func (VPInt[T]) HasValue(v *T) bool

func (VPInt[T]) ParseValue

func (VPInt[T]) ParseValue(opts *ParseOptions, arg string, out *T, set bool) (err error)

func (VPInt[T]) PrintValue

func (VPInt[T]) PrintValue(out io.Writer, value *T) (n int, err error)

func (VPInt[T]) Type

func (VPInt[T]) Type() VPType

type VPMap

type VPMap[K comparable, E any, KP VP[*K], EP VP[*E]] struct {
	Key   KP
	Value EP
}

VPMap wraps other VPs for parsing map[K]E types.

It parses args as "key=value" pairs.

func (VPMap[K, E, KP, EP]) HasValue

func (m VPMap[K, E, KP, EP]) HasValue(v *map[K]E) bool

func (VPMap[K, E, KP, EP]) ParseValue

func (m VPMap[K, E, KP, EP]) ParseValue(opts *ParseOptions, arg string, out *map[K]E, set bool) (err error)

func (VPMap[K, E, KP, EP]) PrintValue

func (m VPMap[K, E, KP, EP]) PrintValue(out io.Writer, value *map[K]E) (n int, err error)

func (VPMap[K, E, KP, EP]) Type

func (m VPMap[K, E, KP, EP]) Type() VPType

type VPNop

type VPNop[T any] struct{}

VPNop does absolutely nothing.

func (VPNop[T]) HasValue

func (VPNop[T]) HasValue(v T) bool

func (VPNop[T]) ParseValue

func (VPNop[T]) ParseValue(*ParseOptions, string, T, bool) error

func (VPNop[T]) PrintValue

func (VPNop[T]) PrintValue(io.Writer, T) (int, error)

func (VPNop[T]) Type

func (VPNop[T]) Type() VPType

type VPPointer

type VPPointer[T any, P VP[*T]] struct{ Elem P }

VPPointer wraps other VP for parsing *T types.

func (VPPointer[T, P]) HasValue

func (p VPPointer[T, P]) HasValue(v **T) bool

func (VPPointer[T, P]) ParseValue

func (p VPPointer[T, P]) ParseValue(opts *ParseOptions, arg string, out **T, set bool) (err error)

func (VPPointer[T, P]) PrintValue

func (p VPPointer[T, P]) PrintValue(out io.Writer, v **T) (n int, err error)

func (VPPointer[T, P]) Type

func (p VPPointer[T, P]) Type() VPType

type VPReflectBool

type VPReflectBool struct{}

VPReflectBool is the reflect version of VPBool.

It accepts arbitrary depth of pointers.

func (VPReflectBool) HasValue

func (VPReflectBool) HasValue(v *reflect.Value) bool

func (VPReflectBool) ParseValue

func (VPReflectBool) ParseValue(opts *ParseOptions, arg string, value *reflect.Value, set bool) (err error)

func (VPReflectBool) PrintValue

func (VPReflectBool) PrintValue(out io.Writer, value *reflect.Value) (int, error)

func (VPReflectBool) Type

func (VPReflectBool) Type() VPType

type VPReflectDuration

type VPReflectDuration struct{}

VPReflectDuration is the reflect version of VPDuration.

It accepts arbitrary depth of pointers.

func (VPReflectDuration) HasValue

func (VPReflectDuration) HasValue(v *reflect.Value) bool

func (VPReflectDuration) ParseValue

func (VPReflectDuration) ParseValue(opts *ParseOptions, arg string, value *reflect.Value, set bool) (err error)

func (VPReflectDuration) PrintValue

func (VPReflectDuration) PrintValue(out io.Writer, value *reflect.Value) (int, error)

func (VPReflectDuration) Type

func (VPReflectDuration) Type() VPType

type VPReflectFloat

type VPReflectFloat struct{}

VPReflectFloat is the reflect version of VPFloat.

It accepts arbitrary depth of pointers.

func (VPReflectFloat) HasValue

func (VPReflectFloat) HasValue(v *reflect.Value) bool

func (VPReflectFloat) ParseValue

func (VPReflectFloat) ParseValue(opts *ParseOptions, arg string, value *reflect.Value, set bool) (err error)

func (VPReflectFloat) PrintValue

func (VPReflectFloat) PrintValue(out io.Writer, value *reflect.Value) (int, error)

func (VPReflectFloat) Type

func (VPReflectFloat) Type() VPType

type VPReflectInt

type VPReflectInt struct{}

VPReflectInt is the reflect version of VPInt.

It accepts arbitrary depth of pointers.

func (VPReflectInt) HasValue

func (VPReflectInt) HasValue(v *reflect.Value) bool

func (VPReflectInt) ParseValue

func (VPReflectInt) ParseValue(opts *ParseOptions, arg string, value *reflect.Value, set bool) (err error)

func (VPReflectInt) PrintValue

func (VPReflectInt) PrintValue(out io.Writer, value *reflect.Value) (int, error)

func (VPReflectInt) Type

func (VPReflectInt) Type() VPType

type VPReflectMap

type VPReflectMap[K, V VP[*reflect.Value]] struct {
	Key  K
	Elem V
}

VPReflectMap is the reflect version of VPMap.

It accepts arbitrary depth of pointers.

func (VPReflectMap[K, V]) HasValue

func (vp VPReflectMap[K, V]) HasValue(value *reflect.Value) bool

func (VPReflectMap[K, V]) ParseValue

func (vp VPReflectMap[K, V]) ParseValue(opts *ParseOptions, arg string, value *reflect.Value, set bool) (err error)

func (VPReflectMap[K, V]) PrintValue

func (vp VPReflectMap[K, V]) PrintValue(out io.Writer, value *reflect.Value) (n int, err error)

func (VPReflectMap[K, V]) Type

func (vp VPReflectMap[K, V]) Type() VPType

type VPReflectRegexp

type VPReflectRegexp struct{}

VPReflectRegexp is the reflect version of VPRegexp.

It accepts arbitrary depth of pointers.

func (VPReflectRegexp) HasValue

func (VPReflectRegexp) HasValue(v *reflect.Value) bool

func (VPReflectRegexp) ParseValue

func (VPReflectRegexp) ParseValue(opts *ParseOptions, arg string, value *reflect.Value, set bool) (err error)

func (VPReflectRegexp) PrintValue

func (VPReflectRegexp) PrintValue(out io.Writer, value *reflect.Value) (int, error)

func (VPReflectRegexp) Type

func (VPReflectRegexp) Type() VPType

type VPReflectRegexpNocase

type VPReflectRegexpNocase struct{}

VPReflectRegexpNocase is the reflect version of VPRegexpNocase.

It accepts arbitrary depth of pointers.

func (VPReflectRegexpNocase) HasValue

func (VPReflectRegexpNocase) HasValue(v *reflect.Value) bool

func (VPReflectRegexpNocase) ParseValue

func (VPReflectRegexpNocase) ParseValue(opts *ParseOptions, arg string, value *reflect.Value, set bool) (err error)

func (VPReflectRegexpNocase) PrintValue

func (VPReflectRegexpNocase) PrintValue(out io.Writer, value *reflect.Value) (int, error)

func (VPReflectRegexpNocase) Type

type VPReflectSize

type VPReflectSize struct{}

VPReflectSize is the reflect version of VPSize.

It accepts arbitrary depth of pointers.

func (VPReflectSize) HasValue

func (VPReflectSize) HasValue(v *reflect.Value) bool

func (VPReflectSize) ParseValue

func (VPReflectSize) ParseValue(opts *ParseOptions, arg string, value *reflect.Value, set bool) (err error)

func (VPReflectSize) PrintValue

func (VPReflectSize) PrintValue(out io.Writer, value *reflect.Value) (int, error)

func (VPReflectSize) Type

func (VPReflectSize) Type() VPType

type VPReflectSlice

type VPReflectSlice[EP VP[*reflect.Value]] struct{ Elem EP }

VPReflectSlice is the reflect version of VPSlice.

It accepts arbitrary depth of pointers.

func (VPReflectSlice[EP]) HasValue

func (vp VPReflectSlice[EP]) HasValue(value *reflect.Value) bool

func (VPReflectSlice[EP]) ParseValue

func (vp VPReflectSlice[EP]) ParseValue(opts *ParseOptions, arg string, value *reflect.Value, set bool) (err error)

func (VPReflectSlice[EP]) PrintValue

func (vp VPReflectSlice[EP]) PrintValue(out io.Writer, value *reflect.Value) (n int, err error)

func (VPReflectSlice[EP]) Type

func (vp VPReflectSlice[EP]) Type() VPType

type VPReflectString

type VPReflectString struct{}

VPReflectString is the reflect version of VPString.

It accepts arbitrary depth of pointers.

func (VPReflectString) HasValue

func (VPReflectString) HasValue(v *reflect.Value) bool

func (VPReflectString) ParseValue

func (VPReflectString) ParseValue(opts *ParseOptions, arg string, value *reflect.Value, set bool) (err error)

func (VPReflectString) PrintValue

func (VPReflectString) PrintValue(out io.Writer, value *reflect.Value) (int, error)

func (VPReflectString) Type

func (VPReflectString) Type() VPType

type VPReflectSum

type VPReflectSum[P VP[*reflect.Value]] struct{ VP P }

VPReflectSum is the reflect version of VPSum.

It accepts arbitrary depth of pointers.

func (VPReflectSum[P]) HasValue

func (VPReflectSum[P]) HasValue(v *reflect.Value) bool

func (VPReflectSum[P]) ParseValue

func (vp VPReflectSum[P]) ParseValue(opts *ParseOptions, arg string, value *reflect.Value, set bool) (err error)

func (VPReflectSum[P]) PrintValue

func (VPReflectSum[P]) PrintValue(out io.Writer, value *reflect.Value) (int, error)

func (VPReflectSum[P]) Type

func (vp VPReflectSum[P]) Type() VPType

type VPReflectTime

type VPReflectTime struct{}

VPReflectTime is the reflect version of VPTime.

It accepts arbitrary depth of pointers.

func (VPReflectTime) HasValue

func (VPReflectTime) HasValue(v *reflect.Value) bool

func (VPReflectTime) ParseValue

func (VPReflectTime) ParseValue(opts *ParseOptions, arg string, value *reflect.Value, set bool) (err error)

func (VPReflectTime) PrintValue

func (VPReflectTime) PrintValue(out io.Writer, value *reflect.Value) (int, error)

func (VPReflectTime) Type

func (VPReflectTime) Type() VPType

type VPReflectUint

type VPReflectUint struct{}

VPReflectUint is the reflect version of VPUint.

It accepts arbitrary depth of pointers.

func (VPReflectUint) HasValue

func (VPReflectUint) HasValue(v *reflect.Value) bool

func (VPReflectUint) ParseValue

func (VPReflectUint) ParseValue(opts *ParseOptions, arg string, value *reflect.Value, set bool) (err error)

func (VPReflectUint) PrintValue

func (VPReflectUint) PrintValue(out io.Writer, value *reflect.Value) (int, error)

func (VPReflectUint) Type

func (VPReflectUint) Type() VPType

type VPReflectUnixMicro

type VPReflectUnixMicro struct{}

VPReflectUnixMicro is the reflect version of VPUnixMicro.

It accepts arbitrary depth of pointers.

func (VPReflectUnixMicro) HasValue

func (VPReflectUnixMicro) HasValue(v *reflect.Value) bool

func (VPReflectUnixMicro) ParseValue

func (VPReflectUnixMicro) ParseValue(opts *ParseOptions, arg string, value *reflect.Value, set bool) (err error)

func (VPReflectUnixMicro) PrintValue

func (VPReflectUnixMicro) PrintValue(out io.Writer, value *reflect.Value) (int, error)

func (VPReflectUnixMicro) Type

func (VPReflectUnixMicro) Type() VPType

type VPReflectUnixMilli

type VPReflectUnixMilli struct{}

VPReflectUnixMilli is the reflect version of VPUnixMilli.

It accepts arbitrary depth of pointers.

func (VPReflectUnixMilli) HasValue

func (VPReflectUnixMilli) HasValue(v *reflect.Value) bool

func (VPReflectUnixMilli) ParseValue

func (VPReflectUnixMilli) ParseValue(opts *ParseOptions, arg string, value *reflect.Value, set bool) (err error)

func (VPReflectUnixMilli) PrintValue

func (VPReflectUnixMilli) PrintValue(out io.Writer, value *reflect.Value) (int, error)

func (VPReflectUnixMilli) Type

func (VPReflectUnixMilli) Type() VPType

type VPReflectUnixNano

type VPReflectUnixNano struct{}

VPReflectUnixNano is the reflect version of VPUnixNano.

It accepts arbitrary depth of pointers.

func (VPReflectUnixNano) HasValue

func (VPReflectUnixNano) HasValue(v *reflect.Value) bool

func (VPReflectUnixNano) ParseValue

func (VPReflectUnixNano) ParseValue(opts *ParseOptions, arg string, value *reflect.Value, set bool) (err error)

func (VPReflectUnixNano) PrintValue

func (VPReflectUnixNano) PrintValue(out io.Writer, value *reflect.Value) (int, error)

func (VPReflectUnixNano) Type

func (VPReflectUnixNano) Type() VPType

type VPReflectUnixSec

type VPReflectUnixSec struct{}

VPReflectUnixSec is the reflect version of VPUnixSec.

It accepts arbitrary depth of pointers.

func (VPReflectUnixSec) HasValue

func (VPReflectUnixSec) HasValue(v *reflect.Value) bool

func (VPReflectUnixSec) ParseValue

func (VPReflectUnixSec) ParseValue(opts *ParseOptions, arg string, value *reflect.Value, set bool) (err error)

func (VPReflectUnixSec) PrintValue

func (VPReflectUnixSec) PrintValue(out io.Writer, value *reflect.Value) (int, error)

func (VPReflectUnixSec) Type

func (VPReflectUnixSec) Type() VPType

type VPRegexp

type VPRegexp[T regexp.Regexp] struct{}

VPRegexp for types compatible regexp.Regexp.

When parsing, it compiles the arg as a regular expression using regexp.Compile.

func (VPRegexp[T]) HasValue

func (VPRegexp[T]) HasValue(v *T) bool

func (VPRegexp[T]) ParseValue

func (VPRegexp[T]) ParseValue(opts *ParseOptions, arg string, out *T, set bool) (err error)

func (VPRegexp[T]) PrintValue

func (VPRegexp[T]) PrintValue(out io.Writer, v *T) (int, error)

func (VPRegexp[T]) Type

func (VPRegexp[T]) Type() VPType

type VPRegexpNocase

type VPRegexpNocase[T regexp.Regexp] struct{}

VPRegexpNocase is VPRegexp but compiles pattern as case-insensitive.

By adding prefix `(?i:` and suffix `)`

func (VPRegexpNocase[T]) HasValue

func (VPRegexpNocase[T]) HasValue(v *T) bool

func (VPRegexpNocase[T]) ParseValue

func (VPRegexpNocase[T]) ParseValue(opts *ParseOptions, arg string, out *T, set bool) (err error)

func (VPRegexpNocase[T]) PrintValue

func (VPRegexpNocase[T]) PrintValue(out io.Writer, v *T) (int, error)

func (VPRegexpNocase[T]) Type

func (VPRegexpNocase[T]) Type() VPType

type VPSize

type VPSize[T integer] struct{}

VPSize for size strings with suffix:

b, B, k, KB, g, GB, t, TB, p, PB, e, EB

parsed value is the size in bytes, size overflow will cause error

func (VPSize[T]) HasValue

func (VPSize[T]) HasValue(v *T) bool

func (VPSize[T]) ParseValue

func (VPSize[T]) ParseValue(opts *ParseOptions, arg string, out *T, set bool) (err error)

func (VPSize[T]) PrintValue

func (VPSize[T]) PrintValue(out io.Writer, value *T) (n int, err error)

func (VPSize[T]) Type

func (VPSize[T]) Type() VPType

type VPSlice

type VPSlice[Elem any, EP VP[*Elem]] struct{ Elem EP }

VPSlice wraps other VP for parsing []T types.

It appends value parsed by the inner VP to []T.

func (VPSlice[E, EP]) HasValue

func (s VPSlice[E, EP]) HasValue(v *[]E) bool

func (VPSlice[E, EP]) ParseValue

func (s VPSlice[E, EP]) ParseValue(opts *ParseOptions, arg string, out *[]E, set bool) (err error)

func (VPSlice[E, EP]) PrintValue

func (s VPSlice[E, EP]) PrintValue(out io.Writer, v *[]E) (n int, err error)

func (VPSlice[E, EP]) Type

func (s VPSlice[E, EP]) Type() VPType

type VPString

type VPString[T ~string] struct{}

VPString for types compatible with string.

It does nothing validating args, so all kinds of strings are accepted.

func (VPString[T]) HasValue

func (VPString[T]) HasValue(v *T) bool

func (VPString[T]) ParseValue

func (VPString[T]) ParseValue(opts *ParseOptions, arg string, out *T, set bool) error

func (VPString[T]) PrintValue

func (VPString[T]) PrintValue(out io.Writer, v *T) (int, error)

func (VPString[T]) Type

func (VPString[T]) Type() VPType

type VPSum

type VPSum[T num, P VP[*T]] struct{}

VPSum sums numeric values.

NOTE: It is not recommended to use VPSum with VPSlice, unless you known what you are doing.

func (VPSum[T, P]) HasValue

func (VPSum[T, P]) HasValue(v *T) bool

func (VPSum[T, P]) ParseValue

func (VPSum[T, P]) ParseValue(opts *ParseOptions, arg string, out *T, set bool) (err error)

func (VPSum[T, P]) PrintValue

func (VPSum[T, P]) PrintValue(out io.Writer, v *T) (int, error)

func (VPSum[T, P]) Type

func (VPSum[T, P]) Type() VPType

type VPTime

type VPTime[T time.Time] struct{}

VPTime for time values like:

  • 15:04
  • 2006-01-02
  • 2006-01-02T15:04:05
  • 2006-01-02T15:04:05Z07:00
  • 15:04:05
  • 15

To parse value, it uses opts.StartTime or time.Now() to fill missing date parts.

func (VPTime[T]) HasValue

func (VPTime[T]) HasValue(v *T) bool

func (VPTime[T]) ParseValue

func (VPTime[T]) ParseValue(opts *ParseOptions, arg string, out *T, set bool) (err error)

func (VPTime[T]) PrintValue

func (VPTime[T]) PrintValue(out io.Writer, v *T) (int, error)

func (VPTime[T]) Type

func (VPTime[T]) Type() VPType

type VPType

type VPType uint32

VPType represents the type a VP is handling.

It is limited to one of following types:

  • scalar type.
  • slice of scalar.
  • map of scalar (key) to scalar/slice (value).

Memory layout:

map elem variant: VPTypeMapElemVariantSlice/VPTypeMapElemVariantSum
       |
       |
0x     0     0     0     0     0     0     0     0
           [map key scalar]    |    [ value scalar ]
                               |
   type variant: VPTypeVariantSlice/VPTypeVariantSum as variant for the
                 value scalar, all bits on the left should be 0.
                 VPTypeVariantMap as variant for the whole type, in this
                 case, map elem variant is for the value scalar

       [   map only bits   ]
  (only used when type variant is map)
const (
	VPTypeUnknown VPType = iota
	VPTypeString
	VPTypeBool
	VPTypeInt
	VPTypeUint
	VPTypeFloat
	VPTypeSize
	VPTypeDuration
	VPTypeTime
	VPTypeTimestampUnixSec
	VPTypeTimestampUnixMilli
	VPTypeTimestampUnixMicro
	VPTypeTimestampUnixNano
	VPTypeRegexp
	VPTypeRegexpNocase

	VPTypeScalarMAX

	VPTypeElemScalarMASK VPType = 0x00000fff
	VPTypeKeyScalarMASK  VPType = 0x0fff0000

	// variant mask for the whole type
	VPTypeVariantMASK  VPType = 0x0000f000
	VPTypeVariantSlice VPType = 0x00001000
	VPTypeVariantSum   VPType = 0x00002000
	VPTypeVariantMap   VPType = 0x00003000

	// variant mask for the map value type (only used when VPTypeVariantMap is set)
	VPTypeMapElemVariantMASK  VPType = 0xf0000000
	VPTypeMapElemVariantSlice VPType = 0x10000000
	VPTypeMapElemVariantSum   VPType = 0x20000000

	VPTypeVariantShift        VPType = 12
	VPTypeKeyScalarShift      VPType = 16
	VPTypeMapElemVariantShift VPType = 28
)

func (VPType) String

func (t VPType) String() string

String returns an empty string if t is unknown.

type VPUint

type VPUint[T uinteger] struct{}

VPUint for types compatible with uint{, 8, 16, 32, 64, ptr}.

It uses strconv.ParseUint to parse args.

func (VPUint[T]) HasValue

func (VPUint[T]) HasValue(v *T) bool

func (VPUint[T]) ParseValue

func (VPUint[T]) ParseValue(opts *ParseOptions, arg string, out *T, set bool) (err error)

func (VPUint[T]) PrintValue

func (VPUint[T]) PrintValue(out io.Writer, value *T) (n int, err error)

func (VPUint[T]) Type

func (VPUint[T]) Type() VPType

type VPUnixMicro

type VPUnixMicro[T ~int64] struct{}

VPUnixMicro is like VPTime but the target value is microseconds since the unix epoch.

func (VPUnixMicro[T]) HasValue

func (VPUnixMicro[T]) HasValue(v *T) bool

func (VPUnixMicro[T]) ParseValue

func (VPUnixMicro[T]) ParseValue(opts *ParseOptions, arg string, out *T, set bool) (err error)

func (VPUnixMicro[T]) PrintValue

func (VPUnixMicro[T]) PrintValue(out io.Writer, value *T) (int, error)

func (VPUnixMicro[T]) Type

func (VPUnixMicro[T]) Type() VPType

type VPUnixMilli

type VPUnixMilli[T ~int64] struct{}

VPUnixMilli is like VPTime but the target value is milliseconds since the unix epoch.

func (VPUnixMilli[T]) HasValue

func (VPUnixMilli[T]) HasValue(v *T) bool

func (VPUnixMilli[T]) ParseValue

func (VPUnixMilli[T]) ParseValue(opts *ParseOptions, arg string, out *T, set bool) (err error)

func (VPUnixMilli[T]) PrintValue

func (VPUnixMilli[T]) PrintValue(out io.Writer, value *T) (int, error)

func (VPUnixMilli[T]) Type

func (VPUnixMilli[T]) Type() VPType

type VPUnixNano

type VPUnixNano[T ~int64] struct{}

VPUnixNano is like VPTime but the target value is nanoseconds since the unix epoch.

func (VPUnixNano[T]) HasValue

func (VPUnixNano[T]) HasValue(v *T) bool

func (VPUnixNano[T]) ParseValue

func (VPUnixNano[T]) ParseValue(opts *ParseOptions, arg string, out *T, set bool) (err error)

func (VPUnixNano[T]) PrintValue

func (VPUnixNano[T]) PrintValue(out io.Writer, value *T) (int, error)

func (VPUnixNano[T]) Type

func (VPUnixNano[T]) Type() VPType

type VPUnixSec

type VPUnixSec[T ~int64] struct{}

VPUnixSec is like VPTime but the target value is seconds since the unix epoch.

func (VPUnixSec[T]) HasValue

func (VPUnixSec[T]) HasValue(v *T) bool

func (VPUnixSec[T]) ParseValue

func (VPUnixSec[T]) ParseValue(opts *ParseOptions, arg string, out *T, set bool) (err error)

func (VPUnixSec[T]) PrintValue

func (VPUnixSec[T]) PrintValue(out io.Writer, value *T) (int, error)

func (VPUnixSec[T]) Type

func (VPUnixSec[T]) Type() VPType

type Violation

type Violation struct {
	Key    string
	Reason ViolationCode
}

type ViolationCode

type ViolationCode uint32
const (
	ViolationCodeNoViolation ViolationCode = iota

	ViolationCodeEmptyAllOf       // for RuleAllOf: none present.
	ViolationCodePartialAllOf     // for RuleAllOf: at least one present but not all present.
	ViolationCodePartialAllOrNone // for RuleAllOrNone: at least one present but not all present.
	ViolationCodeExcessiveOneOf   // for RuleOneOf: more than one present.
	ViolationCodeEmptyOneOf       // for RuleOneOf: none present.
	ViolationCodeEmptyAnyOf       // for RuleAnyOf: none present.
)

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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