cli

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2018 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExitStatusSuccess = iota
	ExitStatusUnknownError
	ExitStatusInvalidArgs
)

Constants for exit statuses

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Commands []Command
	Flags    []Flag

	// UserOut logs messages to end-users
	UserOut io.Writer
	// UserErr logs errors to end-users
	UserErr io.Writer
	// InternalOut logs messages to ops
	InternalOut io.Writer

	Before func(c *Context) error

	Exit <-chan struct{}
}

App is the main structure for any CLI application

func (*App) Run

func (a *App) Run(args []string) (int, error)

Run executed the command with the provided arguments

type BoolFlag

type BoolFlag struct {
	Name  string
	Usage string
}

BoolFlag holds a single args boolean flag

func (BoolFlag) Apply

func (flag BoolFlag) Apply(set *flag.FlagSet)

Apply applies a boolean flag to the FlagSet

type Command

type Command struct {
	Name  string
	Flags []Flag

	Run func(context *Context) (exitStatus int, err error)
}

Command holds a single subcommand

type Context

type Context struct {
	App         *App
	CommandName string
	Command     *Command
	Flags       *FlagSet
	Args        []string
	Exit        <-chan struct{}
}

Context holds the context of a command execution

type Flag

type Flag interface {
	Apply(*flag.FlagSet)
}

Flag is the basic interface for all flags

type FlagSet

type FlagSet struct {
	*flag.FlagSet
}

FlagSet encapsulates the args flags

func NewFlagSet

func NewFlagSet(name string, args []string, flags []Flag) (*FlagSet, error)

NewFlagSet creates a new flag.FlagSet object and parses the flags

func (*FlagSet) Bool

func (f *FlagSet) Bool(name string) bool

Bool looks up a flag as boolean

func (*FlagSet) Int

func (f *FlagSet) Int(name string) int

Int looks up a flag as integer

func (*FlagSet) String

func (f *FlagSet) String(name string) string

String looks up a flag as a string

func (*FlagSet) StringSlice

func (f *FlagSet) StringSlice(name string) []string

StringSlice looks up a flag as an array of strings

type IntFlag

type IntFlag struct {
	Name  string
	Value int
	Usage string
}

IntFlag holds a single args integer flag

func (IntFlag) Apply

func (flag IntFlag) Apply(set *flag.FlagSet)

Apply applies a flag to the FlagSet

type StringFlag

type StringFlag struct {
	Name  string
	Value string
	Usage string
}

StringFlag holds a single args string flag

func (StringFlag) Apply

func (flag StringFlag) Apply(set *flag.FlagSet)

Apply applies a flag to the FlagSet

type StringSliceFlag

type StringSliceFlag struct {
	Name  string
	Value *stringSlice
	Usage string
}

StringSliceFlag holds a single args string flag

func (StringSliceFlag) Apply

func (flag StringSliceFlag) Apply(set *flag.FlagSet)

Apply applies a flag to the FlagSet

Jump to

Keyboard shortcuts

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