cmd

package
v0.0.0-...-b68b9cb Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FlagNonInteractive = BoolFlag{Name: "yes", Short: "y", DefaultValue: false, Usage: "Non-interactive mode: Skips all prompts (default false)", Required: false}
View Source
var NoBellStdout = &noBellStdout{}

Functions

func AddBoolFlags

func AddBoolFlags(cmd *cobra.Command, flags []BoolFlag)

AddBoolFlags adds the given bool flags to the given command. If a flag is required it will be marked as required.

func AddIntFlags

func AddIntFlags(cmd *cobra.Command, flags []IntFlag)

AddIntFlags adds the given int flags to the given command. If a flag is required it will be marked as required.

func AddOptionFlags

func AddOptionFlags[T any](cmd *cobra.Command, flags []OptionFlag[T])

AddOptionFlags adds the given option flags to the given command. If a flag is required it will be marked as required.

func AddPersistentBoolFlags

func AddPersistentBoolFlags(cmd *cobra.Command, flags []BoolFlag)

func AddPersistentStringFlags

func AddPersistentStringFlags(cmd *cobra.Command, flags []StringFlag)

func AddStringFlags

func AddStringFlags(cmd *cobra.Command, flags []StringFlag)

AddStringFlags adds the given string flags to the given command. If a flag is required it will be marked as required.

func CombineFuncs

func CombineFuncs(funcs ...cobra.PositionalArgs) cobra.PositionalArgs

func GetBoolFromPromptOrFlag

func GetBoolFromPromptOrFlag(cmd *cobra.Command, flag BoolFlag) (bool, error)

GetBoolFromPromptOrFlag returns the bool value from 1. the given flag 2. prompts the user for the value if the flag was not set

func GetIntFromPromptOrFlag

func GetIntFromPromptOrFlag(cmd *cobra.Command, flag IntFlag) (int64, error)

GetIntFromPromptOrFlag returns the int value from 1. the given flag 2. prompts the user for the value if the flag was not set

func GetStringFromFlag

func GetStringFromFlag(cmd *cobra.Command, flag StringFlag) (string, error)

GetStringFromFlag returns the string value from the given flag

func GetStringFromPromptOrFlag

func GetStringFromPromptOrFlag(cmd *cobra.Command, flag StringFlag) (string, error)

GetStringFromPromptOrFlag returns the string value from 1. the given flag 2. prompts the user for the value if the flag was not set

func IsInteractive

func IsInteractive(cmd *cobra.Command) bool

IsInteractive returns true if the non-interactive flag was not set.

func PromptCmd

func PromptCmd(options []*cobra.Command) (*cobra.Command, error)

PromptCmd prompts the user to select one of the given options.

func PromptYesNo

func PromptYesNo(label string, defaultValue YesNoOption) (bool, error)

func SetupInteractiveMode

func SetupInteractiveMode(cmd *cobra.Command, _ []string) error

SetupInteractiveMode sets up the interactive mode for the given command. This means that all flags are not required anymore. Load the config file before running this function.

func ValidateInt

func ValidateInt(input string) error

func ValidateIntGreaterZero

func ValidateIntGreaterZero(input string) error

func ValidateIntOrEmpty

func ValidateIntOrEmpty(input string) error

func ValidateKyveAddress

func ValidateKyveAddress(input string) error

func ValidateNotEmpty

func ValidateNotEmpty(input string) error

func ValidatePathExists

func ValidatePathExists(input string) error

func ValidatePathExistsOrEmpty

func ValidatePathExistsOrEmpty(input string) error

func ValidatePort

func ValidatePort(input string) error

Types

type BoolFlag

type BoolFlag struct {
	Name         string
	Short        string
	DefaultValue bool
	Usage        string
	Prompt       string
	Required     bool
}

type IntFlag

type IntFlag struct {
	Name         string
	Short        string
	DefaultValue int64
	Usage        string
	Prompt       string
	Required     bool
	ValidateFn   func(input string) error
}

type Option

type Option[T any] interface {
	Name() string
	Value() T
	StringValue() string
}

func GetOptionFromPrompt

func GetOptionFromPrompt[T any](flag OptionFlag[T]) (Option[T], error)

GetOptionFromPrompt returns the option value from a select prompt

func GetOptionFromPromptOrFlag

func GetOptionFromPromptOrFlag[T any](cmd *cobra.Command, flag OptionFlag[T]) (Option[T], error)

GetOptionFromPromptOrFlag returns the option value from 1. the given flag 2. prompts the user for the value if the flag was not set

type OptionFlag

type OptionFlag[T any] struct {
	Name              string
	Short             string
	DefaultValue      Option[T]
	Options           []Option[T]
	Usage             string
	Prompt            string
	Required          bool
	ValidateFn        func(input string) error
	MaxSelectionSize  uint
	StartInSearchMode bool
}

type StringFlag

type StringFlag struct {
	Name         string
	Short        string
	DefaultValue string
	Usage        string
	Prompt       string
	Required     bool
	ValidateFn   func(input string) error
}

type YesNoOption

type YesNoOption string
const (
	Yes YesNoOption = "Yes"
	No  YesNoOption = "No"
)

Jump to

Keyboard shortcuts

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