console

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 License: AGPL-3.0 Imports: 22 Imported by: 11

README

Console

Console tries to mimick the Symfony PHP Console component as much as possible, but in Go.

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	NoInteractionFlag = &BoolFlag{
		Name:  "no-interaction",
		Usage: "Disable all interactions",
	}
	NoAnsiFlag = &BoolFlag{
		Name:  "no-ansi",
		Usage: "Disable ANSI output",
	}
	AnsiFlag = &BoolFlag{
		Name:  "ansi",
		Usage: "Force ANSI output",
	}
)
View Source
var AppHelpTemplate = `` /* 687-byte string literal not displayed */

AppHelpTemplate is the text template for the Default help topic. cli.go uses text/template to render templates. You can render custom help text by setting this variable.

View Source
var CategoryHelpTemplate = `` /* 652-byte string literal not displayed */

CategoryHelpTemplate is the text template for the category help topic. cli.go uses text/template to render templates. You can render custom help text by setting this variable.

View Source
var CommandHelpTemplate = `` /* 393-byte string literal not displayed */

CommandHelpTemplate is the text template for the command help topic. cli.go uses text/template to render templates. You can render custom help text by setting this variable.

View Source
var HelpFlag = &BoolFlag{
	Name:    "help",
	Aliases: []string{"h"},
	Usage:   "Show help",
}

HelpFlag prints the help for all commands and subcommands. Set to nil to disable the flag.

View Source
var HelpPrinter helpPrinter = printHelp

HelpPrinter is a function that writes the help output. If not set a default is used. The function signature is: func(w io.Writer, templ string, data interface{})

View Source
var LogLevelFlag = VerbosityFlag("log-level", "verbose", "v")
View Source
var OsExiter = os.Exit

OsExiter is the function used when the app exits. If not set defaults to os.Exit.

View Source
var QuietFlag = newQuietFlag("quiet", "q")
View Source
var VersionFlag = &BoolFlag{
	Name:  "V",
	Usage: "Print the version",
}

VersionFlag prints the version for the application

View Source
var VersionPrinter = printVersion

VersionPrinter prints the version for the App

Functions

func CurrentBinaryName

func CurrentBinaryName() string

func CurrentBinaryPath

func CurrentBinaryPath() (string, error)

func ExpandHome

func ExpandHome(path string) string

func FormatErrorChain

func FormatErrorChain(buf *bytes.Buffer, err error, trimPaths bool) bool

func HandleError

func HandleError(err error)

func HandleExitCoder

func HandleExitCoder(err error)

HandleExitCoder checks if the error fulfills the ExitCoder interface, and if so prints the error to stderr (if it is non-empty) and calls OsExiter with the given exit code. If the given error is a MultiError, then this func is called on all members of the Errors slice.

func Hide

func Hide() bool

func IsHelp

func IsHelp(c *Context) bool

func ShowAppHelp

func ShowAppHelp(c *Context) error

ShowAppHelp is an action that displays the help.

func ShowAppHelpAction

func ShowAppHelpAction(c *Context) error

ShowAppHelpAction is an action that displays the global help or for the specified command.

func ShowCommandHelp

func ShowCommandHelp(ctx *Context, command string) error

ShowCommandHelp prints help for the given command

func ShowVersion

func ShowVersion(c *Context)

ShowVersion prints the version number of the App

func VerbosityFlag

func VerbosityFlag(name, alias, shortAlias string) *verbosityFlag

func WrapPanic

func WrapPanic(msg interface{}) error

Types

type ActionFunc

type ActionFunc func(*Context) error

ActionFunc is the action to execute when no subcommands are specified

type AfterFunc

type AfterFunc func(*Context) error

AfterFunc is an action to execute after any subcommands are run, but after the subcommand has finished it is run even if Action() panics

type Alias

type Alias struct {
	Name   string
	Hidden bool
}

func (*Alias) String

func (a *Alias) String() string

type Application

