Documentation ¶
Index ¶
- type Command
- func NewCLI(options *types.CLIOptions) *Command
- func NewCommand(use, long, short string, runE func(cmd *cobra.Command, args []string) error) *Command
- func NewCommandCustom(cmd *cobra.Command) *Command
- func NewCommandRun(use, long, short string, run func(cmd *cobra.Command, args []string)) *Command
- func NewCommandRunE(use, long, short string, runE func(cmd *cobra.Command, args []string) error) *Command
- func (c *Command) AddCommand(commands ...*Command)
- func (c *Command) Children() []*Command
- func (c *Command) ConfirmAction(prompt, yesText, noText string, defaultChoice bool) (bool, error)
- func (c *Command) PromptText(prompt, placeholder string) (string, error)
- func (c *Command) SelectOption(prompt string, options []string) (string, error)
- func (c Command) StartProgressBar(message string, total int) *ProgressBarModel
- func (c Command) StartSpinner(message string) *SpinnerModel
- func (c *Command) WithBoolFlag(f types.BoolFlag) *Command
- func (c *Command) WithPersistentBoolFlag(f types.BoolFlag) *Command
- func (c *Command) WithPersistentStringFlag(f types.BoolFlag) *Command
- func (c *Command) WithStringFlag(f types.StringFlag) *Command
- type ProgressBarModel
- type SpinnerModel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶
Command is the root command for the application.
func NewCLI ¶
func NewCLI(options *types.CLIOptions) *Command
NewCLI sets up the CLI for the application using CLIOptions.
func NewCommand ¶
func NewCommand(use, long, short string, runE func(cmd *cobra.Command, args []string) error) *Command
NewCommand returns a new Command with the provided inputs. Alias for NewCommandRunE.
func NewCommandCustom ¶
NewCustomCommand returns a Command created from the provided cobra.Command
func NewCommandRun ¶
NewCommandRun returns a new Command with the provided inputs. The run function is used for commands that do not return an error.
func NewCommandRunE ¶
func NewCommandRunE(use, long, short string, runE func(cmd *cobra.Command, args []string) error) *Command
NewCommandRunE returns a new Command with the provided inputs. The runE function is used for commands that return an error.
func (*Command) AddCommand ¶
AddCommand adds a slice of commands to the command
func (*Command) ConfirmAction ¶
ConfirmAction prompts the user to confirm an action, it supports customizing the prompt and the text for the "yes" and "no" options. If the user does not provide an answer, the default choice is used.
Example:
confirm, err := myApp.CLI.ConfirmAction( "Do you like Batman?", "Yes", "No", true, ) if err != nil { fmt.Println(err) return err } if confirm { fmt.Println("Everybody likes Batman!") } else { fmt.Println("You don't like Batman...") }
func (*Command) PromptText ¶
PromptText prompts the user to input a text, it supports customizing the prompt and the placeholder.
Example:
response, err := myApp.CLI.PromptText( "What is your name?", "Bruce Wayne", ) if err != nil { fmt.Println(err) return err } fmt.Printf("Hello %s!\n", response)
func (*Command) SelectOption ¶
SelectOption prompts the user to select an option from a list of options.
Example:
selected, err := myApp.CLI.SelectOption( "What is your preferred hero?", []string{"Batman", "Ironman", "Spiderman", "Robin", "None"}, ) if err != nil { fmt.Println(err) return err } fmt.Printf("You selected %s!\n", selected)
func (Command) StartProgressBar ¶
func (c Command) StartProgressBar(message string, total int) *ProgressBarModel
StartProgressBar starts a progress bar with a message and a total The progress bar is stopped automatically when it reaches the total or manually by calling the Stop method on the returned model.
Example:
progressBar := myApp.CLI.StartProgressBar("Loading the batmobile...", 100) for i := 0; i < 100; i++ { progressBar.Increment(1) time.Sleep(50 * time.Millisecond) }
func (Command) StartSpinner ¶
func (c Command) StartSpinner(message string) *SpinnerModel
StartSpinner starts a spinner with a message. The spinner can be stopped by calling the Stop method on the returned model.
Example:
spinner := myApp.CLI.StartSpinner("Loading the batmobile...") time.Sleep(3 * time.Second) spinner.Stop()
func (*Command) WithBoolFlag ¶
WithBoolFlag adds a boolean flag to the command and registers the flag with environment variable injection
func (*Command) WithPersistentBoolFlag ¶
WithPersistentBoolFlag adds a persistent boolean flag to the command and registers the flag with environment variable injection
func (*Command) WithPersistentStringFlag ¶
WithPersistentStringFlag adds a persistent string flag to the command and registers the command with the environment variable injection
func (*Command) WithStringFlag ¶
func (c *Command) WithStringFlag(f types.StringFlag) *Command
WithStringFlag adds a string flag to the command and registers the command with the environment variable injection
type ProgressBarModel ¶
type ProgressBarModel struct {
// contains filtered or unexported fields
}
ProgressBarModel represents a progress bar model
func (*ProgressBarModel) Increment ¶
func (m *ProgressBarModel) Increment(progress int)
UpdateProgress increments the progress of the progress bar only if it has not reached the total.
Example:
progressBar := myApp.CLI.StartProgressBar("Loading the batmobile...", 100) progressBar.Increment(50)
func (*ProgressBarModel) Stop ¶
func (m *ProgressBarModel) Stop()
Stop stops the progress bar and marks it as finished.
Example:
progressBar := myApp.CLI.StartProgressBar("Loading the batmobile...", 100) progressBar.Increment(50) progressBar.UpdateMessage("Failed to load the batmobile") progressBar.Stop()
func (*ProgressBarModel) UpdateMessage ¶
func (m *ProgressBarModel) UpdateMessage(message string)
UpdateMessage updates the message of the progress bar
type SpinnerModel ¶
type SpinnerModel struct {
// contains filtered or unexported fields
}
func (*SpinnerModel) Stop ¶
func (m *SpinnerModel) Stop()
Stop stops the spinner and marks it as finished.
Example:
spinner := myApp.CLI.StartSpinner("Loading the batmobile...") time.Sleep(3 * time.Second) spinner.Stop()
func (*SpinnerModel) UpdateMessage ¶
func (m *SpinnerModel) UpdateMessage(message string)