Documentation ¶
Index ¶
- Constants
- func CmdWait(ctx context.Context)
- func DefaultHelp(c *Command)
- func DefaultRun(c *Command)
- func GetArgIndex(a string) int
- func GetChildArg(a string) string
- func GoDirFmt(dir string)
- func GoFileFmt(path string, group *sync.WaitGroup)
- func IsInstalled() bool
- func IsShell(ctx context.Context) bool
- func Logger(c *Command) *glog.Logger
- func ScanAndLog(info ...interface{}) string
- func ScanMdFiles(path string) []string
- func ScanVar(message string, defaultValue string) *g.Var
- func ScanWithDefault(defaultValue string, info string) string
- func ScanWithDefaultN(info string, defaultValue string) string
- func ScanYesOrNo(info string, defaultValue ...string) bool
- func SelectConfig() string
- func SelectFile(path string, pattern string) string
- func SelectOne(options []string, msg string) (string, int)
- func SetChildCommand(parent ICommandBuilder, child ICommandBuilder) bool
- func SetDefaultCommand(parent ICommandBuilder)
- func SetDefaultFlag(cmd ICommandBuilder)
- func SetFlag(cmd ICommandBuilder, falg IFlagBuilder, group ...string) bool
- func TimeToClose(t int)
- func TimeToCloseShell(ctx context.Context, t int)
- type App
- type CmdHelpBuilder
- type CmdInstallBuilder
- type CmdShellBuilder
- type CmdVersionBuilder
- type Command
- func (c *Command) AddCommand(cmd *Command) bool
- func (c *Command) AddFlag(f *Flag) bool
- func (c *Command) Child(use string) *Command
- func (c *Command) Context() context.Context
- func (c *Command) Exec(ctx context.Context)
- func (c *Command) GetHelp() string
- func (c *Command) Parent() *Command
- func (c *Command) PrintHelp()
- func (c *Command) RunChildCmd(cmdUse string)
- func (c *Command) SetContext(ctx context.Context)
- func (c *Command) ShowHelp()
- type CommandBuilderCore
- func (b *CommandBuilderCore) Command() *Command
- func (b *CommandBuilderCore) Init(ctx context.Context)
- func (b *CommandBuilderCore) SetChildCommand(builder ICommandBuilder) bool
- func (b *CommandBuilderCore) SetChildCommands(builders ...ICommandBuilder)
- func (b *CommandBuilderCore) SetFlag(builder IFlagBuilder, group ...string) bool
- func (b *CommandBuilderCore) SetFlags(builders ...IFlagBuilder)
- func (b *CommandBuilderCore) SetFlagsWithGroup(group string, builders ...IFlagBuilder)
- type Flag
- func FlagCfgFile(ctx context.Context) *Flag
- func FlagCfgPath(ctx context.Context) *Flag
- func FlagDebug(ctx context.Context) *Flag
- func FlagInstallPath(ctx context.Context, group ...string) *Flag
- func FlagNoLogo(ctx context.Context) *Flag
- func FlagSkip(ctx context.Context) *Flag
- func FlagVerbose(ctx context.Context) *Flag
- func NewDefaultFlag(group ...string) *Flag
- func (f *Flag) ConfigKey() string
- func (f *Flag) ConfigKeyCamelLower() string
- func (f *Flag) ConfigKeySnake() string
- func (f *Flag) Context() context.Context
- func (f *Flag) DefaultCfg() g.MapStrAny
- func (f *Flag) Get() string
- func (f *Flag) GetVar() (o *g.Var)
- func (f *Flag) GetVarDefault() *g.Var
- func (f *Flag) GetVarInCfg() *g.Var
- func (f *Flag) GetVarInEnv() *g.Var
- func (f *Flag) GetVarInOpt() (o *g.Var)
- func (f *Flag) GetVarWithCfg() (o *g.Var)
- func (f *Flag) GetVarWithEnv() (o *g.Var)
- func (f *Flag) GetVarWithOpt() (o *g.Var)
- func (f *Flag) GetWithCfg() string
- func (f *Flag) Has() bool
- func (f *Flag) HasCfg() bool
- func (f *Flag) HasCmd() bool
- func (f *Flag) HasEnv() bool
- func (f *Flag) LongKey() string
- func (f *Flag) SetContext(ctx context.Context)
- func (f *Flag) ShortKey() string
- type FlagBuilderCore
- type FlagCfgFileBuilder
- type FlagCfgPathBuilder
- type FlagDebugBuilder
- type FlagInstallPathBuilder
- type FlagNoLogoBuilder
- type FlagSkipBuilder
- type FlagVerboseBuilder
- type ICommandBuilder
- type IFlagBuilder
Constants ¶
const CMD_HELP = "help"
const (
CmdShellUse = "shell"
)
const FLAG_CFG_FILE_LONG = "gf.gcfg.file"
const FLAG_CFG_PATH_LONG = "gf.gcfg.path"
const FLAG_DEBUG_LONG = "debug"
const FLAG_NO_LOGO_LONG = "no-logo"
const INSTALL = "install"
const VERSION = "version"
Variables ¶
This section is empty.
Functions ¶
func IsInstalled ¶ added in v0.2.0
func IsInstalled() bool
IsInstalled returns whether the binary is installed.
func ScanAndLog ¶
func ScanAndLog(info ...interface{}) string
func ScanMdFiles ¶ added in v0.9.0
ScanMdFiles 检索指定路径下的 md 文件。
func ScanWithDefault ¶ added in v0.8.0
ScanWithDefault 获取输入参数和默认值 Deprecated: 这个函数将在下一个版本更新时弃用, 新函数是 ScanWithDefaultN
func ScanWithDefaultN ¶ added in v0.9.1
ScanWithDefaultN 获取输入参数和默认值, 调整参数顺序
func ScanYesOrNo ¶
ScanYesOrNo 选择 yes 或者 no 默认值通过 <defaultValue> 设置,默认为 y 在特殊情况时可以自己设置为 n 输入 y 返回 True. 输入 n 返回 False
func SelectFile ¶ added in v0.9.0
SelectFile 遍历文件夹下的文件内容让用户选择 不查找子文件夹
func SetChildCommand ¶ added in v0.2.0
func SetChildCommand(parent ICommandBuilder, child ICommandBuilder) bool
func SetDefaultCommand ¶ added in v0.2.0
func SetDefaultCommand(parent ICommandBuilder)
SetDefaultCommand 设置命令默认命令 help 和 version
func SetDefaultFlag ¶ added in v0.2.0
func SetDefaultFlag(cmd ICommandBuilder)
func SetFlag ¶ added in v0.2.0
func SetFlag(cmd ICommandBuilder, falg IFlagBuilder, group ...string) bool
func TimeToCloseShell ¶ added in v1.0.1
TimeToCloseShell 在 shell 模式下的退出方式 在 shell 模式下不执行等待
Types ¶
type App ¶ added in v0.2.0
type App struct {
// contains filtered or unexported fields
}
func NewApp ¶ added in v0.2.0
func NewApp(root ICommandBuilder) App
type CmdHelpBuilder ¶ added in v0.2.0
type CmdHelpBuilder struct {
CommandBuilderCore
}
func (*CmdHelpBuilder) Init ¶ added in v0.2.0
func (b *CmdHelpBuilder) Init(ctx context.Context)
func (*CmdHelpBuilder) SetChildCommand ¶ added in v0.2.0
func (b *CmdHelpBuilder) SetChildCommand(builder ICommandBuilder) bool
func (*CmdHelpBuilder) SetFlag ¶ added in v0.2.0
func (b *CmdHelpBuilder) SetFlag(builder IFlagBuilder, _ ...string) bool
type CmdInstallBuilder ¶ added in v0.2.0
type CmdInstallBuilder struct {
CommandBuilderCore
}
func (*CmdInstallBuilder) Init ¶ added in v0.2.0
func (b *CmdInstallBuilder) Init(ctx context.Context)
func (*CmdInstallBuilder) SetChildCommand ¶ added in v0.2.0
func (b *CmdInstallBuilder) SetChildCommand(ICommandBuilder) bool
func (*CmdInstallBuilder) SetFlag ¶ added in v0.2.0
func (b *CmdInstallBuilder) SetFlag(IFlagBuilder, ...string) bool
type CmdShellBuilder ¶ added in v0.3.0
type CmdShellBuilder struct { CommandBuilderCore // contains filtered or unexported fields }
func (*CmdShellBuilder) Init ¶ added in v0.3.0
func (b *CmdShellBuilder) Init(ctx context.Context)
func (*CmdShellBuilder) SetChildCommand ¶ added in v0.3.0
func (b *CmdShellBuilder) SetChildCommand(builder ICommandBuilder) bool
func (*CmdShellBuilder) SetFlag ¶ added in v0.3.0
func (b *CmdShellBuilder) SetFlag(builder IFlagBuilder, _ ...string) bool
type CmdVersionBuilder ¶ added in v0.2.0
type CmdVersionBuilder struct {
CommandBuilderCore
}
func (*CmdVersionBuilder) Init ¶ added in v0.2.0
func (b *CmdVersionBuilder) Init(ctx context.Context)
func (*CmdVersionBuilder) SetChildCommand ¶ added in v0.2.0
func (b *CmdVersionBuilder) SetChildCommand(builder ICommandBuilder) bool
func (*CmdVersionBuilder) SetFlag ¶ added in v0.2.0
func (b *CmdVersionBuilder) SetFlag(builder IFlagBuilder, _ ...string) bool
type Command ¶ added in v0.2.0
type Command struct { Use string // 命令名称 Short string // 命令短描述 Long string // 命令长描述 Example string // 命令使用案例 Note string // 命令的详细说明 Run func(*Command) Help func(*Command) // contains filtered or unexported fields }
func NewCommandWithDefaultFunc ¶ added in v0.9.0
func NewCommandWithDefaultFunc() *Command
func NewDefaultCommand ¶ added in v0.2.0
func NewDefaultCommand() *Command
func (*Command) AddCommand ¶ added in v0.2.0
func (*Command) RunChildCmd ¶ added in v0.2.0
RunChildCmd 运行子命令,<cmdUse> 表示字命令的字符. 当 <cmdUse> 为空时, 判断命令是否可以执行shell 可以则执行 当 <cmdUse> 不存在时, 显示当前命令的帮助信息 <cmdUse> 直接执行
func (*Command) SetContext ¶ added in v0.9.0
type CommandBuilderCore ¶ added in v0.2.0
type CommandBuilderCore struct {
C *Command
}
func (*CommandBuilderCore) Command ¶ added in v0.2.0
func (b *CommandBuilderCore) Command() *Command
func (*CommandBuilderCore) Init ¶ added in v0.2.0
func (b *CommandBuilderCore) Init(ctx context.Context)
func (*CommandBuilderCore) SetChildCommand ¶ added in v0.2.0
func (b *CommandBuilderCore) SetChildCommand(builder ICommandBuilder) bool
func (*CommandBuilderCore) SetChildCommands ¶ added in v0.2.0
func (b *CommandBuilderCore) SetChildCommands(builders ...ICommandBuilder)
func (*CommandBuilderCore) SetFlag ¶ added in v0.2.0
func (b *CommandBuilderCore) SetFlag(builder IFlagBuilder, group ...string) bool
func (*CommandBuilderCore) SetFlags ¶ added in v0.2.0
func (b *CommandBuilderCore) SetFlags(builders ...IFlagBuilder)
func (*CommandBuilderCore) SetFlagsWithGroup ¶ added in v0.4.0
func (b *CommandBuilderCore) SetFlagsWithGroup(group string, builders ...IFlagBuilder)
type Flag ¶ added in v0.2.0
type Flag struct { Short string // 选项 短 Long string // 选择 长 DefaultValue interface{} // 带参数时的参数名 Description string // 描述信息 ConfigNodeName string // 配置文件节点名 Group string // 配置节点中的分组, 更多的区分同一种配置参数, 还是尽量配置参数不一样 // contains filtered or unexported fields }
func FlagCfgFile ¶ added in v0.2.0
func FlagCfgPath ¶ added in v1.0.1
func FlagInstallPath ¶ added in v1.0.1
func FlagNoLogo ¶ added in v0.2.0
func FlagVerbose ¶ added in v0.4.0
func NewDefaultFlag ¶ added in v0.2.0
func (*Flag) ConfigKey ¶ added in v0.3.0
ConfigKey 获取当前 Config 的配置项名称, 此名称应该在软件内唯一 此参数也用于 Command.AddFlag 中存储 Flag 使用
func (*Flag) ConfigKeyCamelLower ¶ added in v0.4.0
ConfigKeyCamelLower 驼峰式的 configKey
func (*Flag) ConfigKeySnake ¶ added in v0.4.0
ConfigKeySnake 蛇式的 config_key
func (*Flag) DefaultCfg ¶ added in v0.3.0
func (*Flag) GetVar ¶ added in v0.2.0
GetVar 获取标志参数值。 按照 全配置名称 -> 长参数 -> 短参数 -> [长参数不空]配置文件(驼峰变量->蛇形变量->long变量) -> 环境变量 的顺序读取
func (*Flag) GetVarDefault ¶ added in v1.0.1
GetVarDefault 获取默认值的 Var
func (*Flag) GetVarInCfg ¶ added in v1.0.1
GetVarInCfg 只通过配置文件获取值 不存在时返回 nil
func (*Flag) GetVarInEnv ¶ added in v1.0.1
GetVarInEnv 只通过环境变量获取值 不存在时返回 nil
func (*Flag) GetVarInOpt ¶ added in v1.0.1
GetVarInOpt 只通过命令行参数获取值 全配置名称 -> 长参数 -> 短参数 不存在时返回 nil
func (*Flag) GetVarWithCfg ¶ added in v1.0.1
GetVarWithCfg 通过配置文件获取值, 当值不存在时,使用默认值
func (*Flag) GetVarWithEnv ¶ added in v1.0.1
GetVarWithEnv 通过环境变量获取值, 当值不存在时,使用默认值
func (*Flag) GetVarWithOpt ¶ added in v1.0.1
GetVarWithOpt 通过命令行参数获取值, 当值不存在时,使用默认值
func (*Flag) GetWithCfg ¶ added in v1.0.1
func (*Flag) SetContext ¶ added in v0.9.0
type FlagBuilderCore ¶ added in v0.2.0
type FlagBuilderCore struct {
F *Flag
}
func (*FlagBuilderCore) Flag ¶ added in v0.2.0
func (f *FlagBuilderCore) Flag() *Flag
type FlagCfgFileBuilder ¶ added in v0.2.0
type FlagCfgFileBuilder struct {
FlagBuilderCore
}
type FlagCfgPathBuilder ¶ added in v1.0.1
type FlagCfgPathBuilder struct {
FlagBuilderCore
}
type FlagDebugBuilder ¶ added in v0.2.0
type FlagDebugBuilder struct {
FlagBuilderCore
}
type FlagInstallPathBuilder ¶ added in v1.0.1
type FlagInstallPathBuilder struct {
FlagBuilderCore
}
type FlagNoLogoBuilder ¶ added in v0.2.0
type FlagNoLogoBuilder struct {
FlagBuilderCore
}
type FlagSkipBuilder ¶ added in v0.8.0
type FlagSkipBuilder struct {
FlagBuilderCore
}
type FlagVerboseBuilder ¶ added in v0.4.0
type FlagVerboseBuilder struct {
FlagBuilderCore
}
type ICommandBuilder ¶ added in v0.2.0
type ICommandBuilder interface { // Init 初始化命令 Init(ctx context.Context) // Command 获取此命令 Command() *Command // SetChildCommand 利用 builder 设置子命令 SetChildCommand(builder ICommandBuilder) bool // SetFlag 设置 Flag 标签 SetFlag(IFlagBuilder, ...string) bool }