type Application struct {
	// The name of the program. Defaults to filepath.Base(os.Executable())
	Name string
	// Full name of command for help, defaults to Name
	HelpName string
	// Description of the program.
	Usage string
	// Version of the program
	Version string
	// Channel of the program (dev, beta, stable, ...)
	Channel string
	// Description of the program
	Description string
	// List of commands to execute
	Commands []*Command
	// List of flags to parse
	Flags []Flag
	// Prefix used to automatically find flag in environment
	FlagEnvPrefix []string
	// Categories contains the categorized commands and is populated on app startup
	Categories CommandCategories
	// An action to execute before any subcommands are run, but after the context is ready
	// If a non-nil error is returned, no subcommands are run
	Before BeforeFunc
	// An action to execute after any subcommands are run, but after the subcommand has finished
	// It is run even if Action() panics
	After AfterFunc
	// The action to execute when no subcommands are specified
	Action ActionFunc
	// Build date
	BuildDate string
	// Copyright of the binary if any
	Copyright string
	// Writer writer to write output to
	Writer io.Writer
	// ErrWriter writes error output
	ErrWriter io.Writer
	// contains filtered or unexported fields
}

Application is the main structure of a cli application.

func (*Application) BestCommand added in v1.0.3

func (a *Application) BestCommand(name string) *Command

BestCommand returns the named command on App or a command fuzzy matching if there is only one. Returns nil if the command does not exist of if the fuzzy matching find more than one.

func (*Application) Category

func (a *Application) Category(name string) *CommandCategory

Category returns the named CommandCategory on App. Returns nil if the category does not exist

func (*Application) Command

func (a *Application) Command(name string) *Command

Command returns the named command on App. Returns nil if the command does not exist

func (*Application) Run

func (a *Application) Run(arguments []string) (err error)

Run is the entry point to the cli app. Parses the arguments slice and routes to the proper flag/args combination

Example
// set args for examples sake
os.Args = []string{"greet", "--name", "Jeremy"}

app := &Application{
	Writer:    os.Stdout,
	ErrWriter: os.Stderr,
	Name:      "greet",
	Flags: []Flag{
		&StringFlag{Name: "name", DefaultValue: "bob", Usage: "a name to say"},
	},
	Action: func(c *Context) error {
		fmt.Printf("Hello %v\n", c.String("name"))
		return nil
	},
}

app.Run(os.Args)
Output:

Hello Jeremy
Example (CommandHelp)
// set args for examples sake
os.Args = []string{"greet", "help", "describeit"}

app := &Application{
	Writer:    os.Stdout,
	ErrWriter: os.Stderr,
	Name:      "greet",
	HelpName:  "greet",
	Flags: []Flag{
		&StringFlag{Name: "name", DefaultValue: "bob", Usage: "a name to say"},
	},
	Commands: []*Command{
		{
			Name:        "describeit",
			Aliases:     []*Alias{{Name: "d"}},
			Usage:       "use it to see a description",
			Description: "This is how we describe describeit the function",
			Action: func(c *Context) error {
				fmt.Printf("i like to describe things")
				return nil
			},
		},
	},
}
app.Run(os.Args)
Output:

<comment>Description:</>
  use it to see a description

<comment>Usage:</>
  greet describeit

<comment>Help:</>

  This is how we describe describeit the function
Example (Quiet)
// set args for examples sake
os.Args = []string{"greet", "-q", "--name", "Jeremy"}

app := &Application{
	Writer:    os.Stdout,
	ErrWriter: os.Stdout,
	Name:      "greet",
	Flags: []Flag{
		&StringFlag{Name: "name", DefaultValue: "bob", Usage: "a name to say"},
	},
	Action: func(c *Context) error {
		fmt.Fprintf(c.App.Writer, "Hello %v\n", c.String("name"))
		fmt.Fprintf(c.App.ErrWriter, "Byebye %v\n", c.String("name"))
		return nil
	},
}

app.Run(os.Args)
Output:

Example (QuietDisabled)
terminal.DefaultStdout = terminal.NewBufferedConsoleOutput(os.Stdout, os.Stdout)
// set args for examples sake
os.Args = []string{"greet", "--quiet=false", "--name", "Jeremy"}

app := &Application{
	Writer:    os.Stdout,
	ErrWriter: os.Stdout,
	Name:      "greet",
	Flags: []Flag{
		&StringFlag{Name: "name", DefaultValue: "bob", Usage: "a name to say"},
	},
	Action: func(c *Context) error {
		fmt.Fprintf(c.App.Writer, "Hello %v\n", c.String("name"))
		fmt.Fprintf(c.App.ErrWriter, "Byebye %v\n", c.String("name"))
		return nil
	},
}

