util

package
v1.43.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Byte     = 1
	Kibibyte = Byte * 1024
	Mebibyte = Kibibyte * 1024
	Gibibyte = Mebibyte * 1024
	Tebibyte = Gibibyte * 1024
)

Variables

This section is empty.

Functions

func AddGroup added in v1.42.0

func AddGroup(cmd *cobra.Command, id string, title string, groupCmds ...*cobra.Command)

AddGroup adds a group to the passed command and adds the passed commands to the group.

func Age added in v1.31.0

func Age(t, currentTime time.Time) string

func ChainRunE

func ChainRunE(fns ...func(cmd *cobra.Command, args []string) error) func(cmd *cobra.Command, args []string) error

func Datetime

func Datetime(t time.Time) string

func DescribeDeprecation added in v1.35.0

func DescribeDeprecation(resource hcloud.Deprecatable) string

func DescribeFormat

func DescribeFormat(object interface{}, format string) error

func DescribeJSON

func DescribeJSON(object interface{}) error

func DescribeYAML added in v1.41.0

func DescribeYAML(object interface{}) error

func ExactlyOneSet

func ExactlyOneSet(s string, ss ...string) bool

func LabelsToString

func LabelsToString(labels map[string]string) string

func ListLongDescription

func ListLongDescription(intro string, columns []string) string

func NA

func NA(s string) string

func PrefixLines added in v1.35.0

func PrefixLines(text, prefix string) string

PrefixLines will prefix all individual lines in the text with the passed prefix.

func SplitLabel

func SplitLabel(label string) []string

func SplitLabelVars added in v1.23.0

func SplitLabelVars(label string) (string, string)

SplitLabelVars splits up label into key and value and returns them as separate return values. If label doesn't contain the `=` separator, SplitLabelVars returns the original string as key, with an empty value.

func ToKebabCase added in v1.43.0

func ToKebabCase(s string) string

ToKebabCase converts the passed string to kebab-case.

func Validate added in v1.43.0

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

Validate checks if the number of positional arguments matches the usage string of a cobra.Command. It returns an error if the number of arguments does not match the usage string (if it is not variadic) or if an argument is missing. If your command usage has optional positional arguments, use ValidateLenient instead.

func ValidateLenient added in v1.43.0

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

ValidateLenient checks if the number of positional arguments matches the usage string of a cobra.Command. In contrast to Validate, it does not return an error if there are more arguments than expected. This can be useful for commands that have optional positional arguments.

func ValidateRequiredFlags added in v1.22.0

func ValidateRequiredFlags(flags *pflag.FlagSet, names ...string) error

ValidateRequiredFlags ensures that flags has values for all flags with the passed names.

This function duplicates the functionality cobra provides when calling MarkFlagRequired. However, in some cases a flag cannot be marked as required in cobra, for example when it depends on other flags. In those cases this function comes in handy.

func Wrap added in v1.41.1

func Wrap(key string, value any) map[string]any

Wrap wraps the passed value in a map with the passed key.

This is useful when working with JSON objects.

func YesNo

func YesNo(b bool) string

Types

This section is empty.

Jump to

Keyboard shortcuts

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