cli

package module
v0.0.0-...-b459d38 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2015 License: BSD-3-Clause Imports: 8 Imported by: 42

README

Build Status godoc reference

go-cli

A minimalist framework for CLIs containing nested commands.

There's a surprising amount of entirely uninteresting code needed to create a human and machine friendly CLI such as

  • ensuring proper exit codes on invalid input
  • calculating sub-command list padding
  • parsing os.Args so each command is passed only the arguments scoped to it

See the example

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command interface {
	// The name of the command
	Name() string

	// A one-line description of this command
	ShortHelp() string

	// A multi-line description of this command.
	//
	// Its subcommands' ShortHelp message will also be printed.
	LongHelp() string

	// Execute executes with the remaining passed in arguments.
	//
	// Return false if the command can't execute which will display the
	// command's LongHelp message
	Execute([]string) bool

	// Any sub commands this command is capable of
	SubCommands() []Command
}

type Driver

type Driver struct {
	// This is exposed so commands creating flag.FlagSet can use the setting
	// on the driver for consistency
	ErrorHandling flag.ErrorHandling
	// contains filtered or unexported fields
}

func New

func New(errorHandling flag.ErrorHandling) *Driver

func NewWithEnv

func NewWithEnv(errorHandling flag.ErrorHandling, args []string, stdout io.Writer) *Driver

NewWithEnv inverts control of the outside world and enables testing

func (*Driver) ParseInput

func (d *Driver) ParseInput() error

func (*Driver) RegisterRoot

func (d *Driver) RegisterRoot(newRoot Command) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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