Documentation
¶
Index ¶
- Variables
- func AskChoice(s string, opts ...string) int
- func AskConfirm(s string) bool
- func AskPassword(s string) string
- func AskSelect(s string, opts ...string) []int
- func AskValue(s string) string
- func CommandWithExtraAliases(c *Command, run interface{})
- func CommandWithExtraFlags(c *Command, run interface{})
- func CommandWithPreRun(f func(c *Command, args *[]string) error) func(c *Command, run interface{})
- func CommandWithoutExtraFlags(c *Command, run interface{})
- func Ellipsis(s string, i int) string
- func ExitOnError(err error, helpFunc ...func() error)
- func NewCommand(c Command, run RunFunc, subCommands SubCommands, mod ...CommandModifier) *cobra.Command
- func NewDeleteCommand(c Command, run RunDeleteFunc, subCommands SubCommands, mod ...CommandModifier) *cobra.Command
- func NewError(format string, args ...interface{}) error
- func NewGetCommand(c Command, run RunGetFunc, subCommands SubCommands, mod ...CommandModifier) *cobra.Command
- func NewListCommand(c Command, run RunListFunc, subCommands SubCommands, mod ...CommandModifier) *cobra.Command
- func OSExit(code int)
- func ParsePath(path string) (string, string, error)
- func ReadLine() string
- func WrapError(err error, format string, args ...interface{}) error
- type Arg
- type Command
- type CommandModifier
- type CustomMultiSelect
- type CustomMultiSelectOption
- type Display
- type Error
- type Flag
- type FlagType
- type ListResult
- type RunDeleteFunc
- type RunFunc
- type RunGetFunc
- type RunListFunc
- type SubCommands
- type Values
Constants ¶
This section is empty.
Variables ¶
var ( Yellow = color.New(color.FgYellow).SprintfFunc() Red = color.New(color.FgRed).SprintfFunc() Blue = color.New(color.FgBlue).SprintfFunc() Magenta = color.New(color.FgMagenta).SprintfFunc() Green = color.New(color.FgGreen).SprintfFunc() Cyan = color.New(color.FgCyan).SprintfFunc() BuildingChar = Blue("↻") OKChar = Green("✓") KOChar = Red("✗") Arrow = Cyan("➤") )
Colors... colors everywhere
var ErrWrongUsage = &Error{Code: 1, Err: fmt.Errorf("Wrong usage")}
ErrWrongUsage is a common error
var ShellMode bool
ShellMode will os.Exit if false, display only exit code if true
var Verbose bool
If Verbose is set to true, ExitOnError will try to display more detail about the potential errors
Functions ¶
func AskPassword ¶
AskPassword ask for a password string and returns it.
func AskSelect ¶
AskSelect for multiple choices in given options, returns indexes of selected options.
func CommandWithExtraAliases ¶
func CommandWithExtraAliases(c *Command, run interface{})
CommandWithExtraAliases to add common extra alias
func CommandWithExtraFlags ¶
func CommandWithExtraFlags(c *Command, run interface{})
CommandWithExtraFlags to add common extra flags
func CommandWithPreRun ¶
CommandWithPreRun to add pre run function
func CommandWithoutExtraFlags ¶
func CommandWithoutExtraFlags(c *Command, run interface{})
CommandWithoutExtraFlags to avoid add extra flags
func ExitOnError ¶
ExitOnError if the error is not nil; exit the process with printing help functions and the error
func NewCommand ¶
func NewCommand(c Command, run RunFunc, subCommands SubCommands, mod ...CommandModifier) *cobra.Command
NewCommand creates a new cobra command with or without a RunFunc and eventually subCommands
func NewDeleteCommand ¶
func NewDeleteCommand(c Command, run RunDeleteFunc, subCommands SubCommands, mod ...CommandModifier) *cobra.Command
NewDeleteCommand creates a new cobra command with a RunDeleteFunc and eventually subCommands
func NewGetCommand ¶
func NewGetCommand(c Command, run RunGetFunc, subCommands SubCommands, mod ...CommandModifier) *cobra.Command
NewGetCommand creates a new cobra command with a RunGetFunc and eventually subCommands
func NewListCommand ¶
func NewListCommand(c Command, run RunListFunc, subCommands SubCommands, mod ...CommandModifier) *cobra.Command
NewListCommand creates a new cobra command with a RunListFunc and eventually subCommands
func OSExit ¶
func OSExit(code int)
OSExit will os.Exit if ShellMode is false, display only exit code if true
Types ¶
type Command ¶
type Command struct { Name string Ctx []Arg Args []Arg OptionalArgs []Arg VariadicArgs Arg Short string Long string Example string Flags []Flag Aliases []string Hidden bool PreRun func(c *Command, args *[]string) error }
Command represents the way to instantiate a cobra.Command
type CommandModifier ¶
type CommandModifier func(*Command, interface{})
CommandModifier is a function type to extend a command
type CustomMultiSelect ¶
type CustomMultiSelect struct { survey.MultiSelect Message string Options []CustomMultiSelectOption // contains filtered or unexported fields }
CustomMultiSelect is a custom multi select over survey multi select that allows to add extra info on items.
func NewCustomMultiSelect ¶
func NewCustomMultiSelect(message string, opts ...CustomMultiSelectOption) *CustomMultiSelect
NewCustomMultiSelect custom survey multi select from options.
func (*CustomMultiSelect) Prompt ¶
func (c *CustomMultiSelect) Prompt() (interface{}, error)
Prompt override to extract option values.
type CustomMultiSelectOption ¶
CustomMultiSelectOption for CustomMultiSelect.
type Display ¶
type Display string
Display helps you to display message on a terminal
type Flag ¶
type Flag struct { Name string ShortHand string Usage string Default string Type FlagType IsValid func(string) bool }
Flag represents a command flag.
type ListResult ¶
type ListResult []interface{}
ListResult is the result type for command function which returns list. Use AsListResult to compute this
func AsListResult ¶
func AsListResult(i interface{}) ListResult
AsListResult compute any slice to ListResult
type RunDeleteFunc ¶
RunDeleteFunc is a run function for a command. It returns an error.
type RunGetFunc ¶
RunGetFunc is a run function for a command. It returns an object value (not a pointer) and an error.
type RunListFunc ¶
type RunListFunc func(Values) (ListResult, error)
RunListFunc is a run function for a command. It returns an objects list and an error
type SubCommands ¶
SubCommands represents an array of cobra.Command
type Values ¶
Values represents commands flags and args values accessible with their name
func (*Values) GetStringArray ¶
GetStringArray returns a string array.
func (*Values) GetStringSlice ¶
GetStringSlice returns a string slice.