yscmd

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2022 License: MIT Imports: 21 Imported by: 1

Documentation

Index

Constants

View Source
const CMD_HELP = "help"
View Source
const CMD_SHELL = "shell"
View Source
const FLAG_CFG_FILE_LONG = "gf.gcfg.file"
View Source
const FLAG_DEBUG_LONG = "debug"
View Source
const FLAG_NO_LOGO_LONG = "no-logo"
View Source
const INSTALL = "install"
View Source
const VERSION = "version"

Variables

This section is empty.

Functions

func CmdWait added in v0.8.0

func CmdWait(ctx context.Context)

func DefaultHelp added in v0.2.0

func DefaultHelp(c *Command)

func DefaultRun added in v0.2.0

func DefaultRun(c *Command)

func GetArgIndex added in v0.6.0

func GetArgIndex(a string) int

GetArgIndex 获取指定 Arg 对应的索引值

func GetChildArg added in v0.6.0

func GetChildArg(a string) string

GetChildArg 获取指定 Arg 对应的 子命令

func GoDirFmt

func GoDirFmt(dir string)

func GoFileFmt

func GoFileFmt(path string, group *sync.WaitGroup)

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

func ScanMdFiles(path string) []string

ScanMdFiles 检索指定路径下的 md 文件。

func ScanVar added in v0.9.0

func ScanVar(message string, defaultValue string) *g.Var

ScanVar 获取命令行输入的字符串转换为 Var 类型方便使用

func ScanWithDefault added in v0.8.0

func ScanWithDefault(defaultValue string, info ...string) string

ScanWithDefault 获取输入参数和默认值

func ScanYesOrNo

func ScanYesOrNo(info ...interface{}) bool

ScanYesOrNo 选择 yes 或者 no 输入 y 或不输入 返回 True. 输入 n 返回 False

func SelectConfig added in v0.9.0

func SelectConfig() string

SelectConfig 找寻当前目录下的配置文件

func SelectFile added in v0.9.0

func SelectFile(path string, pattern string) string

SelectFile 遍历文件夹下的文件内容让用户选择 不查找子文件夹

func SelectOne added in v0.8.0

func SelectOne(options []string, msg string) (string, int)

SelectOne 从选项中选择一个出来 默认选择 0

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)

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 TimeToClose added in v0.8.0

func TimeToClose(t int)

TimeToClose 延迟xx秒并显示提示

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

func (App) Run added in v0.2.0

func (a App) Run(ctx context.Context)

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 CmdHelp added in v0.9.0

func CmdHelp(ctx context.Context) *Command

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 (c *Command) AddCommand(cmd *Command) bool

func (*Command) AddFlag added in v0.2.0

func (c *Command) AddFlag(f *Flag) bool

func (*Command) Child added in v0.6.0

func (c *Command) Child(use string) *Command

func (*Command) Context added in v0.9.0

func (c *Command) Context() context.Context

func (*Command) Exec added in v0.2.0

func (c *Command) Exec()

Exec 执行命令的 Run 函数

func (*Command) GetHelp added in v0.2.0

func (c *Command) GetHelp() string

GetHelp 使用模板创建默认的帮助命令

func (*Command) Parent added in v0.6.0

func (c *Command) Parent() *Command

func (*Command) PrintHelp added in v0.2.0

func (c *Command) PrintHelp()

func (*Command) RunChildCmd added in v0.2.0

func (c *Command) RunChildCmd(cmdUse string)

RunChildCmd 运行子命令,<cmdUse> 表示字命令的字符. 当 <cmdUse> 为空时, 判断命令是否可以执行shell 可以则执行 当 <cmdUse> 不存在时, 显示当前命令的帮助信息 <cmdUse> 直接执行

func (*Command) SetContext added in v0.9.0

func (c *Command) SetContext(ctx context.Context)

func (*Command) ShowHelp added in v0.2.0

func (c *Command) ShowHelp()

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 FlagCfgFile(ctx context.Context) *Flag

func FlagDebug added in v0.2.0

func FlagDebug(ctx context.Context) *Flag
func FlagNoLogo(ctx context.Context) *Flag

