flagutil

package
v1.3.9 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractFlagBool

func ExtractFlagBool(args []string, name string) (bool, []string, bool)

func ExtractFlagString

func ExtractFlagString(args []string, name string) (string, []string, bool)

func GetFlagBool

func GetFlagBool(args []string, name string) bool

func GetFlagString

func GetFlagString(args []string, name string) (string, bool)

func GetFlagValue

func GetFlagValue(args []string, name string, isBool bool) (string, []int, bool)

func ParseFlagSetSets

func ParseFlagSetSets(fs *flag.FlagSet, args []string, isBool map[string]bool) (unknownArgs, unnamedArgs, execArgs []string, _ error)

usefull to allow unknown flags to be collected, to possibly pass them to another program. The main issue is knowning which unknown flags are boolean that won't receive a value after space (ex: -mybool main.go, main.go is not an arg to mybool). In this case, the provided map allows to correct this without having to define the flags in the flagset.

Types

type Arg

type Arg struct {
	Name  string // can be empty if just a value
	Value string // can be empty if just a name
}

func (*Arg) String

func (a *Arg) String() string

type BoolFuncFlag

type BoolFuncFlag func(string) error

func (BoolFuncFlag) IsBoolFlag

func (v BoolFuncFlag) IsBoolFlag() bool

func (BoolFuncFlag) Set

func (v BoolFuncFlag) Set(s string) error

func (BoolFuncFlag) String

func (v BoolFuncFlag) String() string

type ParsedArgs

type ParsedArgs []*Arg

func ParseParsedArgs

func ParseParsedArgs(args []string, isBool map[string]bool) ParsedArgs

func (ParsedArgs) CommonSplit

func (pa ParsedArgs) CommonSplit() (ParsedArgs, ParsedArgs, ParsedArgs)

func (ParsedArgs) Get

func (pa ParsedArgs) Get(name string) (*Arg, bool)

func (ParsedArgs) Join

func (pa ParsedArgs) Join() []string

func (*ParsedArgs) Remove

func (pa *ParsedArgs) Remove(arg *Arg)

func (ParsedArgs) SplitAtDoubleDashExclude

func (pa ParsedArgs) SplitAtDoubleDashExclude() (ParsedArgs, ParsedArgs)

func (ParsedArgs) SplitAtFirstNamed

func (pa ParsedArgs) SplitAtFirstNamed() (ParsedArgs, ParsedArgs)

func (ParsedArgs) SplitAtFirstUnnamed

func (pa ParsedArgs) SplitAtFirstUnnamed() (ParsedArgs, ParsedArgs)

func (ParsedArgs) SplitAtNameExclude

func (pa ParsedArgs) SplitAtNameExclude(name string) (ParsedArgs, ParsedArgs)

type StringFuncFlag

type StringFuncFlag func(string) error

func (StringFuncFlag) Set

func (v StringFuncFlag) Set(s string) error

func (StringFuncFlag) String

func (v StringFuncFlag) String() string

Jump to

Keyboard shortcuts

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