cmd

package module
v0.0.0-...-39afb7a Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2017 License: Apache-2.0 Imports: 6 Imported by: 6

README

cmd

cmd is Go library which handles command line parsing.

Documentation

Index

Constants

View Source
const (
	Set int = iota
	Delete
	SetValidate
	DeleteValidate
	Subscribe
)
View Source
const (
	ParseNoMatch = iota
	ParseAmbiguous
	ParseIncomplete
	ParseSuccess
)
View Source
const (
	Success int = iota
)

Variables

View Source
var (
	DynamicFunc func([]string, string, []string) []string
)
View Source
var String2NodeTypeMap = map[string]NodeType{}

Functions

func Interface2String

func Interface2String(srcs []interface{}) []string

func ParseResult2String

func ParseResult2String(result int) string

func String2Interface

func String2Interface(strs []string) []interface{}

Types

type Args

type Args []interface{}

type Callback

type Callback interface{}

type Cmd

type Cmd struct {
	Modes map[string]*Mode
}

func NewCmd

func NewCmd() *Cmd

func (*Cmd) FirstCommands

func (c *Cmd) FirstCommands(mode string, privilege uint32) (cmds string)

func (*Cmd) InstallMode

func (c *Cmd) InstallMode(name string, header string, prompt string) *Mode

func (*Cmd) InstallSubMode

func (c *Cmd) InstallSubMode(mode *Mode, name string, header string, prompt string) *Mode

func (*Cmd) LookupMode

func (c *Cmd) LookupMode(name string) *Mode

func (*Cmd) ParseLine

func (c *Cmd) ParseLine(mode string, line string, args ...*Param) (int, Callback, []interface{}, CompSlice)

type Comp

type Comp struct {
	Name     string
	Help     string
	Dir      bool
	Additive bool
}

type CompSlice

type CompSlice []*Comp

func (CompSlice) Len

func (comps CompSlice) Len() int

func (CompSlice) Less

func (comps CompSlice) Less(i, j int) bool

func (CompSlice) Swap

func (comps CompSlice) Swap(i, j int)

type Hook

type Hook interface{}

type MatchState

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

type MatchType

type MatchType int
const (
	MatchTypeNone MatchType = iota
	MatchTypeIncomplete
	MatchTypeLine
	MatchTypeWord
	MatchTypeIPv6
	MatchTypeIPv6Prefix
	MatchTypeIPv4
	MatchTypeIPv4Prefix
	MatchTypeRange
	MatchTypePartial
	MatchTypeExact
)

func MatchIPv4

func MatchIPv4(str string) (pos int, match MatchType)

func MatchIPv4Prefix

func MatchIPv4Prefix(line string) (pos int, match MatchType)

func MatchIPv6

func MatchIPv6(line string) (pos int, match MatchType)

func MatchIPv6Prefix

func MatchIPv6Prefix(line string) (pos int, match MatchType)

func MatchKeyword

func MatchKeyword(str, name string) (pos int, match MatchType)

func MatchLine

func MatchLine(str string) (pos int, match MatchType)

func MatchRange

func MatchRange(line string, min, max uint64) (pos int, match MatchType)

func MatchWord

func MatchWord(str string) (pos int, match MatchType)

type Mode

type Mode struct {
	Name     string
	TopLevel bool
	Prompt   string
	Header   string
	Parent   *Mode
	Modes    []*Mode
	Parser   *Node
}

func NewMode

func NewMode(name string, header string, prompt string) *Mode

func (*Mode) InstallHook

func (m *Mode) InstallHook(line string, hook Hook, args ...*Param)

func (*Mode) InstallLine

func (m *Mode) InstallLine(line string, fn Callback, args ...*Param)

type Node

type Node struct {
	Name      string
	Help      string
	Type      NodeType
	Privilege uint32
	Fn        Callback
	Hook      Hook
	Nodes     *NodeSlice
	Min       uint64
	Max       uint64
	Module    string
	Dynamic   []string
	Paren     bool
}

func NewNode

func NewNode() *Node

func NewNodeType

func NewNodeType(typ NodeType, lit string, paren bool) *Node

func NewParser

func NewParser() *Node

func (*Node) Dump

func (p *Node) Dump()

func (*Node) DumpNode

func (n *Node) DumpNode(depth int)

func (*Node) Install

func (p *Node) Install(s Scanner, fn Callback, args []*Param)

func (*Node) InstallCmd

func (p *Node) InstallCmd(cmd []string, fn Callback, args ...*Param)

func (*Node) InstallLine

func (p *Node) InstallLine(line string, fn Callback, args ...*Param)

func (*Node) LinkNodes

func (n *Node) LinkNodes(node *Node)

func (*Node) Lookup

func (n *Node) Lookup(name string) *Node

func (*Node) Match

func (n *Node) Match(str string, name string) (pos int, match MatchType)

func (*Node) MatchDynamic

func (n *Node) MatchDynamic(line string, command []string, state *MatchState)

func (*Node) MatchNode

func (n *Node) MatchNode(str string, name string, state *MatchState)

func (*Node) Parse

func (n *Node) Parse(line string, param *Param) (int, Callback, []interface{}, CompSlice)

func (*Node) ParseArgSet

func (n *Node) ParseArgSet(str string, param *Param)

func (*Node) ParseCmd

func (n *Node) ParseCmd(cmd []string, args ...*Param) (int, Callback, []interface{}, CompSlice)

func (*Node) ParseLine

func (n *Node) ParseLine(line string, args ...*Param) (int, Callback, []interface{}, CompSlice)

func (*Node) ParseMatch

func (n *Node) ParseMatch(line string, param *Param, state *MatchState)

func (*Node) String

func (n *Node) String() string

type NodeSlice

type NodeSlice []*Node

type NodeType

type NodeType int
const (
	NodeEOL NodeType = iota
	NodeKeyword
	NodeIPv4
	NodeIPv4Prefix
	NodeIPv6
	NodeIPv6Prefix
	NodeWord
	NodeLine
	NodeRange
	NodeDynamic
)

func Build

func Build(s Scanner, fn Callback, parent NodeSlice, head *NodeSlice, tail *NodeSlice, param *Param) NodeType

type Param

type Param struct {
	Command       []string
	Helps         []string
	HelpIndex     int
	Privilege     uint32
	Complete      bool
	Dynamic       bool
	TrailingSpace bool
	Args          []interface{}
	Hook          Hook
	Paren         bool
}

type Scanner

type Scanner interface {
	Scan() (NodeType, string)
}

func NewScannerCmd

func NewScannerCmd(cmd []string) Scanner

func NewScannerLine

func NewScannerLine(line string) Scanner

type ScannerCmd

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

ScannerCmd start.

func (*ScannerCmd) Scan

func (s *ScannerCmd) Scan() (typ NodeType, lit string)

type ScannerLine

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

func (*ScannerLine) Scan

func (s *ScannerLine) Scan() (typ NodeType, lit string)

Jump to

Keyboard shortcuts

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