app.Run(os.Args)
Output:

Hello Jeremy
Byebye Jeremy

func (*Application) VisibleCategories

func (a *Application) VisibleCategories() []CommandCategory

VisibleCategories returns a slice of categories and commands that are Hidden=false

func (*Application) VisibleCommands

func (a *Application) VisibleCommands() []*Command

VisibleCommands returns a slice of the Commands with Hidden=false

func (*Application) VisibleFlags

func (a *Application) VisibleFlags() []Flag

VisibleFlags returns a slice of the Flags with Hidden=false

type Arg

type Arg struct {
	Name, Default string
	Description   string
	Optional      bool
	Slice         bool
}

func (*Arg) String

func (a *Arg) String() string

type ArgDefinition

type ArgDefinition []*Arg

func (ArgDefinition) Usage

func (def ArgDefinition) Usage() string

type Args

type Args interface {
	// Get returns the named argument, or else a blank string
	Get(name string) string

	// Tail returns the rest of the arguments (the last "array" one)
	// or else an empty string slice
	Tail() []string
	// Len returns the length of the wrapped slice
	Len() int
	// Present checks if there are any arguments present
	Present() bool
	// Slice returns a copy of the internal slice
	Slice() []string
	// contains filtered or unexported methods
}

type BeforeFunc

type BeforeFunc func(*Context) error

BeforeFunc is an action to execute before any subcommands are run, but after the context is ready if a non-nil error is returned, no subcommands are run

type BoolFlag

type BoolFlag struct {
	Name         string
	Aliases      []string
	Usage        string
	EnvVars      []string
	Hidden       bool
	DefaultValue bool
	DefaultText  string
	Required     bool
	Validator    func(*Context, bool) error
	Destination  *bool
}

BoolFlag is a flag with type bool

func (*BoolFlag) Apply

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

Apply populates the flag given the flag set and environment

func (*BoolFlag) Names

func (f *BoolFlag) Names() []string

Names returns the names of the flag

func (*BoolFlag) String

func (f *BoolFlag) String() string

String returns a readable representation of this value (for usage defaults)

func (*BoolFlag) Validate

func (f *BoolFlag) Validate(c *Context) error

type Command

type Command struct {
	// The name of the command
	Name string
	// A list of aliases for the command
	Aliases []*Alias
	// A short description of the usage of this command
	Usage string
	// A longer explanation of how the command works
	Description string
	// The category the command is part of
	Category string
	// An action to execute before any sub-subcommands are run, but after the context is ready
	// If a non-nil error is returned, no sub-subcommands are run
	Before BeforeFunc
	// An action to execute after any subcommands are run, but after the subcommand has finished
	// It is run even if Action() panics
	After AfterFunc
	// The function to call when this command is invoked
	Action ActionFunc
	// List of flags to parse
	Flags []Flag
	// List of args to parse
	Args ArgDefinition
	// Treat all flags as normal arguments if true
	FlagParsing FlagParsingMode
	// Boolean to hide this command from help
	Hidden func() bool
	// Full name of command for help, defaults to full command name, including parent commands.
	HelpName string
	// The name used on the CLI by the user
	UserName string
	// contains filtered or unexported fields
}

Command is a subcommand for a console.App.

func (*Command) Arguments

func (c *Command) Arguments() ArgDefinition

Arguments returns a slice of the Arguments

func (*Command) FullName

func (c *Command) FullName() string

FullName returns the full name of the command. For subcommands this ensures that parent commands are part of the command path

func (*Command) HasName

func (c *Command) HasName(name string, exact bool) bool

HasName returns true if Command.Name matches given name

func (*Command) Names

func (c *Command) Names() []string

Names returns the names including short names and aliases.

func (*Command) PreferredName

func (c *Command) PreferredName() string

func (*Command) Run

func (c *Command) Run(ctx *Context) (err error)

Run invokes the command given the context, parses ctx.Args() to generate command-specific flags

func (*Command) VisibleFlags

func (c *Command) VisibleFlags() []Flag

VisibleFlags returns a slice of the Flags with Hidden=false

type CommandCategories

