app

package
v1.5.7 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Argument

type Argument interface {
	Parameter

	// Default 参数默认值
	Default() any

	// Target 绑定值
	Target() any

	// Text 默认显示文本
	Text() string

	// Required 是否是必填项
	Required() bool

	// Flag 解析出真正使用的参数
	Flag() Flag
}

Argument 参数

type Arguments

type Arguments []Argument

Arguments 参数列表

func (Arguments) Add

func (a Arguments) Add(required Argument, optionals ...Argument) (arguments Arguments)

func (Arguments) Append

func (a Arguments) Append(required Argument, optionals ...Argument) Arguments

func (Arguments) Flags

func (a Arguments) Flags() (flags []cli.Flag)

type Command

type Command interface {
	Parameter
	Stopper
	Lifecycle

	// Run 执行命令
	Run(ctx context.Context) error

	// Arguments 参数列表
	Arguments() Arguments

	// Subcommands 子命令列表
	Subcommands() Commands

	// Description 描述文字
	Description() string

	// Category 分类
	Category() string
}

Command 描述一个可以被执行的命令

type Commands

type Commands []Command

func (Commands) Cli

func (c Commands) Cli() (commands []*cli.Command)

type Flag

type Flag interface {
	fmt.Stringer

	// Apply 解析参数
	Apply(set *flag.FlagSet) error

	// Names 别名列表
	Names() []string

	// IsSet 是否可设置
	IsSet() bool
}

Flag 描述一个可以被解析的参数或者选项

type Lifecycle added in v0.4.1

type Lifecycle interface {
	// Before 程序启动前
	Before(ctx context.Context) error

	// After 程序启动后
	After(ctx context.Context) error
}

type Parameter

type Parameter interface {
	// Aliases 别名,可以是短名称也可以是长名称,比如一个叫version的命令,别名可以是[v,version]
	Aliases() []string

	// Name 名称
	Name() string

	// Usage 描述使用方法
	Usage() string

	// Hidden 是否在帮助信息或者显示命令时隐藏
	Hidden() bool
}

type Serve

type Serve interface {
	Stopper
	Lifecycle

	// Start 运行服务
	Start(ctx context.Context) (err error)

	// Name 服务名称
	Name() string
}

Serve 描述一个服务器 可以是Http服务器,也可以是gRPC服务器或者一个MQ的消费者 泛指一个可以长期执行的服务

type Stopper added in v0.4.0

type Stopper interface {
	// Stop 停止
	Stop(ctx context.Context) (err error)
}

Stopper 可停止

Jump to

Keyboard shortcuts

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