flagx

package module
v0.0.0-...-82f96e9 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

README

flags

parse struct from command line and environments

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(strcutVal any, args []string, options ...func(flagSet *flag.FlagSet)) ([]string, error)

Parse 解析参数到struct

func Walk

func Walk(strcutVal any, walkFn func(item Flag))

Types

type App

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

func New

func New(args ...string) *App

func (*App) AddCommand

func (app *App) AddCommand(name string, command Command) *App

func (*App) Run

func (app *App) Run(ctx context.Context)

func (*App) Usage

func (app *App) Usage()

type Command

type Command interface {
	Run(ctx context.Context, args []string) error
}

type Flag

type Flag struct {
	Name        string   // 名称
	Aliases     []string // 别名
	Usage       string   // 用法说明
	EnvVars     []string // 关联环境变量
	Default     string   // 默认值字符串
	Deprecated  string   // 过期描述
	NoOptDefVal string   // 不带参数
	Required    bool     // 必须
	Hidden      bool     // 隐藏参数
	// contains filtered or unexported fields
}

func Struct

func Struct(strcutVal any) (flags []Flag)

将struct转换为参数标记集合

func (Flag) Get

func (v Flag) Get() any

func (Flag) GetSlice

func (v Flag) GetSlice() []string

func (Flag) IsBoolFlag

func (v Flag) IsBoolFlag() bool

func (Flag) IsZero

func (v Flag) IsZero() bool

func (Flag) KindString

func (v Flag) KindString() string

func (Flag) Set

func (v Flag) Set(s string) error

func (Flag) SetValue

func (v Flag) SetValue(x reflect.Value)

func (Flag) String

func (v Flag) String() string

Jump to

Keyboard shortcuts

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