type CommandCategories interface {
	// AddCommand adds a command to a category, creating a new category if necessary.
	AddCommand(category string, command *Command)
	// Categories returns a copy of the category slice
	Categories() []CommandCategory
}

type CommandCategory

type CommandCategory interface {
	// Name returns the category name string
	Name() string
	// VisibleCommands returns a slice of the Commands with Hidden=false
	VisibleCommands() []*Command
}

CommandCategory is a category containing commands.

type CommandNotFoundError

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

func (*CommandNotFoundError) Error

func (e *CommandNotFoundError) Error() string

func (*CommandNotFoundError) ExitCode

func (e *CommandNotFoundError) ExitCode() int

func (*CommandNotFoundError) GetSeverity

func (e *CommandNotFoundError) GetSeverity() zerolog.Level

type CommandNotFoundFunc

type CommandNotFoundFunc func(*Context, string) error

CommandNotFoundFunc is executed if the proper command cannot be found

type Context

type Context struct {
	App     *Application
	Command *Command
	// contains filtered or unexported fields
}

Context is a type that is passed through to each Handler action in a cli application. Context can be used to retrieve context-specific args and parsed command-line options.

func NewContext

func NewContext(app *Application, set *flag.FlagSet, parentCtx *Context) *Context

NewContext creates a new context. For use in when invoking an App or Command action.

func (*Context) Args

func (c *Context) Args() Args

func (*Context) Bool

func (c *Context) Bool(name string) bool

Bool looks up the value of a local BoolFlag, returns false if not found

func (*Context) Duration

func (c *Context) Duration(name string) time.Duration

Duration looks up the value of a local DurationFlag, returns 0 if not found

func (*Context) Float64

func (c *Context) Float64(name string) float64

Float64 looks up the value of a local Float64Flag, returns 0 if not found

func (*Context) Float64Slice

func (c *Context) Float64Slice(name string) []float64

Float64Slice looks up the value of a local Float64SliceFlag, returns nil if not found

func (*Context) Generic

func (c *Context) Generic(name string) interface{}

Generic looks up the value of a local GenericFlag, returns nil if not found

func (*Context) HasFlag

func (c *Context) HasFlag(name string) bool

HasFlag determines if a flag is defined in this context and all of its parent contexts.

func (*Context) Int

func (c *Context) Int(name string) int

Int looks up the value of a local IntFlag, returns 0 if not found

func (*Context) Int64

func (c *Context) Int64(name string) int64

Int64 looks up the value of a local Int64Flag, returns 0 if not found

func (*Context) Int64Slice

func (c *Context) Int64Slice(name string) []int64

Int64Slice looks up the value of a local Int64SliceFlag, returns nil if not found

func (*Context) IntSlice

func (c *Context) IntSlice(name string) []int

IntSlice looks up the value of a local IntSliceFlag, returns nil if not found

func (*Context) IsSet

func (c *Context) IsSet(name string) bool

IsSet determines if the flag was actually set

func (*Context) Lineage

func (c *Context) Lineage() []*Context

Lineage returns *this* context and all of its ancestor contexts in order from child to parent

func (*Context) NArg

func (c *Context) NArg() int

NArg returns the number of the command line arguments.

func (*Context) Set

func (c *Context) Set(name, value string) error

Set assigns a value to a context flag.

func (*Context) String

func (c *Context) String(name string) string

String looks up the value of a local StringFlag, returns "" if not found

func (*Context) StringMap

func (c *Context) StringMap(name string) map[string]string

StringMap looks up the value of a local StringMapFlag, returns nil if not found

func (*Context) StringSlice

func (c *Context) StringSlice(name string) []string

StringSlice looks up the value of a local StringSliceFlag, returns nil if not found

func (*Context) Uint

func (c *Context) Uint(name string) uint

Uint looks up the value of a local UintFlag, returns 0 if not found

func (*Context) Uint64

func (c *Context) Uint64(name string) uint64

Uint64 looks up the value of a local Uint64Flag, returns 0 if not found

type DurationFlag

type DurationFlag struct {
	Name         string
	Aliases      []string
	Usage        string
	EnvVars      []string
	Hidden       bool
	DefaultValue time.Duration
	DefaultText  string
	Required     bool
	Validator    func(*Context, time.Duration) error
	Destination  *time.Duration
}

