flag

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: Apache-2.0 Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MapStringString

type MapStringString struct {
	Map *map[string]string

	NoSplit bool
	// contains filtered or unexported fields
}

MapStringString 可以设置为命令行格式 `--flag "string=string"`。 支持多个标志调用。例如:`--flag "a=foo" --flag "b=bar"`。如果希望这是唯一的类型调用,则应设置 `NoSplit` 为 true。 如果 `NoSplit` 设置为 false,则支持单个调用中的多个逗号分隔的键值对。例如:`--flag "a=foo,b=bar"`。

func NewMapStringString

func NewMapStringString(m *map[string]string) *MapStringString

NewMapStringString 创建一个 MapStringString 标志解析器 接受一个指向 map[string]string 的指针,并返回该 map 的 MapStringString 标志解析器

func NewMapStringStringNoSplit

func NewMapStringStringNoSplit(m *map[string]string) *MapStringString

NewMapStringStringNoSplit 创建一个 MapStringString 标志解析器 接受一个指向 map[string]string 的指针,并设置 `NoSplit` 为 true,然后返回该 map 的 MapStringString 标志解析器

func (*MapStringString) Empty

func (m *MapStringString) Empty() bool

Empty 实现 OmitEmpty.

func (*MapStringString) Set

func (m *MapStringString) Set(value string) error

Set 实现 github.com/spf13/pflag.Value.

func (*MapStringString) String

func (m *MapStringString) String() string

String 实现 github.com/spf13/pflag.Value.

func (*MapStringString) Type

func (*MapStringString) Type() string

Type 实现 github.com/spf13/pflag.Value.

type StringFlag

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

StringFlag 是一个字符串标志,兼容 flags 和 pflags,并跟踪是否提供了值

func NewStringFlag

func NewStringFlag(defaultVal string) StringFlag

NewStringFlag 创建一个字符串标志

func (*StringFlag) Default

func (f *StringFlag) Default(value string)

Default 设置默认值

func (StringFlag) Provided

func (f StringFlag) Provided() bool

Provided 返回标志是否被提供

func (*StringFlag) Set

func (f *StringFlag) Set(value string) error

Set 设置标志的值

func (StringFlag) String

func (f StringFlag) String() string

String 返回标志的值

func (*StringFlag) Type

func (f *StringFlag) Type() string

Type 返回标志的类型

func (StringFlag) Value

func (f StringFlag) Value() string

Value 返回标志的值

type Tristate

type Tristate int

Tristate 是一个标志,兼容 flags 和 pflags,并跟踪是否提供了值 注:也就是一个布尔值,但是可以设置为未设置、真、假

const (
	Unset Tristate = iota // 0
	True
	False
)

func (*Tristate) Default

func (f *Tristate) Default(value bool)

Default 设置默认值

func (Tristate) Provided

func (f Tristate) Provided() bool

Provided 返回标志是否被提供

func (*Tristate) Set

func (f *Tristate) Set(value string) error

Set 设置标志的值

func (Tristate) String

func (f Tristate) String() string

String 返回标志的值

func (*Tristate) Type

func (f *Tristate) Type() string

Type 返回标志的类型

func (Tristate) Value

func (f Tristate) Value() bool

Value 返回标志的值

Jump to

Keyboard shortcuts

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