Documentation
¶
Index ¶
- Constants
- Variables
- func GetCurrentEnv() string
- func ShouldDisableColors() bool
- func WrapColorAwareRunE(fn func(cmd *cobra.Command, args []string, noColor bool) error) func(cmd *cobra.Command, args []string) error
- func WrapOutputFormatRunE(fn func(cmd *cobra.Command, args []string, noColor bool, format string) error) func(cmd *cobra.Command, args []string) error
- func WrapRunE(runE func(cmd *cobra.Command, args []string) error) func(cmd *cobra.Command, args []string) error
Constants ¶
View Source
const ( FormatTable = "table" FormatJSON = "json" FormatCSV = "csv" FormatXML = "xml" )
Variables ¶
View Source
var ( Env string OutputFormat string NoColor bool ValidFormats = []string{FormatTable, FormatJSON, FormatCSV, FormatXML} )
View Source
var ConfirmPrompt = func(question string, noColor bool) bool { var response string if !noColor { fmt.Print(color.New(color.FgHiRed).Sprint("⚠️ " + question + " ")) fmt.Print(color.New(color.FgHiWhite, color.Bold).Sprint("[y/N]") + " ") } else { fmt.Printf("⚠️ %s [y/N] ", question) } _, err := fmt.Scanln(&response) if err != nil { if err.Error() == "unexpected newline" { return false } return false } response = strings.ToLower(strings.TrimSpace(response)) return response == "y" || response == "yes" }
View Source
var Prompt = func(msg string, noColor bool) (string, error) { if !noColor { fmt.Print(color.New(color.FgHiRed, color.Bold).Sprint("❯ " + msg + " ")) } else { fmt.Print("❯ " + msg + " ") } reader := bufio.NewReader(os.Stdin) input, err := reader.ReadString('\n') if err != nil { return "", err } return strings.TrimSpace(input), nil }
View Source
var ResourcePrompt = func(resourceType string, msg string, noColor bool) (string, error) { icon := "❯" switch strings.ToLower(resourceType) { case "port": icon = "🔌" case "mve": icon = "🌐" case "mcr": icon = "🛰️" case "vxc": icon = "🔗" case "location": icon = "📍" } if !noColor { fmt.Print(color.New(color.FgHiRed, color.Bold).Sprint(icon + " " + msg + " ")) } else { fmt.Print(icon + " " + msg + " ") } reader := bufio.NewReader(os.Stdin) input, err := reader.ReadString('\n') if err != nil { return "", err } return strings.TrimSpace(input), nil }
Functions ¶
func GetCurrentEnv ¶
func GetCurrentEnv() string
func ShouldDisableColors ¶ added in v0.3.2
func ShouldDisableColors() bool
func WrapColorAwareRunE ¶
func WrapColorAwareRunE(fn func(cmd *cobra.Command, args []string, noColor bool) error) func(cmd *cobra.Command, args []string) error
WrapColorAwareRunE combines WrapRunE and WrapCommandFunc to handle both error formatting and passing the noColor flag to command functions.
func WrapOutputFormatRunE ¶
func WrapOutputFormatRunE(fn func(cmd *cobra.Command, args []string, noColor bool, format string) error) func(cmd *cobra.Command, args []string) error
WrapOutputFormatRunE handles both output format and color settings in command functions. This wrapper takes a function that needs both output format and noColor parameters.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.