Documentation ¶
Index ¶
- Constants
- func Blue(msg string) string
- func Colorize(msg string, attrs ...color.Attribute) string
- func Green(msg string) string
- func IconBlue(msg string) string
- func NormalizeCliName(basename string) string
- func Red(msg string) string
- func Yellow(msg string) string
- type App
- type CliOptions
- type Command
- func (c *Command) AddCobraCommands(commands ...*cobra.Command)
- func (c *Command) AddCommands(commands ...*Command)
- func (c *Command) CobraCommand() *cobra.Command
- func (c *Command) Flags() *pflag.FlagSet
- func (c *Command) Help() error
- func (c *Command) MarkHidden(flags ...string)
- func (c *Command) Name() string
- func (c *Command) Run()
- type CommandOption
- func EnableCommandCompletion(hidden bool) CommandOption
- func EnableCommandVersion() CommandOption
- func WithCommandAliases(aliases ...string) CommandOption
- func WithCommandCliOptions(opts CliOptions) CommandOption
- func WithCommandDesc(desc string) CommandOption
- func WithCommandExamples(examples string) CommandOption
- func WithCommandRunFunc(run RunCommandFunc) CommandOption
- type CompletableOptions
- type FlagPrinter
- type Logger
- type Option
- func DisableConfig() Option
- func DisableVersion() Option
- func EnableCompletion(hidden bool) Option
- func EnableSilence() Option
- func WithAliases(aliases ...string) Option
- func WithBaseName(basename string) Option
- func WithCliOptions(opts CliOptions) Option
- func WithDesc(desc string) Option
- func WithExamples(examples string) Option
- func WithFlagPrinter(printer FlagPrinter) Option
- func WithLogger(logger Logger) Option
- func WithOnSignalReceived(receiver func(os.Signal), signals ...os.Signal) Option
- func WithRunFunc(run RunFunc) Option
- type PrintableOptions
- type RunCommandFunc
- type RunFunc
- type SignalReceiver
Constants ¶
const ConfigFlagName = "config"
const (
FlagSetNameGlobal = "global"
)
Variables ¶
This section is empty.
Functions ¶
func NormalizeCliName ¶
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is the main structure of a cli application.
func (*App) AddCobraCommands ¶ added in v0.1.1
AddCobraCommands adds multiple sub cobra.Command to the App.
func (*App) AddCommands ¶
AddCommands adds multiple sub commands to the App.
func (*App) PrintWorkingDir ¶ added in v0.2.0
func (a *App) PrintWorkingDir()
type CliOptions ¶
type CliOptions interface { Flags() (fss cliflag.NamedFlagSets) Validate() []error }
CliOptions abstracts configuration options for reading parameters from the command line.
type Command ¶ added in v0.1.1
type Command struct {
// contains filtered or unexported fields
}
Command is a sub command structure of a cli application. It is recommended that a command be created with the app.NewCommand() function.
func NewCommand ¶ added in v0.1.1
func NewCommand(name string, short string, opts ...CommandOption) *Command
NewCommand creates a new sub command instance based on the given command name and other options.
func (*Command) AddCobraCommands ¶ added in v0.1.1
AddCobraCommands adds multiple sub cobra.Command to the current command.
func (*Command) AddCommands ¶ added in v0.1.1
AddCommands adds multiple sub commands to the current command.
func (*Command) CobraCommand ¶ added in v0.1.6
CobraCommand returns cobra command instance inside the Command.
func (*Command) Flags ¶ added in v0.1.19
Flags returns the complete FlagSet that applies to this command.
func (*Command) MarkHidden ¶ added in v0.1.19
MarkHidden sets flags to 'hidden' in your program.
type CommandOption ¶ added in v0.1.1
type CommandOption interface {
// contains filtered or unexported methods
}
CommandOption defines optional parameters for initializing the command structure.
func EnableCommandCompletion ¶ added in v0.2.0
func EnableCommandCompletion(hidden bool) CommandOption
EnableCommandCompletion creating a default 'completion' command of the Command. Set only when use the Command as a root command.
func EnableCommandVersion ¶ added in v0.1.22
func EnableCommandVersion() CommandOption
EnableCommandVersion enable the version flag of the Command. Set only when use the Command as a root command.
func WithCommandAliases ¶ added in v0.1.1
func WithCommandAliases(aliases ...string) CommandOption
WithCommandAliases sets the Command aliases.
func WithCommandCliOptions ¶ added in v0.1.1
func WithCommandCliOptions(opts CliOptions) CommandOption
WithCommandCliOptions to open the command's function to read from the command line.
func WithCommandDesc ¶ added in v0.1.2
func WithCommandDesc(desc string) CommandOption
WithCommandDesc sets the Command description.
func WithCommandExamples ¶ added in v0.1.20
func WithCommandExamples(examples string) CommandOption
WithCommandExamples is used to set the examples of the Command.
func WithCommandRunFunc ¶ added in v0.1.1
func WithCommandRunFunc(run RunCommandFunc) CommandOption
WithCommandRunFunc is used to set the command startup callback function option.
type CompletableOptions ¶
type CompletableOptions interface {
Complete() error
}
CompletableOptions abstracts options which can be completed.
type FlagPrinter ¶ added in v0.2.11
type FlagPrinter interface {
Printf(template string, args ...interface{})
}
type Logger ¶ added in v0.2.0
type Logger interface { Debugf(template string, args ...interface{}) Debug(msg string, keysAndValues ...interface{}) Infof(template string, args ...interface{}) Info(msg string, keysAndValues ...interface{}) Warnf(template string, args ...interface{}) Warn(msg string, keysAndValues ...interface{}) Errorf(template string, args ...interface{}) Error(msg string, keysAndValues ...interface{}) Fatalf(template string, args ...interface{}) Fatal(msg string, keysAndValues ...interface{}) }
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option defines optional parameters for initializing the application structure.
func EnableCompletion ¶ added in v0.2.0
EnableCompletion creating a default 'completion' command
func EnableSilence ¶ added in v0.2.11
func EnableSilence() Option
EnableSilence sets the application to silent mode, in which the program startup information, flags, configuration information, and version information are not printed in the console.
func WithAliases ¶ added in v0.1.1
WithAliases sets the application aliases.
func WithBaseName ¶
WithBaseName is used to set the basename of the cli.
func WithCliOptions ¶
func WithCliOptions(opts CliOptions) Option
WithCliOptions to open the application's function to read from the command line or read parameters from the configuration file.
func WithExamples ¶ added in v0.1.20
WithExamples is used to set the examples of the application.
func WithFlagPrinter ¶ added in v0.2.11
func WithFlagPrinter(printer FlagPrinter) Option
WithFlagPrinter is used print the flags of the application.
func WithLogger ¶ added in v0.2.0
WithLogger is used to set the (logger) of the application.
func WithOnSignalReceived ¶ added in v0.1.11
WithOnSignalReceived sets a signals' receiver. SIGTERM and SIGINT are registered by default. Register other signals via the signal parameter.
func WithRunFunc ¶
WithRunFunc is used to set the application run callback function option.
type PrintableOptions ¶
type PrintableOptions interface {
String() string
}
PrintableOptions abstracts options which can be printed.
type RunCommandFunc ¶ added in v0.1.1
RunCommandFunc defines the command startup callback function.