Documentation
¶
Overview ¶
轻量级命令行框架
Index ¶
- Constants
- func Adapter(router *Router)
- func Alias(cmd string, alias ...string)
- func AliasMany(alias map[string][]string)
- func AmendSubC(subC string) string
- func Args() []string
- func CallCmdHelp(key string) bool
- func EmptyFunc(todo func())
- func FormatKv(kv map[string]interface{}, params ...string) string
- func FormatQue(que []interface{}, prefs ...string) string
- func FormatStr(d string, ss ...[][]string) string
- func FormatTable(data [][]interface{}, args ...interface{}) string
- func Init(param []string)
- func InjectArgs(params ...string)
- func IsEmptyCmd() bool
- func Register(name string, cmd interface{})
- func RegisterApps(data map[string]interface{})
- func RegisterFunc(cmd string, todo func())
- func Rwd() string
- func StrParseData(v string) interface{}
- func SubCommand(able bool)
- func UnfindFunc(todo func(cmd string))
- type ActionInterface
- type App
- func (app *App) Arg(key string) interface{}
- func (app *App) ArgDefault(key string, def interface{}) interface{}
- func (app *App) ArgRaw(key string) string
- func (app *App) ArgRawDefault(key, def string) string
- func (app *App) Args(key string) interface{}
- func (app *App) ArgsRaw(key string) string
- func (app *App) Cwd() string
- func (app *App) HasSetting(set string) bool
- func (app *App) Next(keys ...string) string
- func (app *App) PrjName() string
- func (app *App) QueueNext(key string) string
- type CmdUitl
- type Command
- type Router
- type SubCmdAlias
Constants ¶
const ( AppMethodInit = "Init" AppMethodRun = "Run" AppMethodNoSubC = "SubCommandUnfind" AppMethodHelp = "Help" )
Variables ¶
This section is empty.
Functions ¶
func FormatKv ¶ added in v0.5.2
The `k-v` data format to beautiful str.
FormatKv(kv map[string]interface{}, pref string) 含前缀的字符输出. FormatKv(kv map[string]interface{}, pref string, md string) 含前缀和中间连接符号的字符输出.
func FormatTable ¶ added in v0.5.0
func FormatTable(data [][]interface{}, args ...interface{}) string
表格格式化 (data, bool) 是否使用 idx
func Init ¶
func Init(param []string)
建议使用 InjectArgs 代替,后期可能进行优化 命令程序初始化入口,用于开发时非直接编译测试 @todo 0.6 删除 Deprecated: use InjectArgs instead, will delete in 0.6
func StrParseData ¶ added in v0.5.0
func StrParseData(v string) interface{}
app.Data 数据格式化 正则检查并被处理为对应的数据格式 --key='字符串参数 可含空格'/--key="'字符串参数 可含空格'" 去除标点,并且认为是字符串 --key=1,2,45,87,96,52,37 整形数组 解析的格式有: bool, int64, float64, string, []int, []string,[]float64, string
Types ¶
type App ¶
type App struct { Data map[string]interface{} // 格式化数据 DataRaw map[string]string // 原始数据,命令行的所有数据解析时都为字符串 Router *Router Command string // 当前的命令 SubCommand string // 二级命令 Setting []string // 项目设置 Queue []string // 命令队列 // contains filtered or unexported fields }
全局命令行实例,可通过 GetApp 获取
func (*App) ArgDefault ¶ added in v0.5.2
can default value to get the arg
func (*App) ArgRawDefault ¶ added in v0.5.2
get raw arg has default
type CmdUitl ¶ added in v0.5.0
type CmdUitl struct {
// contains filtered or unexported fields
}
Command 协助方法 通过 cmdInst 与 命令程序解析
func (*CmdUitl) BaseSubCAlias ¶ added in v0.5.0
func (cu *CmdUitl) BaseSubCAlias(inst interface{}, alias map[string][]string) *SubCmdAlias
二级命令别名
type Command ¶
type Command struct { App App SCA *SubCmdAlias Util *CmdUitl }
命令结构体
func (*Command) InnerDistribute ¶ added in v0.2.0
func (c *Command) InnerDistribute()
入口/内部分发(Entrance)
func (*Command) SubCommandUnfind ¶ added in v0.1.1
二级命令应用
type Router ¶
type Router struct { // 别名映射组 Alias map[string]string UnfindAction func(action string) // 路由失败 EmptyAction func() // 路由失败 FuncAction func(action string, a *App) bool // 函数式action命名,快速实现 OptionListener func(opt string, a *App) bool // 选项监听回调 }
路由器基类
type SubCmdAlias ¶ added in v0.2.0
二级命令别名