utils

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2025 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

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.YellowString("%s [y/N]: ", question))
	} else {
		fmt.Printf("%s [y/N]: ", question)
	}

	_, err := fmt.Scanln(&response)
	if err != nil {
		fmt.Println("Error reading input:", err)
		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.BlueString(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
}

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.

func WrapRunE

func WrapRunE(runE func(cmd *cobra.Command, args []string) error) func(cmd *cobra.Command, args []string) error

WrapRunE wraps a RunE function to set SilenceUsage to true if an error occurs and formats the error message.

Types

This section is empty.

Jump to

Keyboard shortcuts

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