flagx

package
v1.25.1 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Main = NewCommand("main", "根命令")

Main 根命令

Functions

func Execute

func Execute(args ...string) error

Execute 执行入口

func Register

func Register(commands ...*Command)

Register 注册子命令

Types

type Command

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

func NewCommand

func NewCommand(name, usage string) *Command

NewCommand 创建命令

func (*Command) AddOption

func (c *Command) AddOption(options ...Option) *Command

AddOption 添加参数

func (*Command) Execute

func (c *Command) Execute() error

Execute 执行命令

func (*Command) FlagSet

func (c *Command) FlagSet() *flag.FlagSet

FlagSet 初始化FlagSet并将参数注册到FlagSet

func (*Command) GetArg

func (c *Command) GetArg(index int) string

func (*Command) GetArgs

func (c *Command) GetArgs() []string

func (*Command) GetOptionValue

func (c *Command) GetOptionValue(name string) typex.Value

GetOptionValue 获取参数值

func (*Command) Join

func (c *Command) Join(command *Command) *Command

Join 添加父命令

func (*Command) Name

func (c *Command) Name() string

func (*Command) NeedHelp

func (c *Command) NeedHelp() bool

func (*Command) ParseArgs

func (c *Command) ParseArgs() error

ParseArgs 解析参数值到选项中

func (*Command) PrintOptions

func (c *Command) PrintOptions()

PrintOptions 打印命令选项

func (*Command) PrintSubs

func (c *Command) PrintSubs()

PrintSubs 打印子命令

func (*Command) Register

func (c *Command) Register()

func (*Command) SetExecutor

func (c *Command) SetExecutor(executor func() error) *Command

SetExecutor 设置执行器

type Option

type Option interface {
	Name() string
	Usage() string
	Set(fs *flag.FlagSet)
	Get() typex.Value
}

func BoolOption

func BoolOption(name, usage string, def bool) Option

func FloatOption

func FloatOption(name, usage string, def float64) Option

func Int64Option

func Int64Option(name, usage string, def int64) Option

func IntOption

func IntOption(name, usage string, def int) Option

func StringOption

func StringOption(name, usage string, def string) Option

Jump to

Keyboard shortcuts

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