Documentation ¶
Overview ¶
Copyright 2023 Talhuang<talhuang1231@gmail.com>. All rights reserved. Use of this source code is governed by a MIT style license that can be found in the LICENSE file.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatBaseName ¶
FormatBaseName cleans up and formats the basename, especially for windows OS.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is the central structure representing the CLI application.
func (*App) AddCommand ¶
AddCommand adds a command to the App.
func (*App) AddCommands ¶
AddCommands adds multiple commands to the App.
type CliOptions ¶
type CliOptions interface { // Flags returns a set of named flag sets that can be used by the application. // NamedFlagSets helps organize flags into logical groups for better CLI display. Flags() (fss flag.NamedFlagSets) // Validate checks the validity of the provided command-line options. // It returns a list of errors encountered during validation. Validate() []error }
CliOptions defines an interface for command-line options. This interface provides methods for getting flag sets and validating those flags.
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
Command struct represents an individual CLI command.
func NewCommand ¶
func NewCommand(usage string, desc string, opts ...CommandOption) *Command
NewCommand initializes and returns a new Command.
func (*Command) AddCommand ¶
AddCommand adds a subcommand to the current command.
func (*Command) AddCommands ¶
AddCommands adds multiple subcommands to the current command.
type CommandOption ¶
type CommandOption func(*Command)
CommandOption represents a function that configures a Command.
func WithCommandOptions ¶
func WithCommandOptions(opt CliOptions) CommandOption
WithCommandOptions returns a CommandOption that sets the options for a command.
func WithCommandRunFunc ¶
func WithCommandRunFunc(run RunCommandFunc) CommandOption
WithCommandRunFunc returns a CommandOption that sets the run function of a command.
type CompleteableOptions ¶
type CompleteableOptions interface { // Complete completes any additional setup or data fetching required for the option. Complete() error }
CompleteableOptions defines an interface for options that require completion. Some options might need additional setup or data fetching after being parsed and validated.
type Option ¶
type Option func(*App)
Option represents a function that can modify an App.
func WithDefaultValidArgs ¶
func WithDefaultValidArgs() Option
WithDefaultValidArgs sets default validation for command arguments.
func WithDescription ¶
WithDescription sets a description for the App.
func WithOptions ¶
func WithOptions(opt CliOptions) Option
WithOptions allows CLI options to be passed into the App.
func WithRunFunc ¶
WithRunFunc sets the run function callback for the app.
func WithValidArgs ¶
func WithValidArgs(args cobra.PositionalArgs) Option
WithValidArgs sets validation for command arguments.
type PrintableOptions ¶
type PrintableOptions interface { // String returns a string representation of the option. String() string }
PrintableOptions defines an interface for options that can be converted to a string. This interface provides a method to get a string representation of the option, which can be useful for logging or display purposes.
type RunCommandFunc ¶
RunCommandFunc defines the function signature for commands that run.