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: 10 modules, 12 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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
⌂ 换网址