Documentation ¶
Index ¶
- Constants
- Variables
- func BoolFlag(ctx context.Context, name string, otherwise bool) bool
- func BuildMap(val interface{}, vip *viper.Viper, exprs ...[]string) map[string]interface{}
- func BuildStrMap(val interface{}, vip *viper.Viper, exprs ...[]string) map[string]string
- func FieldOrViper(val interface{}, name string, vip *viper.Viper, keys ...string) interface{}
- func FloatFlag(ctx context.Context, name string, otherwise float64) float64
- func GetBoolOrViper(ctx context.Context, key string, viperKey string) bool
- func GetFloatOrViper(ctx context.Context, key string, viperKey string) float64
- func GetIntOrViper(ctx context.Context, key string, viperKey string) int
- func GetStringMap(ctx context.Context, key string) map[string]interface{}
- func GetStringMapString(ctx context.Context, key string) map[string]string
- func GetStringOrViper(ctx context.Context, key, viperKey string) string
- func GetViper(ctx context.Context) *viper.Viper
- func HelpFlag(ctx context.Context) bool
- func IntFlag(ctx context.Context, name string, otherwise int) int
- func NewViper(cfg ViperConfig) (*viper.Viper, error)
- func OtherArgs(ctx context.Context) []string
- func PrintJson(ctx context.Context, val interface{}, opts ...string) error
- func Printf(ctx context.Context, format string, args ...interface{}) error
- func Printj(ctx context.Context, fmt string, val interface{}, rest ...interface{}) error
- func Println(ctx context.Context, args ...interface{}) error
- func PrintsJson(ctx context.Context) bool
- func Quiet(ctx context.Context) bool
- func RunLoop(cli *Cli, ctx context.Context, prompt, historyPath string) error
- func Stdout(ctx context.Context) io.Writer
- func StringFlag(ctx context.Context, name, otherwise string) string
- func StringFlagOrViper(ctx context.Context, key string, viperKey string) string
- func StringFlags(ctx context.Context, names ...string) []string
- func StringOrViper(v string, vip *viper.Viper, key string) string
- func WithStdout(ctx context.Context, w io.Writer) context.Context
- func WithViper(ctx context.Context, vip *viper.Viper) context.Context
- type Action
- type Cli
- func (c *Cli) Action(callback Action) *Cli
- func (c *Cli) BannerFunction(fn func(context.Context, *Cli) string) *Cli
- func (c *Cli) BoolFlag(name, description string, variable bool, ptr ...*bool) *Cli
- func (c *Cli) Commands(commands ...*Command) *Cli
- func (c *Cli) DefaultCommand(defaultCommand *Command) *Cli
- func (c *Cli) ErrorFunction(fn func(string, error) error) *Cli
- func (c *Cli) HelpHandler(handler func(context.Context, *Cli) error) *Cli
- func (c *Cli) IntFlag(name, description string, variable int, ptr ...*int) *Cli
- func (c *Cli) LongDescription(longdescription string) *Cli
- func (c *Cli) Name() string
- func (c *Cli) NewSubCommand(name, description string) *Command
- func (c *Cli) PreRun(callback func(context.Context, *Cli) error)
- func (c *Cli) PrintBanner(ctx context.Context)
- func (c *Cli) PrintHelp(ctx context.Context)
- func (c *Cli) Run(ctx context.Context, args ...string) error
- func (cli *Cli) RunBuffer(ctx context.Context, printsJson bool, args ...string) ([]byte, error)
- func (cli *Cli) RunLine(ctx context.Context, printsJson bool, line string) ([]byte, error)
- func (cli *Cli) RunUnmarshal(ctx context.Context, line string, ret interface{}) error
- func (c *Cli) ShortDescription() string
- func (c *Cli) StringFlag(name, description string, variable string, ptr ...*string) *Cli
- func (c *Cli) Version() string
- type Command
- func (c *Command) Action(callback Action) *Command
- func (c *Command) AddCommand(command *Command)
- func (c *Command) BoolFlag(name, description string, val bool, ptrs ...*bool) *Command
- func (c *Command) FloatFlag(name, description string, val float64, ptrs ...*float64) *Command
- func (c *Command) Hidden()
- func (c *Command) IntFlag(name, description string, val int, ptrs ...*int) *Command
- func (c *Command) LongDescription(longdescription string) *Command
- func (c *Command) NewSubCommand(name, description string) *Command
- func (c *Command) PrintHelp(ctx context.Context)
- func (c *Command) StringFlag(name, description string, val string, ptrs ...*string) *Command
- func (c *Command) SubCommands(commands ...*Command) *Command
- type ViperConfig
Constants ¶
const ( FlagValuesKey = "__flag_values__" StdoutKey = "__stdout__" PrintJsonKey = "__print_json__" QuietKey = "__quiet__" )
const (
ViperKey = "__viper__"
)
Variables ¶
var ErrHelp = errors.New("jcli: help requested")
Functions ¶
func BuildStrMap ¶
func FieldOrViper ¶
func GetFloatOrViper ¶
func GetStringMapString ¶
func GetStringOrViper ¶
GetStringOrViper gets the value from the context using the key; if fails, tries to get the viper instance from the context then uses viperKey to get the value.
func PrintsJson ¶
func StringFlagOrViper ¶
func StringFlags ¶
StringFlags is a convenient function that calls StringFlag with multiple names and empty string as the default value
Types ¶
type Cli ¶
type Cli struct {
// contains filtered or unexported fields
}
func (*Cli) BannerFunction ¶
BannerFunction - Set the function that is called to get the banner string.
func (*Cli) DefaultCommand ¶
DefaultCommand - Sets the given command as the command to run when no other commands given.
func (*Cli) ErrorFunction ¶
ErrorFunction - Set custom error message when undefined flags are used by the user. First argument is a string containing the commnad path used. Second argument is the undefined flag error.
func (*Cli) HelpHandler ¶
HelpHandler - Sets the help handler
func (*Cli) LongDescription ¶
LongDescription - Sets the long description for the command.
func (*Cli) NewSubCommand ¶
NewSubCommand - Creates a new SubCommand for the application.
func (*Cli) PrintBanner ¶
PrintBanner - Prints the application banner!
func (*Cli) RunUnmarshal ¶
func (*Cli) ShortDescription ¶
ShortDescription - Get the Application short description.
func (*Cli) StringFlag ¶
StringFlag - Adds a string flag to the root command.
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
Command represents a command that may be run by the user
func NewCommand ¶
NewCommand creates a new Command
func (*Command) AddCommand ¶
AddCommand - Adds a subcommand, which should be non-nil
func (*Command) BoolFlag ¶
BoolFlag - Adds a boolean flag to the command. Use the first pointer in ptrs, if given, for storage, which is shared and not suitable for concurrent execution.
func (*Command) LongDescription ¶
LongDescription - Sets the long description for the command
func (*Command) NewSubCommand ¶
NewSubCommand - Creates a new subcommand
func (*Command) StringFlag ¶
StringFlag - Adds a string flag to the command
func (*Command) SubCommands ¶
Command - Adds subcommands to this command