DurationFlag is a flag with type time.Duration (see https://golang.org/pkg/time/#ParseDuration)

func (*DurationFlag) Apply

func (f *DurationFlag) Apply(set *flag.FlagSet)

Apply populates the flag given the flag set and environment

func (*DurationFlag) Names

func (f *DurationFlag) Names() []string

Names returns the names of the flag

func (*DurationFlag) String

func (f *DurationFlag) String() string

String returns a readable representation of this value (for usage defaults)

func (*DurationFlag) Validate

func (f *DurationFlag) Validate(c *Context) error

type ExitCoder

type ExitCoder interface {
	error
	ExitCode() int
}

ExitCoder is the interface checked by `App` and `Command` for a custom exit code

func Exit

func Exit(message string, exitCode int) ExitCoder

Exit wraps a message and exit code into an ExitCoder suitable for handling by HandleExitCoder

type Flag

type Flag interface {
	fmt.Stringer
	Validate(*Context) error
	// Apply Flag settings to the given flag set
	Apply(*flag.FlagSet)
	Names() []string
}

Flag is a common interface related to parsing flags in cli. For more advanced flag parsing techniques, it is recommended that this interface be implemented.

type FlagParsingMode

type FlagParsingMode int

FlagParsingMode defines how arguments and flags parsing is done. Three different values: FlagParsingNormal, FlagParsingSkipped and FlagParsingSkippedAfterFirstArg.

const (
	// FlagParsingNormal sets parsing to a normal mode, complete parsing of all
	// flags found after command name
	FlagParsingNormal FlagParsingMode = iota
	// FlagParsingSkipped sets parsing to a mode where parsing stops just after
	// the command name.
	FlagParsingSkipped
	// FlagParsingSkippedAfterFirstArg sets parsing to a hybrid mode where parsing continues
	// after the command name until an argument is found.
	// This for example allows usage like `blackfire -v=4 run --samples=2 php foo.php`
	FlagParsingSkippedAfterFirstArg
)

func (FlagParsingMode) IsPostfix

func (mode FlagParsingMode) IsPostfix() bool

func (FlagParsingMode) IsPrefix

func (mode FlagParsingMode) IsPrefix() bool

type FlagStringFunc

type FlagStringFunc func(Flag) string

FlagStringFunc is used by the help generation to display a flag, which is expected to be a single line.

var FlagStringer FlagStringFunc = stringifyFlag

FlagStringer converts a flag definition to a string. This is used by help to display a flag.

type FlagsByName

type FlagsByName []Flag

FlagsByName is a slice of Flag.

func (FlagsByName) Len

func (f FlagsByName) Len() int

func (FlagsByName) Less

func (f FlagsByName) Less(i, j int) bool

func (FlagsByName) Swap

func (f FlagsByName) Swap(i, j int)

type Float64Flag

type Float64Flag struct {
	Name         string
	Aliases      []string
	Usage        string
	EnvVars      []string
	Hidden       bool
	DefaultValue float64
	DefaultText  string
	Required     bool
	Validator    func(*Context, float64) error
	Destination  *float64
}

Float64Flag is a flag with type float64

func (*Float64Flag) Apply

func (f *Float64Flag) Apply(set *flag.FlagSet)

Apply populates the flag given the flag set and environment

func (*Float64Flag) Names

func (f *Float64Flag) Names() []string

Names returns the names of the flag

func (*Float64Flag) String

func (f *Float64Flag) String() string

String returns a readable representation of this value (for usage defaults)

func (*Float64Flag) Validate

func (f *Float64Flag) Validate(c *Context) error

type Float64Slice

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

Float64Slice is an opaque type for []float64 to satisfy flag.Value

func NewFloat64Slice

func NewFloat64Slice(defaults ...float64) *Float64Slice

NewFloat64Slice makes a *Float64Slice with default values

func (*Float64Slice) Serialized

func (f *Float64Slice) Serialized() string

Serialized allows Float64Slice to fulfill Serializeder

func (*Float64Slice) Set

func (f *Float64Slice) Set(value string) error

Set parses the value into a float64 and appends it to the list of values

func (*Float64Slice) String

func (f *Float64Slice) String() string

String returns a readable representation of this value (for usage defaults)

func (*Float64Slice) Value

func (f *Float64Slice) Value() []float64

Value returns the slice of float64s set by this flag

type Float64SliceFlag

type Float64SliceFlag struct {
	Name        string
	Aliases     []string
	Usage       string
	EnvVars     []string
	Hidden      bool
	DefaultText string
	Required    bool
	Validator   func(*Context, []float64) error
	Destination *Float64Slice
}

Float64SliceFlag is a flag with type *Float64Slice

func (*Float64SliceFlag) Apply

func (f *Float64SliceFlag) Apply(set *flag.FlagSet)

Apply populates the flag given the flag set and environment

func (*Float64SliceFlag) Names

func (f *Float64SliceFlag) Names() []string

Names returns the names of the flag

func (*Float64SliceFlag) String

func (f *Float64SliceFlag) String() string

String returns a readable representation of this value (for usage defaults)

func (*Float64SliceFlag) Validate

func (f *Float64SliceFlag) Validate(c *Context) error

type Generic

type Generic interface {
	Set(value string) error
	String() string
}

Generic is a generic parseable type identified by a specific flag

type GenericFlag

type GenericFlag struct {
	Name        string
	Aliases     []string
	Usage       string
	EnvVars     []string
	Hidden      bool
	DefaultText string
	Required    bool
	Validator   func(*Context, interface{}) error
	Destination Generic
}

GenericFlag is a flag with type Generic

func (*GenericFlag) Apply

func (f *GenericFlag) Apply(set *flag.FlagSet)

Apply takes the flagset and calls Set on the generic flag with the value provided by the user for parsing by the flag

func (*GenericFlag) Names

func (f *GenericFlag) Names() []string

Names returns the names of the flag

func (*GenericFlag) String

func (f *GenericFlag) String() string

String returns a readable representation of this value (for usage defaults)

func (*GenericFlag) Validate

func (f *GenericFlag) Validate(c *Context) error

type IncorrectUsageError

type IncorrectUsageError struct {
	ParentError error
}

func (IncorrectUsageError) Cause

func (e IncorrectUsageError) Cause() error

func (IncorrectUsageError) Error

func (e IncorrectUsageError) Error() string

type Int64Flag

type Int64Flag struct {
	Name         string
	Aliases      []string
	Usage        string
	EnvVars      []string
	Hidden       bool
	DefaultValue int64
	DefaultText  string
	Required     bool
	Validator    func(*Context, int64) error
	Destination  *int64
}

Int64Flag is a flag with type int64

func (*Int64Flag) Apply

func (f *Int64Flag) Apply(set *flag.FlagSet)

Apply populates the flag given the flag set and environment

func (*Int64Flag) Names

func (f *Int64Flag) Names() []string

Names returns the names of the flag

func (*Int64Flag) String

func (f *Int64Flag) String() string

String returns a readable representation of this value (for usage defaults)

func (*Int64Flag) Validate

func (f *Int64Flag) Validate(c *Context) error

type Int64Slice

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

Int64Slice is an opaque type for []int to satisfy flag.Value

func NewInt64Slice

func NewInt64Slice(defaults ...int64) *Int64Slice

NewInt64Slice makes an *Int64Slice with default values

func (*Int64Slice) Serialized

func (f *Int64Slice) Serialized() string

Serialized allows Int64Slice to fulfill Serializeder

func (*Int64Slice) Set

func (f *Int64Slice) Set(value string) error

Set parses the value into an integer and appends it to the list of values

func (*Int64Slice) String

func (f *Int64Slice) String() string

String returns a readable representation of this value (for usage defaults)

func (*Int64Slice) Value

func (f *Int64Slice) Value() []int64

Value returns the slice of ints set by this flag

type Int64SliceFlag

type Int64SliceFlag struct {
	Name        string
	Aliases     []string
	Usage       string
	EnvVars     []string
	Hidden      bool
	DefaultText string
	Required    bool
	Validator   func(*Context, []int64) error
	Destination *Int64Slice
}

Int64SliceFlag is a flag with type *Int64Slice

func (*Int64SliceFlag) Apply

func (f *Int64SliceFlag) Apply(set *flag.FlagSet)

Apply populates the flag given the flag set and environment

func (*Int64SliceFlag) Names

func (f *Int64SliceFlag) Names() []string

Names returns the names of the flag

func (*Int64SliceFlag) String

func (f *Int64SliceFlag) String() string

String returns a readable representation of this value (for usage defaults)

func (*Int64SliceFlag) Validate

func (f *Int64SliceFlag) Validate(c *Context) error

type IntFlag

type IntFlag struct {
	Name         string
	Aliases      []string
	Usage        string
	EnvVars      []string
	Hidden       bool
	DefaultValue int
	DefaultText  string
	Required     bool
	Validator    func(*Context, int) error
	Destination  *int
}

IntFlag is a flag with type int

func (*IntFlag) Apply

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

Apply populates the flag given the flag set and environment

func (*IntFlag) Names

func (f *IntFlag) Names() []string

Names returns the names of the flag

func (*IntFlag) String

func (f *IntFlag) String() string

String returns a readable representation of this value (for usage defaults)

func (*IntFlag) Validate

func (f *IntFlag) Validate(c *Context) error

type IntSlice

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

IntSlice wraps an []int to satisfy flag.Value

func NewIntSlice

func NewIntSlice(defaults ...int) *IntSlice

NewIntSlice makes an *IntSlice with default values

func (*IntSlice) Serialized

func (i *IntSlice) Serialized() string

Serialized allows IntSlice to fulfill Serializeder

func (*IntSlice) Set

func (i *IntSlice) Set(value string) error

Set parses the value into an integer and appends it to the list of values

func (*IntSlice) SetInt

func (i *IntSlice) SetInt(value int)

SetInt directly adds an integer to the list of values

func (*IntSlice) String

func (i *IntSlice) String() string

String returns a readable representation of this value (for usage defaults)

func (*IntSlice) Value

func (i *IntSlice) Value() []int

Value returns the slice of ints set by this flag

type IntSliceFlag

type IntSliceFlag struct {
	Name        string
	Aliases     []string
	Usage       string
	EnvVars     []string
	Hidden      bool
	DefaultText string
	Required    bool
	Validator   func(*Context, []int) error
	Destination *IntSlice
}

IntSliceFlag is a flag with type *IntSlice

func (*IntSliceFlag) Apply

func (f *IntSliceFlag) Apply(set *flag.FlagSet)

Apply populates the flag given the flag set and environment

func (*IntSliceFlag) Names

func (f *IntSliceFlag) Names() []string

Names returns the names of the flag

func (*IntSliceFlag) String

func (f *IntSliceFlag) String() string

String returns a readable representation of this value (for usage defaults)

func (*IntSliceFlag) Validate

func (f *IntSliceFlag) Validate(c *Context) error

type MultiError

type MultiError interface {
	error
	// Errors returns a copy of the errors slice
	Errors() []error
}

MultiError is an error that wraps multiple errors.

type Serializeder

type Serializeder interface {
	Serialized() string
}

Serializeder is used to circumvent the limitations of flag.FlagSet.Set

type StringFlag

type StringFlag struct {
	Name         string
	Aliases      []string
	Usage        string
	EnvVars      []string
	Hidden       bool
	DefaultValue string
	DefaultText  string
	Required     bool
	Validator    func(*Context, string) error
	Destination  *string
}

StringFlag is a flag with type string

func (*StringFlag) Apply

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

Apply populates the flag given the flag set and environment

func (*StringFlag) Names

func (f *StringFlag) Names() []string

Names returns the names of the flag

func (*StringFlag) String

func (f *StringFlag) String() string

String returns a readable representation of this value (for usage defaults)

func (*StringFlag) Validate

func (f *StringFlag) Validate(c *Context) error

type StringMap

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

StringMap wraps a map[string]string to satisfy flag.Value

func NewStringMap

func NewStringMap(m map[string]string) *StringMap

NewStringMap creates a *StringMap with default values

func (*StringMap) Serialized

func (m *StringMap) Serialized() string

Serialized allows StringSlice to fulfill Serializeder

func (*StringMap) Set

func (m *StringMap) Set(value string) error

Set appends the string value to the list of values

func (*StringMap) String

func (m *StringMap) String() string

String returns a readable representation of this value (for usage defaults)

func (*StringMap) Value

func (m *StringMap) Value() map[string]string

Value returns the map set by this flag

type StringMapFlag

type StringMapFlag struct {
	Name        string
	Aliases     []string
	Usage       string
	EnvVars     []string
	Hidden      bool
	DefaultText string
	Required    bool
	Validator   func(*Context, map[string]string) error
	Destination *StringMap
}

StringMapFlag is a flag with type *StringMap

func (*StringMapFlag) Apply

func (f *StringMapFlag) Apply(set *flag.FlagSet)

Apply populates the flag given the flag set and environment

func (*StringMapFlag) Names

func (f *StringMapFlag) Names() []string

Names returns the names of the flag

func (*StringMapFlag) String

func (f *StringMapFlag) String() string

String returns a readable representation of this value (for usage defaults)

func (*StringMapFlag) Validate

func (f *StringMapFlag) Validate(c *Context) error

type StringSlice

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

StringSlice wraps a []string to satisfy flag.Value

func NewStringSlice

func NewStringSlice(defaults ...string) *StringSlice

NewStringSlice creates a *StringSlice with default values

func (*StringSlice) Serialized

func (f *StringSlice) Serialized() string

Serialized allows StringSlice to fulfill Serializeder

func (*StringSlice) Set

func (f *StringSlice) Set(value string) error

Set appends the string value to the list of values

func (*StringSlice) String

func (f *StringSlice) String() string

String returns a readable representation of this value (for usage defaults)

func (*StringSlice) Value

func (f *StringSlice) Value() []string

Value returns the slice of strings set by this flag

type StringSliceFlag

type StringSliceFlag struct {
	Name        string
	Aliases     []string
	Usage       string
	EnvVars     []string
	Hidden      bool
	DefaultText string
	Required    bool
	Validator   func(*Context, []string) error
	Destination *StringSlice
}

StringSliceFlag is a flag with type *StringSlice

func (*StringSliceFlag) Apply

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

Apply populates the flag given the flag set and environment

func (*StringSliceFlag) Names

func (f *StringSliceFlag) Names() []string

Names returns the names of the flag

func (*StringSliceFlag) String

func (f *StringSliceFlag) String() string

String returns a readable representation of this value (for usage defaults)

func (*StringSliceFlag) Validate

func (f *StringSliceFlag) Validate(c *Context) error

type Uint64Flag

type Uint64Flag struct {
	Name         string
	Aliases      []string
	Usage        string
	EnvVars      []string
	Hidden       bool
	DefaultValue uint64
	DefaultText  string
	Required     bool
	Validator    func(*Context, uint64) error
	Destination  *uint64
}

Uint64Flag is a flag with type uint64

func (*Uint64Flag) Apply

func (f *Uint64Flag) Apply(set *flag.FlagSet)

Apply populates the flag given the flag set and environment

func (*Uint64Flag) Names

func (f *Uint64Flag) Names() []string

Names returns the names of the flag

func (*Uint64Flag) String

func (f *Uint64Flag) String() string

String returns a readable representation of this value (for usage defaults)

func (*Uint64Flag) Validate

func (f *Uint64Flag) Validate(c *Context) error

type UintFlag

type UintFlag struct {
	Name         string
	Aliases      []string
	Usage        string
	EnvVars      []string
	Hidden       bool
	DefaultValue uint
	DefaultText  string
	Required     bool
	Validator    func(*Context, uint) error
	Destination  *uint
}

UintFlag is a flag with type uint

func (*UintFlag) Apply

func (f *UintFlag) Apply(set *flag.FlagSet)

Apply populates the flag given the flag set and environment

func (*UintFlag) Names

func (f *UintFlag) Names() []string

Names returns the names of the flag

func (*UintFlag) String

func (f *UintFlag) String() string

String returns a readable representation of this value (for usage defaults)

func (*UintFlag) Validate

func (f *UintFlag) Validate(c *Context) error

type WrappedPanic

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

func (WrappedPanic) Cause

func (p WrappedPanic) Cause() error

func (WrappedPanic) Error

func (p WrappedPanic) Error() string

func (WrappedPanic) StackTrace

func (p WrappedPanic) StackTrace() errors.StackTrace

Jump to

Keyboard shortcuts

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