router

package
v0.0.0-...-a75bd19 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Leaf

type Leaf struct {
	Command comm.Command
	Leaves  map[string]*Leaf
}

Leaf is a leaf of the command router tree.

func NewLeaf

func NewLeaf(com comm.Command) *Leaf

NewLeaf returns a Leaf with the command.

type Router

type Router struct {
	Routes *Leaf
}

Router routes a command string to a command.

func NewRouter

func NewRouter() *Router

NewRouter returns a new Router structure.

func (*Router) AddCommand

func (r *Router) AddCommand(com comm.Command)

AddCommand adds command-string mapping

func (*Router) Route

func (r *Router) Route(argv []string) (comm.Command, int)

Route routes to handler from string. Returns the command and the number of matched args. e.g.

	   // r has a route through "example"->"command"->"string"
    com, ind := r.Route([]string{"example", "command", "string", "with", "args"})

`com` will contain the command at "string" leaf `ind` will be 3

func (*Router) ToSlice

func (r *Router) ToSlice() []comm.Command

ToSlice searches the tree and populates a slice of Commands sorted by the first alias name

Duplicates are removed in case you were wondering

func (*Router) ToStringSlice

func (r *Router) ToStringSlice() []string

ToStringSlice wraps ToSlice and populates a strings slice of aliases

Jump to

Keyboard shortcuts

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