Documentation ¶
Index ¶
- func AddFlags(flagName string, fs *pflag.FlagSet)
- func FormatBaseName(basename string) string
- func InitFlags(flags *pflag.FlagSet)
- func PrintSections(w io.Writer, fs NamedFlagSets, cols int)
- func TerminalSize(w io.Writer) (int, int, error)
- func WordSepNormalizeFunc(_ *pflag.FlagSet, name string) pflag.NormalizedName
- type App
- type CmdLineOptioner
- type Command
- type CommandOption
- type CompleteableOptions
- type NamedFlagSets
- type Option
- type RunCommandFunc
- type RunFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatBaseName ¶
FormatBaseName generates a executable file name under different os based on basename
func PrintSections ¶
func PrintSections(w io.Writer, fs NamedFlagSets, cols int)
PrintSections prints the given names flagsets info in sections
func TerminalSize ¶
TerminalSize returns the width and height of the user's process terminal
func WordSepNormalizeFunc ¶
func WordSepNormalizeFunc(_ *pflag.FlagSet, name string) pflag.NormalizedName
WordSepNormalizeFunc changes all flags that contain "_" separators.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App base structure for constructs a cli application
type CmdLineOptioner ¶
type CmdLineOptioner interface { Flags() (fs NamedFlagSets) // 验证命令行参数是否合法、参数补全、设置默认值等 Validate() []error }
CmdLineOptioner abstracts configuration options for reading parameters from command line.
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
Command a sub command structure of the cli application
func NewCommand ¶
func NewCommand(usage, desc string, opts ...CommandOption) *Command
NewCommand creates a new sub command instance with command name and others options
type CommandOption ¶
type CommandOption func(*Command)
CommandOption optional parameters for initializing the command
func WithCommandOptions ¶
func WithCommandOptions(opt CmdLineOptioner) CommandOption
WithCommandOptions allows the app to read from the flags from command line
func WithCommandRunFunc ¶
func WithCommandRunFunc(runFunc RunCommandFunc) CommandOption
type CompleteableOptions ¶
type CompleteableOptions interface {
Complete() error
}
CompleteableOptions abstracts options which can be completed.
type NamedFlagSets ¶
NamedFlagSets stores named flag sets in the order of calling FlagSet
type Option ¶
type Option func(*App)
Option optional parameters for initializing the applicaiton
func WithDefaultValidArgs ¶
func WithDefaultValidArgs() Option
WithDefaultValidArgs default args validation funciton
func WithDescription ¶
func WithRunFunc ¶
func WithSilence ¶
func WithSilence() Option
func WithValidArgs ¶
func WithValidArgs(args cobra.PositionalArgs) Option
WithValidArgs validate the non-flag args
type RunCommandFunc ¶
RunCommandFunc the app's command startup callback function