cli

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

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

Go to latest
Published: Dec 20, 2021 License: Apache-2.0 Imports: 13 Imported by: 3

README

cli

Helper library for command line apps written in Go

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownCommand  = errors.New("Unknown command")
	ErrRequiredCommand = errors.New("A command is required")
	ErrNoCommandFunc   = errors.New("No callback function was provided")
)
View Source
var ErrNoEditor = errors.New("No editor found in environment")

Functions

func Edit

func Edit(input []byte) (output []byte, err error)

func Query

func Query(reader io.Reader, writer io.Writer, message string, acceptable ...string) (resp string)

Types

type Arguments

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

func (*Arguments) Args

func (args *Arguments) Args() []string

func (*Arguments) Bool

func (args *Arguments) Bool(desc string) *bool

func (*Arguments) BoolVar

func (args *Arguments) BoolVar(p *bool, desc string)

func (*Arguments) Duration

func (args *Arguments) Duration(desc string) *time.Duration

func (*Arguments) DurationVar

func (args *Arguments) DurationVar(p *time.Duration, desc string)

func (*Arguments) Float64

func (args *Arguments) Float64(desc string) *float64

func (*Arguments) Float64Var

func (args *Arguments) Float64Var(p *float64, desc string)

func (*Arguments) Int

func (args *Arguments) Int(desc string) *int

func (*Arguments) Int64

func (args *Arguments) Int64(desc string) *int64

func (*Arguments) Int64Var

func (args *Arguments) Int64Var(p *int64, desc string)

func (*Arguments) IntVar

func (args *Arguments) IntVar(p *int, desc string)

func (*Arguments) Len

func (args *Arguments) Len() int

func (*Arguments) Parse

func (args *Arguments) Parse(input []string) error

func (*Arguments) String

func (args *Arguments) String(desc string) *string

func (*Arguments) StringVar

func (args *Arguments) StringVar(p *string, desc string)

func (*Arguments) Uint

func (args *Arguments) Uint(desc string) *uint

func (*Arguments) Uint64

func (args *Arguments) Uint64(desc string) *uint64

func (*Arguments) Uint64Var

func (args *Arguments) Uint64Var(p *uint64, desc string)

func (*Arguments) UintVar

func (args *Arguments) UintVar(p *uint, desc string)

func (*Arguments) Usage

func (args *Arguments) Usage(writer io.Writer)

func (*Arguments) Var

func (args *Arguments) Var(value Value, desc string)

func (*Arguments) VarSlice

func (args *Arguments) VarSlice(value SliceValue, desc string)

type Command

type Command struct {
	Name        string
	Description string
	Usage       string
	Callback    CommandFunc
	SubCommands []*Command
	Flags       flag.FlagSet
	// contains filtered or unexported fields
}

Command represents a single cli command. The idea is that a cli app is run such as:

program cmd <flags>

and can have nested commands:

program cmd1 <flags> subcmd1 <flags> ...

a Command object represents a single command in the hierarchy and is a placeholder to register subcommands

func New

func New(name string, options ...Option) *Command

New will return a Command object that is initialized according to the supplied command options

func (*Command) Lookup

func (cmd *Command) Lookup(name string) (subcmd *Command, found bool)

func (*Command) Run

func (cmd *Command) Run(args []string) ([]string, error)

func (*Command) SetOutput

func (cmd *Command) SetOutput(writer io.Writer)

SetOutput will set the io.Writer used for printing usage

func (*Command) SubCommand

func (cmd *Command) SubCommand(name string, options ...Option) *Command

SubCommand adds a subcommand to the current command hierarchy

type CommandFunc

type CommandFunc func(name string, args ...string) ([]string, error)

CommandFunc is the callback function that will be executed when a command is called. If the CommandFunc returns a non-nil error then processing stops immediately

func Callback

func Callback(f interface{}, descriptions ...string) CommandFunc

type ErrorHandling

type ErrorHandling int
const (
	ExitOnError     ErrorHandling = iota // Print usage and Call os.Exit(2).
	ContinueOnError                      // Return a descriptive error.
	PanicOnError                         // Call panic with a descriptive error.
)

type Option

type Option func(*Command)

func CallbackOption

func CallbackOption(callback CommandFunc) Option

func DescOption

func DescOption(description string) Option

func ErrorHandlingOption

func ErrorHandlingOption(errorHandling ErrorHandling) Option

func OutputOption

func OutputOption(output io.Writer) Option

func UsageOption

func UsageOption(usageStr string) Option

type SliceValue

type SliceValue interface {
	String() string
	Set([]string) error
}

type Value

type Value interface {
	String() string
	Set(string) error
}

Jump to

Keyboard shortcuts

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