Documentation ¶
Overview ¶
Package cli contains utilities for "Command Line Interface" applications.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadPipedInput ¶
ReadPipedInput retrieves contents passed-in from standard input up to the provided maximum number of bytes.
Example ¶
// Read a maximum of 32 bytes from standard input input, err := ReadPipedInput(32) if len(input) > 0 && err != nil { // Handle error panic(err) } log.Printf("data received: %s", input)
Output:
func ReadSecure ¶
ReadSecure will interactively prompt the user to enter a value. The value provided won't be displayed on the screen.
Example ¶
// Interactively prompt the user to enter a value. The value provided won't be // displayed on the screen. password, err := ReadSecure("Enter your password: ") if err != nil { // Handle error panic(err) } log.Printf("you entered: %s", password)
Output:
func SetupCommandParams ¶
SetupCommandParams will properly configure the command with the provided parameter list.
Example ¶
Register a list of parameters to a sample command.
sampleCmd := &cobra.Command{} parameters := []Param{ { Name: "name-of-parameter", Usage: "describe the parameter use or intent", FlagKey: "cmd.parameter.name", ByDefault: 9090, }, { Name: "bool-flag", Usage: "parameters support several basic types", FlagKey: "cmd.parameter.flag", ByDefault: false, }, } if err := SetupCommandParams(sampleCmd, parameters); err != nil { panic(err) }
Output:
func SignalsHandler ¶
SignalsHandler returns a properly configured OS signals handler channel.
Example ¶
// Register the signals to look for and wait for one s := <-SignalsHandler([]os.Signal{ syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, }) log.Printf("signal received: %s", s)
Output:
Types ¶
type Param ¶
type Param struct { // Name of the parameter, will be displayed to the user when inspecting the // help information for the command. Name string // Brief and clear description of the parameter usage or intent, will be // displayed to the user when inspecting the help information for the command. Usage string // Internal code for the parameter. This should match the structure of a // configuration file when used and can be useful to add 'namespaces' for // configuration settings. This key should be used when reading configuration // options using viper. For example: // root.child.parameter FlagKey string // Default value to use for the parameter, the type of the default value will // determine the expected type for the parameter. Supported types are: // int, int32, int64 uint32, uint64, string, bool, []string ByDefault interface{} // If provided the parameter can be provided using a shorthand letter that can // be used after a single dash. Must be unique. Short string // Parameters are optional by default. If instead you wish your command to report // an error when a parameter has not been set, mark it as required. Required bool }
Param represents an individual CLI parameter.
type Spinner ¶
type Spinner struct {
// contains filtered or unexported fields
}
Spinner indicator.
func NewSpinner ¶
func NewSpinner(opts ...SpinnerOption) *Spinner
NewSpinner creates a new spinner indicator instance.
type SpinnerOption ¶
type SpinnerOption = func(s *Spinner)
SpinnerOption provide a functional style mechanism to adjust the settings when creating a new spinner instance.
func WithSpinnerColor ¶
func WithSpinnerColor(color string) SpinnerOption
WithSpinnerColor adjust the color used for the spinner indicator. Supported values are: "green", "blue", "yellow" and "red".
Directories ¶
Path | Synopsis |
---|---|
Package konf provides utilities to work with `github.com/nil-go/konf`
|
Package konf provides utilities to work with `github.com/nil-go/konf` |
Package shell provides an interactive client for CLI-based applications.
|
Package shell provides an interactive client for CLI-based applications. |
Package viper provides utilities to work with `github.com/spf13/viper`
|
Package viper provides utilities to work with `github.com/spf13/viper` |