func FlagSkip added in v0.8.0

func FlagSkip(ctx context.Context) *Flag

func FlagVerbose added in v0.4.0

func FlagVerbose(ctx context.Context) *Flag

func NewDefaultFlag added in v0.2.0

func NewDefaultFlag(group ...string) *Flag

func (*Flag) ConfigKey added in v0.3.0

func (f *Flag) ConfigKey() string

ConfigKey 获取当前 Config 的配置项名称, 此名称应该在软件内唯一 此参数也用于 Command.AddFlag 中存储 Flag 使用

func (*Flag) ConfigKeyCamelLower added in v0.4.0

func (f *Flag) ConfigKeyCamelLower() string

ConfigKeyCamelLower 驼峰式的 configKey

func (*Flag) ConfigKeySnake added in v0.4.0

func (f *Flag) ConfigKeySnake() string

ConfigKeySnake 蛇式的 config_key

func (*Flag) Context added in v0.9.0

func (f *Flag) Context() context.Context

func (*Flag) DefaultCfg added in v0.3.0

func (f *Flag) DefaultCfg() g.MapStrAny

func (*Flag) Get added in v0.2.0

func (f *Flag) Get() string

Get 获取字符串结果,建议不使用

func (*Flag) GetVar added in v0.2.0

func (f *Flag) GetVar() *g.Var

GetVar 按照 全配置名称 -> 长参数 -> 短参数 -> [长参数不空]配置文件(驼峰变量->蛇形变量->long变量) -> 环境变量 的顺序读取

func (*Flag) Has added in v0.2.0

func (f *Flag) Has() bool

Has 按照 命令行,配置文件,环境变量的顺序读取

func (*Flag) HasCfg added in v0.2.0

func (f *Flag) HasCfg() bool

HasCfg 配置文件是否存在

func (*Flag) HasCmd added in v0.2.0

func (f *Flag) HasCmd() bool

HasCmd 命令行是否存在

func (*Flag) HasEnv added in v0.2.0

func (f *Flag) HasEnv() bool

HasEnv 环境变量是否存在

func (*Flag) LongKey added in v0.3.0

func (f *Flag) LongKey() string

func (*Flag) SetContext added in v0.9.0

func (f *Flag) SetContext(ctx context.Context)

func (*Flag) ShortKey added in v0.3.0

func (f *Flag) ShortKey() string

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

func (*FlagBuilderCore) Init added in v0.9.0

func (f *FlagBuilderCore) Init(ctx context.Context, group ...string)

type FlagCfgFileBuilder added in v0.2.0

type FlagCfgFileBuilder struct {
	FlagBuilderCore
}

func (*FlagCfgFileBuilder) Init added in v0.2.0

func (b *FlagCfgFileBuilder) Init(ctx context.Context, group ...string)

type FlagDebugBuilder added in v0.2.0

type FlagDebugBuilder struct {
	FlagBuilderCore
}

func (*FlagDebugBuilder) Init added in v0.2.0

func (b *FlagDebugBuilder) Init(ctx context.Context, group ...string)

type FlagNoLogoBuilder added in v0.2.0

type FlagNoLogoBuilder struct {
	FlagBuilderCore
}

func (*FlagNoLogoBuilder) Init added in v0.2.0

func (f *FlagNoLogoBuilder) Init(ctx context.Context, group ...string)

type FlagSkipBuilder added in v0.8.0

type FlagSkipBuilder struct {
	FlagBuilderCore
}

func (*FlagSkipBuilder) Init added in v0.8.0

func (b *FlagSkipBuilder) Init(ctx context.Context, group ...string)

type FlagVerboseBuilder added in v0.4.0

type FlagVerboseBuilder struct {
	FlagBuilderCore
}

func (*FlagVerboseBuilder) Init added in v0.4.0

func (b *FlagVerboseBuilder) Init(ctx context.Context, group ...string)

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
}

type IFlagBuilder added in v0.2.0

type IFlagBuilder interface {
	// Init 初始化命令
	Init(context.Context, ...string)

	// Flag 获取此
	Flag() *Flag
}

Jump to

Keyboard shortcuts

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