cmdargs

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RoleFlag       Role = 1 << iota
	RoleBoolFlag        = 1 << iota // modifies RoleFlag
	RoleKnown           = 1 << iota // modifies RoleFlag or RoleFlagValue
	RoleInline          = 1 << iota // modifies RoleFlag
	RoleFlagValue       = 1 << iota
	RoleUnnamed         = 1 << iota
	RoleTerminator      = 1 << iota
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Args

type Args struct {
	Args []string
	// contains filtered or unexported fields
}

func NewArgs

func NewArgs(args []string) Args

func (Args) DeleteFlag

func (args Args) DeleteFlag(flagName string) (res Args, deleted bool)

func (Args) IterateEntries

func (args Args) IterateEntries(yield func(entry Entry) (getNext bool))

func (Args) IterateTokens

func (args Args) IterateTokens(yield func(info Token) bool)

func (Args) LookupFlag

func (args Args) LookupFlag(flagName string) (res FlagEntry, has bool)

func (Args) MapEntries

func (args Args) MapEntries(
	mapper func(Entry) Entry,
) Args

func (Args) MapFlags

func (args Args) MapFlags(
	mapper func(flag FlagEntry) (mapped Entry),
) Args

func (Args) StripUnknownFlags

func (args Args) StripUnknownFlags(
	ignoredFlagsWithKnownType stdutil.FormalTagNames,
) (res, stripped Args)

func (Args) UpsertFlag

func (args Args) UpsertFlag(
	insert FlagEntry,
	update func(old FlagEntry) (updated FlagEntry),
) Args

func (Args) WithAmbiguousAsBool

func (args Args) WithAmbiguousAsBool(ambiguousAsBool bool) Args

func (Args) WithFlagSet

func (args Args) WithFlagSet(flagSets ...*flag.FlagSet) Args

func (Args) WithKnownFlags

func (args Args) WithKnownFlags(knownFlags stdutil.FormalTagNames) Args

func (Args) WithoutKnownFlags

func (args Args) WithoutKnownFlags(knownFlagsToRemove stdutil.FormalTagNames) Args

type Entry

type Entry interface {
	String() string
	TokenStrings() []string
	TokensCount() int
	Kind() EntryKind
}

func NewTerminatorEntry

func NewTerminatorEntry() Entry

type EntryKind

type EntryKind int
const (
	EntryKindFlag EntryKind = iota
	EntryKindTerminator
	EntryKindUnnamedArgs
)

type FlagEntry

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

func NewBoolFlagEntry

func NewBoolFlagEntry(flagName, flagValue string) FlagEntry

func NewFlagEntry

func NewFlagEntry(flagName, flagValue string) FlagEntry

func (FlagEntry) Equals

func (f FlagEntry) Equals(other FlagEntry) bool

func (FlagEntry) IsBool

func (f FlagEntry) IsBool() bool

func (FlagEntry) IsDoubleDashed

func (f FlagEntry) IsDoubleDashed() bool

func (FlagEntry) IsInline

func (f FlagEntry) IsInline() bool

func (FlagEntry) Kind

func (f FlagEntry) Kind() EntryKind

func (FlagEntry) Name

func (f FlagEntry) Name() string

func (FlagEntry) String

func (f FlagEntry) String() string

func (FlagEntry) TokenStrings

func (f FlagEntry) TokenStrings() []string

func (FlagEntry) TokensCount

func (f FlagEntry) TokensCount() int

func (FlagEntry) Value

func (f FlagEntry) Value() string

func (FlagEntry) WithDoubleDashes

func (f FlagEntry) WithDoubleDashes(isDoubleDashed bool) FlagEntry

func (FlagEntry) WithInline

func (f FlagEntry) WithInline(isInline bool) FlagEntry

WithInline makes the flag inline or not inline If it was a bool flag and `isInline = false`, it becomes a non-bool flag with string value. In this case, if bool flag didn't have inline value, it will have empty string non-inline value If it was a bool flag with no value and `isInline = true`, explicit value "true" will be used

func (FlagEntry) WithName

func (f FlagEntry) WithName(name string) FlagEntry

func (FlagEntry) WithNoValue

func (f FlagEntry) WithNoValue() FlagEntry

WithNoValue makes the flag a bool flag with no value (equals true)

func (FlagEntry) WithValue

func (f FlagEntry) WithValue(value string) FlagEntry

type Role

type Role int

func (Role) Has

func (r Role) Has(role Role) bool

type TerminatorEntry

type TerminatorEntry struct{}

func (TerminatorEntry) Kind

func (tt TerminatorEntry) Kind() EntryKind

func (TerminatorEntry) String

func (tt TerminatorEntry) String() string

func (TerminatorEntry) TokenStrings

func (tt TerminatorEntry) TokenStrings() []string

func (TerminatorEntry) TokensCount

func (tt TerminatorEntry) TokensCount() int

type Token

type Token struct {
	Arg       string
	FlagName  string
	FlagValue string
	// Role is sum of Role constants. Possible values:
	// RoleFlag | RoleKnown | RoleInline                 // contains FlagValue
	// RoleFlag | RoleKnown | RoleBoolFlag               // no FlagValue, implicit `true`
	// RoleFlag | RoleKnown | RoleInline | RoleBoolFlag  // explicit bool string FlagValue
	// RoleFlag | RoleKnown                              // will be followed by value
	// RoleFlag | RoleInline                             // unknown, contains FlagValue
	// RoleFlag | RoleBoolFlag                           // unknown, located at the end, no FlagValue
	// RoleFlag                 //  unknown, it's ambiguous whether it's bool flag or flag name
	//                          //  On receiving it, yield function should decide how to treat it
	// RoleUnnamed
	// RoleFlagValue            // goes next after non-inline flag
	// RoleTerminator
	Role Role
}

type UnnamedArgsEntry

type UnnamedArgsEntry []string

func (UnnamedArgsEntry) Kind

func (ua UnnamedArgsEntry) Kind() EntryKind

func (UnnamedArgsEntry) String

func (ua UnnamedArgsEntry) String() string

func (UnnamedArgsEntry) TokenStrings

func (ua UnnamedArgsEntry) TokenStrings() []string

func (UnnamedArgsEntry) TokensCount

func (ua UnnamedArgsEntry) TokensCount() int

Jump to

Keyboard shortcuts

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