Versions in this module Expand all Collapse all v1 v1.0.0 Oct 25, 2022 Changes in this version + const ExportPlugin + var CheckSum = NewFlag("check", "-check") + var DefaultDateFormatter = "20060102.15:04:05.999" + var LogFLevel = NewFlag("logl", "-logl {0-5} 日志输出级别(0-5)对应 debug-error") + var LogFlag = NewFlag("logf", "-logf ./app.log 指定日志文件") + var NotImplementsMessage = NewMessage(0, "该功能还没实现", LOG_WARN) + var PluginDir = NewFlag("pdir", "-pdir {dir} 添加插件目录,可多个") + var UiFlag = NewFlag("ui", "程序启用GUI,输入指令会忽略") + var WorkDir = NewFlag("wdir", "-wdir 指定工作目录") + func DirEnsure(dest string, create bool) (abspath string, created bool, err error) + func FirstNoneNilResult(values ...T) T + func ParseFlag(fm FlagMap, f Flag) (T, bool) + func ParseInputArgs(args []string) (Args, FlagMap) + func ParseLine(input string) (Args, FlagMap) + func RenderPluginFile(bean *PluginBean, dest string) (err error) + func SplitLines(txt string, width int, indent int, firstIndent bool) (fmtstr string) + type AlignField struct + AlignWidth int + Content string + Padding PaddingType + func (field *AlignField) Indent(indent int) *AlignField + func (field *AlignField) NewLine() *AlignField + func (field *AlignField) SplitFixedWidthLine(width int, indent int, firstIndent bool) *AlignField + func (field *AlignField) SplitLine(indent int, firstIndent bool) *AlignField + func (field *AlignField) WriteAppend(w io.Writer) + type AlignWriter struct + func NewAlignWriter() *AlignWriter + func ScreenAlignWriter(screenWidth int) *AlignWriter + func (aw *AlignWriter) AlignAppend(content string, width int, pad PaddingType) *AlignField + func (aw *AlignWriter) LeftPaddingAppend(context string) *AlignField + func (aw *AlignWriter) MaskString(align int, endln bool) string + func (aw *AlignWriter) MaskWirte(align int, writer io.Writer) + func (aw *AlignWriter) NopaddingAppend(context string) *AlignField + func (aw *AlignWriter) RightPaddingAppend(context string) *AlignField + type Args = []string + func MergeFlagMap(args []string, fmap FlagMap) Args + type BootStrap struct + func CLI() *BootStrap + func (boot *BootStrap) Run(args []string) Message + type Command interface + Flags func() []Flag + Key func() string + Run func(ctx Context, args []string, flagmap FlagMap) Message + Usage func() string + func NewCommand(key string, usage string, do ExecFunc) Command + func NewFlagsCommand(key string, usage string, do ExecFunc, flags ...Flag) Command + func NewRootCommand(key string, usage string) Command + type CommandInputs struct + Args Args + Flags FlagMap + type CommandVisitor = func(key string, command map[string]Command) (next bool) + type Console interface + Log func() (Log, bool) + Std func() StandConsole + func NewConsole(term io.Writer, logf *Logger) Console + type Context interface + Interupt func() bool + Logger func() (logger Log, enable bool) + RegisteredPlugins func() PluginVersionMap + StdConsole func() StandConsole + Value func(key any) any + WorkDir func() string + func MockContext() Context + type ContextKey = string + type ExecFunc = func(ctx Context, args []string, flagmap FlagMap) Message + func BuildRun(exec ExecFunc, inputRules []InputValidator, paramRules ...ParamValiator) ExecFunc + type FParser interface + Parse func(args Args) (T, bool) + type Flag interface + Alias func() (string, bool) + Name func() string + Usage func() string + func BuildFlag(name string, alias string, parser FlagParser[T]) Flag + func NewFlag(nameUsageAlias ...string) Flag + type FlagExpected struct + DefVal any + ErrMsg Message + Flag Flag + Required bool + Validator FlagValidator + type FlagInputs = CommandInputs + type FlagMap interface + Empty func() bool + GetBool func(key string) (v bool, found bool) + GetInt func(key string) (v int, found bool) + GetString func(key string) (v string, found bool) + GetStrings func(key string) (v Args, found bool) + HasFlag func(flag Flag) (Args, bool) + Set func(key string, values ...string) + func NewFMap(args []string) FlagMap + func NewFlagMap() FlagMap + type FlagParser func(args Args) (T, bool) + type FlagValidator = Validator[*FlagInputs] + type GeneralPlugin struct + Commands []Command + Desc string + Help HelperFunc + ID string + Init LifeHook + PreRun LifeHook + Ver string + func (gp *GeneralPlugin) BeforeRun(ctx Context) error + func (gp *GeneralPlugin) Helper() HelperFunc + func (gp *GeneralPlugin) Name() string + func (gp *GeneralPlugin) Registry() []Command + func (gp *GeneralPlugin) Setup(ctx Context) error + func (gp *GeneralPlugin) Usage() string + func (gp *GeneralPlugin) Version() string + type HelperFunc = func() string + type InputValidRule = func(ctx Context, args []string, flags FlagMap) (bool, Message) + type InputValidator = Validator[*CommandInputs] + func InputRules(rules ...InputValidator) []InputValidator + func NewInputValidRule(rule InputValidRule, fail Message) InputValidator + type LifeHook = func(ctx Context) error + type LoadedPlugin struct + Digest string + File string + Verified bool + func LoadPlugin(dirs []string, console Log) ([]*LoadedPlugin, int) + type Log interface + NewLogger func(file string) Log + type LogLevel = int + const LOG_DEBUG + const LOG_ERROR + const LOG_INFO + const LOG_SUCC + const LOG_WARN + type Logger struct + Max int64 + RStrage int + func NewDatePatternLogger(file string) *Logger + func NewLogger(file string) *Logger + func NewParialLogger(file string, maxMB int) *Logger + func (log *Logger) NFile(f string) *Logger + func (log *Logger) PrependPrefix(values ...Prefix) + func (log *Logger) PrependPrefixString(values ...string) + func (log *Logger) Write(p []byte) (n int, err error) + type Message interface + Code func() int + Err func() (error, bool) + Kind func() int + Msg func() string + func DebugMessage(code int, msg string, msgargs ...any) Message + func ErrMessage(code int, msg string, msgargs ...any) Message + func InfoMessage(code int, msg string, msgargs ...any) Message + func InteruptMessage(msg string) Message + func NewMessage(code int, msg string, kind int, msgargs ...any) Message + func NothingDo(ctx Context, args []string, flagmap FlagMap) (msg Message) + func SuccMessage(code int, msg string, msgargs ...any) Message + func WarnMessage(code int, msg string, msgargs ...any) Message + type PaddingType = int + const INDENT_NOLIMIT + const LEFT_PADDING + const NONE_PADDING + const RIGHT_PADDING + const SPLIT_LINE_WIDTH + type ParamRule struct + func (vp *ParamRule) Index() int + func (vp *ParamRule) Valid(ctx Context, value string) (bool, Message) + type ParamValiator = ParamValidator[string] + func ParamRules(rules ...ParamValiator) []ParamValiator + func ValidAllParam(rule ParamValidRule) ParamValiator + func ValidParam(index uint, rule ParamValidRule) ParamValiator + type ParamValidRule = func(ctx Context, val string) (bool, Message) + type ParamValidator interface + Index func() int + type Plugin interface + BeforeRun func(ctx Context) error + Helper func() HelperFunc + Name func() string + Registry func() []Command + Setup func(ctx Context) error + Usage func() string + Version func() string + type PluginBean struct + ExportType string + Name string + Usage string + Version string + type PluginBundle interface + Dependencies func() []PluginBundle + File func() string + Md5 func() string + Name func() string + Version func() string + type PluginContext interface + func NewPContext(ctx Context, ptr unsafe.Pointer) PluginContext + func NewPluginContext(ctx Context, plugin Plugin) PluginContext + type PluginVersionMap = map[string]PluginBundle + type PluginVisitor = func(key string, plugins map[string]*RegisteredPlugin) (next bool) + type Prefix = func() string + type RegisteredCommand struct + From unsafe.Pointer + SubCommands SubCommand + func NewRegistryCommand(ptr unsafe.Pointer, c Command) *RegisteredCommand + func NewRootRegistry(from unsafe.Pointer, key string) *RegisteredCommand + func (c *RegisteredCommand) AddSub(ptr unsafe.Pointer, cmd Command) (add *RegisteredCommand, ok bool, err error) + func (c *RegisteredCommand) AppendSub(sub *RegisteredCommand) (ok bool, err error) + func (c *RegisteredCommand) Children() (children []*RegisteredCommand, maxL int) + func (c *RegisteredCommand) Flags() []Flag + func (c *RegisteredCommand) HasSub() (sub SubCommand, has bool) + func (c *RegisteredCommand) Key() string + func (c *RegisteredCommand) Range(v RegisteredCommandVisitor) + func (c *RegisteredCommand) RootCommand(cmd Command) + func (c *RegisteredCommand) Run(ctx Context, args []string, flagmap FlagMap) Message + func (c *RegisteredCommand) SetSubs(subs ...*RegisteredCommand) + func (c *RegisteredCommand) Usage() string + type RegisteredCommandVisitor = RootCommandVisitor + type RegisteredPlugin struct + func (rp *RegisteredPlugin) Append(c *RegisteredCommand) error + func (rp *RegisteredPlugin) Commands() (commands []*RegisteredCommand, maxL int) + func (rp *RegisteredPlugin) Installed() + type Registry interface + Command func(args []string) (RegisteredCommand, bool) + CommandKeyMaxLen func() (int, bool) + FindPlugin func(plugin Plugin) (RegisteredPlugin, bool) + Finish func(panicunfinished bool) (loaded int, failed int) + Logger func(log Log) + Plugin func(name string) (RegisteredPlugin, bool) + RangePlugin func(PluginVisitor) + RangeRootCommand func(RootCommandVisitor) + RegisterCommand func(p Plugin, cmds ...Command) (ok bool, err error) + RegisterPlugins func(plugins ...Plugin) + RootCommand func(key string) (RegisteredCommand, bool) + RootKeyMaxLen func() (int, bool) + func NewRegistry() Registry + type RegistryCommands []*RegisteredCommand + func (g RegistryCommands) Len() int + func (g RegistryCommands) Less(i, j int) bool + func (g RegistryCommands) Swap(i, j int) + type RootCommandVisitor = func(key string, roots map[string]*RegisteredCommand) (next bool) + type RotateStrage = int + const DATE_PATTERN + const NONE + const PARTIAL_NUMBER + type ShortAction = int + const ActionExec + const ActionInput + type ShortCommand struct + Action ShortAction + Command string + type ShortCutCommands = []ShortCommand + func DefaultShortCut(custom ShortCutCommands) (ShortCutCommands, map[ShortCutKey]int) + type ShortCutKey = int + const KeyAlt0 + const KeyAlt1 + const KeyAlt2 + const KeyAlt3 + const KeyAlt4 + const KeyAlt5 + const KeyAlt6 + const KeyAlt7 + const KeyAlt8 + const KeyAlt9 + const KeyAltW + type ShortKey struct + Key ShortCutKey + Title string + func NewShortKey(key ShortCutKey) *ShortKey + type StandConsole interface + AppendPrefix func(prefix string, args ...any) Console + Debug func(msg string, args ...any) + Err func(emsg string, args ...any) + Info func(msg string, args ...any) + Level func(level LogLevel) + Msg func(msg Message) + Prefix func(prefix string, args ...any) Console + PrependPrefix func(prefix string, args ...any) Console + Succ func(msg string, args ...any) + WError func(err error) + Warn func(msg string, args ...any) + type SubCommand = map[string]*RegisteredCommand + type UiOptions struct + MaxHistoryItem int + ShortCut ShortCutCommands + type Validator interface + Valid func(ctx Context, value T) (bool, Message) + func EmptyArgs() Validator[*CommandInputs] + func ExactlyLength(size uint, emsg Message) Validator[*CommandInputs] + func ExpectLength(min int, max int, emsg Message) Validator[*CommandInputs] + func MustFlagged(flags ...*FlagExpected) Validator[*CommandInputs] + type ValueOperator interface + Remove func(key any) (removed any, loaded bool) + SetValue func(key any, value any) + SetValueIfAbsent func(key any, value any) (exist bool) + type Window interface + Run func(prompt string, ctx Context) Message + func ConfigUi(options UiOptions) Window + func NewUi() Window