cli

package module
v0.0.0-...-45b367f Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2016 License: MIT Imports: 1 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cli

type Cli struct {
	HelpMsg string
	// contains filtered or unexported fields
}

Cli is a command interface. It executes the subcommand from its arguments list or a default command.

func New

func New() *Cli

New Creates a new Cli to be used to handle a set of sub-commands.

func (*Cli) Execute

func (c *Cli) Execute(args []string)

Execute checks the first argument and executes the matching sub-command if any. If no arguments are present it executes the Cli.defaultCmd. If the first argument does not match a sub-command it prints the Cli.HelpMsg.

func (*Cli) Handle

func (c *Cli) Handle(cmd string, handler Command)

Handle registers the handler for a given command.

func (*Cli) HandleDefault

func (c *Cli) HandleDefault(handler Command)

HandleDefault registers the default command to be executed if no arguments are given. If no arguments are given and Cli.defaultCmd == nil the Cli.HelpMsg will be printed.

func (*Cli) HandleDefaultFunc

func (c *Cli) HandleDefaultFunc(handler cmdFunc)

HandleDefaultFunc registers a function to handle the default command to be executed if no arguments are given.

func (*Cli) HandleFunc

func (c *Cli) HandleFunc(cmd string, handler cmdFunc)

HandleFunc registers a function to handle a given command.

type Command

type Command interface {
	Execute([]string)
}

Objects implementing the Command interface can be registered to handle paticular sub-commands in a cli.

Jump to

Keyboard shortcuts

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