internal

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidUsage = errors.New("invalid usage")

ErrInvalidUsage when returned by a Handler the usage message is displayed.

Functions

func ArgsToMap

func ArgsToMap(s []string) (map[string]string, error)

sliceToMap converts sequence of arguments into a key-value map. [a, b, c, d] => {a: b, c: d} or errors when number of args is not even.

func OutputJSON

func OutputJSON(v interface{}, compress bool) error

OutputJSON prints indented json to stdout.

func OutputLine

func OutputLine(format string) error

OutputLine prints the given string to stdout appending a new-line char.

Types

type CLI

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

CLI is a cli subcommands executor.

func New

func New(desc string, f FlagFunc, cmds []*Command) (*CLI, error)

New creates new cli executor.

func (*CLI) Run

func (r *CLI) Run(ctx context.Context, argv ...string) error

Run runs one or the given commands based on argv.

Panics if argv is empty.

If ErrInvalidUsage is returned there's no need to print it, the usage message is already sent to STDERR.

type Command

type Command struct {
	Name      string
	Alias     string
	Help      string
	Desc      string
	Handler   HandlerFunc
	ParseFunc func(*flag.FlagSet)
}

Command is a cli subcommand.

type FlagFunc

type FlagFunc func(fs *flag.FlagSet)

FlagFunc prepares fs for parsing, setting flags.

type HandlerFunc

type HandlerFunc func(ctx context.Context, fs *flag.FlagSet) error

HandlerFunc is a subcommand handler, fs is already parsed.

Jump to

Keyboard shortcuts

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