cli

package
v0.0.0-...-2b48b92 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	*cobra.Command
	// contains filtered or unexported fields
}

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

func NewCommandCustom(cmd *cobra.Command) *Command

NewCustomCommand returns a Command created from the provided cobra.Command

func NewCommandRun

func NewCommandRun(use, long, short string, run func(cmd *cobra.Command, args []string)) *Command

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

func (c *Command) AddCommand(commands ...*Command)

AddCommand adds a slice of commands to the command

func (*Command) Children

func (c *Command) Children() []*Command

Children returns the children of the command

func (*Command) ConfirmAction

func (c *Command) ConfirmAction(prompt, yesText, noText string, defaultChoice bool) (bool, error)

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

func (c *Command) PromptText(prompt, placeholder string) (string, error)

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

func (c *Command) SelectOption(prompt string, options []string) (string, error)

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

func (c *Command) WithBoolFlag(f types.BoolFlag) *Command

WithBoolFlag adds a boolean flag to the command and registers the flag with environment variable injection

func (*Command) WithPersistentBoolFlag

func (c *Command) WithPersistentBoolFlag(f types.BoolFlag) *Command

WithPersistentBoolFlag adds a persistent boolean flag to the command and registers the flag with environment variable injection

func (*Command) WithPersistentStringFlag

func (c *Command) WithPersistentStringFlag(f types.BoolFlag) *Command

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)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL