app

package
v0.0.0-...-f615dff Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetConfigIn

func SetConfigIn(in string)

SetConfigIn 设置配置文件路径

Types

type App

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

func NewApp

func NewApp(prefix, appname string, opts ...Option) *App

func (*App) Run

func (a *App) Run()

type Command

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

func (*Command) AddCommand

func (c *Command) AddCommand(cmd *Command)

func (*Command) AddCommands

func (c *Command) AddCommands(cmds ...*Command)

type CompletableOptions

type CompletableOptions interface {
	Complete() error
}

CompletableOptions 抽象可以完成/编译的options

type ConfigurableOptions

type ConfigurableOptions interface {
	ApplyFlags() []error
}

ConfigurableOptions 抽象用于从配置文件读取参数的配置选项。

type FlagSet

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

func (*FlagSet) Flags

func (fs *FlagSet) Flags(name string) *pflag.FlagSet

type FlagsIntf

type FlagsIntf interface {
	AddFlags(fs *pflag.FlagSet)
	Validate() []error
}

FlagsIntf 提供命令行接口,定义命令行的具体实现 该接口的实现由子配置结构体实现 例子:

type Options struct {
    MySQLOpts *MySQLOptions `json:"mysql" mapstructure:"mysql"`
}
type MySQLOptions struct {
	...
}
var _ Flags = &MySQLOptions{} // 实现了 FlagsIntf
... 这里省略实现函数

type FlagsOptions

type FlagsOptions interface {
	// Flags 添加命令行
	Flags() (fs FlagSet)
	// Validate 验证
	Validate() []error
}

FlagOptions 命令行读取配置

type Option

type Option func(*App)

func WithCommand

func WithCommand(use, short, long string) Option

WithCommand 设置命令行参数

func WithDefaultValidArgs

func WithDefaultValidArgs() Option

WithDefaultValidArgs set default valid args to valid non-flag arguments

func WithDescription

func WithDescription(desc string) Option

func WithFlags

func WithFlags(fi FlagsOptions) Option

func WithNoConfig

func WithNoConfig() Option

func WithRunFunc

func WithRunFunc(run RunFunc) Option

func WithVersion

func WithVersion(noVersion bool) Option

type OptionsIntf

OptionsIntf 提供Options接口,定义Options的具体实现

type PrintableOptions

type PrintableOptions interface {
	String() string
}

PrintableOptions 抽象可以打印的options

type RunCommandFunc

type RunCommandFunc func(args []string) error

type RunFunc

type RunFunc func(app string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