cmdtool

package
v0.0.0-...-750c461 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: BSD-3-Clause-Clear Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CmdTypeName = iota
	CmdTypeFlag
	CmdTypeParam
)
View Source
const (
	// ParamRequired the parameter was required. missing this parameter will cause error!
	ParamRequired = 1 << iota
	// ParamSet the parameter can be occurs multiply times
	ParamSet
	// ParamKeyValuePair the parameter should in KEY=VALUE form
	ParamKeyValuePair
	// FlagRequired the flag was required
	FlagRequired
	// FlagValueRequired the flag requests a value parameter
	FlagValueRequired
)

Variables

View Source
var (
	ErrNoFlag              = misc.MakeError("No such flag!")
	ErrNoParam             = misc.MakeError("No such parameter!")
	ErrIncorrectFlagValue  = misc.MakeError("Incorrect flag value!")
	ErrIncorrectParamValue = misc.MakeError("Incorrect parameter!")
	ErrGroupFlagsConflict  = misc.MakeError("Group flags conflict!")
	ErrMissingFlag         = misc.MakeError("Missing flag!")
	ErrMissingParameter    = misc.MakeError("Missing parameter!")
	ErrTooManyParameters   = misc.MakeError("Too many parameters!")
	ErrUnknownFlag         = misc.MakeError("Unknown flag!")
	ErrInternalError       = misc.MakeError("Internal Error!")
	ErrFlagValueRequired   = misc.MakeError("Flag value required!")
)

Functions

This section is empty.

Types

type Cmd

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

Cmd command line text parser/executor

func (*Cmd) AddArgsCommand

func (c *Cmd) AddArgsCommand(alias ...string) *CmdExecutor

AddArgsCommand defines command that handle os.Args input

func (*Cmd) AddCommand

func (c *Cmd) AddCommand(cmdName string, alias ...string) *CmdExecutor

func (*Cmd) Execute

func (c *Cmd) Execute(s string) error

func (*Cmd) ExecuteArgs

func (c *Cmd) ExecuteArgs() error

ExecuteArgs execute os.Args

func (*Cmd) ParseLine

func (c *Cmd) ParseLine(l string) (tokens []CmdToken, err error)

func (*Cmd) Printf

func (c *Cmd) Printf(fmt string, val ...interface{})

func (*Cmd) SetLogger

func (c *Cmd) SetLogger(loggerWriter LoggerWriter) LoggerWriter

type CmdContext

type CmdContext interface {
	Flag(name string) (CmdFlag, error)
	Flags() []CmdFlag
	Param(name string) (CmdParam, error)
	ParamSet(name string) ([]CmdParam, error)
	Params() []CmdParam

	Print(info ...interface{})
	Printf(fmt string, args ...interface{})
	E(info ...interface{})
	W(info ...interface{})
	I(info ...interface{})
	V(info ...interface{})
	ListCommands(func(string) bool)
	ShowUsage(brief bool)
}

type CmdExecutor

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

func (*CmdExecutor) AddFlag

func (ctx *CmdExecutor) AddFlag(name string, valueInfo string, pattern interface{}, flags int, desc string) *CmdExecutor

func (*CmdExecutor) AddFlagGroup

func (ctx *CmdExecutor) AddFlagGroup(name string, valueInfo string, pattern interface{}, flags int, desc string, groupName string) *CmdExecutor

AddFlagGroup create a new flag group / add a new flag into the named group a group of flags are mutually exclusive, only one flag should occurs in a certain group

func (*CmdExecutor) AddFlagParam

func (ctx *CmdExecutor) AddFlagParam(name string, valueInfo string, pattern interface{}, flags int, desc string) *CmdExecutor

func (*CmdExecutor) AddParam

func (ctx *CmdExecutor) AddParam(name string, valueInfo string, pattern interface{}, flags int, desc string) *CmdExecutor

func (*CmdExecutor) E

func (ctx *CmdExecutor) E(info ...interface{})

func (*CmdExecutor) Finish

func (ctx *CmdExecutor) Finish(handler func(ctx CmdContext)) error

func (*CmdExecutor) Flag

func (ctx *CmdExecutor) Flag(name string) (CmdFlag, error)

func (*CmdExecutor) Flags

func (ctx *CmdExecutor) Flags() []CmdFlag

func (*CmdExecutor) I

func (ctx *CmdExecutor) I(info ...interface{})

func (*CmdExecutor) ListCommands

func (ctx *CmdExecutor) ListCommands(filter func(string) bool)

func (*CmdExecutor) Param

func (ctx *CmdExecutor) Param(name string) (CmdParam, error)

func (*CmdExecutor) ParamSet

func (ctx *CmdExecutor) ParamSet(name string) ([]CmdParam, error)

func (*CmdExecutor) Params

func (ctx *CmdExecutor) Params() []CmdParam

func (*CmdExecutor) Print

func (ctx *CmdExecutor) Print(str ...interface{})

func (*CmdExecutor) Printf

func (ctx *CmdExecutor) Printf(fmt string, args ...interface{})

func (*CmdExecutor) SetDesc

func (ctx *CmdExecutor) SetDesc(desc string) *CmdExecutor

func (*CmdExecutor) ShowUsage

func (ctx *CmdExecutor) ShowUsage(brief bool)

func (*CmdExecutor) V

func (ctx *CmdExecutor) V(info ...interface{})

func (*CmdExecutor) W

func (ctx *CmdExecutor) W(info ...interface{})

type CmdFlag

type CmdFlag interface {
	CmdToken
	Name() string
	Value() string
}

type CmdName

type CmdName interface {
	CmdToken
	Name() string
}

type CmdParam

type CmdParam interface {
	CmdToken
	Name() string
	Key() string
	Value() string
}

type CmdToken

type CmdToken interface {
	Type() int
}

type LoggerWriter

type LoggerWriter func(level string, str ...interface{})

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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