Documentation
¶
Index ¶
- Constants
- func AddGroup(cmd *cobra.Command, id string, title string, groupCmds ...*cobra.Command)
- func Age(t, currentTime time.Time) string
- func AnySet(ss ...string) bool
- func AnyToAnySlice(a any) []any
- func AnyToStringSlice(a any) []string
- func ChainRunE(fns ...func(cmd *cobra.Command, args []string) error) func(cmd *cobra.Command, args []string) error
- func Datetime(t time.Time) string
- func DescribeDeprecation(resource hcloud.Deprecatable) string
- func DescribeFormat(w io.Writer, object interface{}, format string) error
- func DescribeJSON(w io.Writer, object interface{}) error
- func DescribeLabels(out io.Writer, labels map[string]string, prefix string)
- func DescribeYAML(w io.Writer, object interface{}) error
- func DisplayZoneName(zoneName string) string
- func ExactlyOneSet(s string, ss ...string) bool
- func FilterNil[T any](values []T) []T
- func FormatHcloudError(err error) string
- func GrossPrice(price hcloud.Price) string
- func IsNil(v any) bool
- func IterateInOrder[M ~map[K]V, K cmp.Ordered, V any](m M) iter.Seq2[K, V]
- func LabelsToString(labels map[string]string) string
- func ListLongDescription(intro string, columns []string) string
- func NA(s string) string
- func OptionalString(s *string, defaultValue string) string
- func OrZero[T any](ptr *T) T
- func ParseBoolLenient(s string) (bool, error)
- func ParseZoneIDOrName(zoneIDOrName string) (string, error)
- func PrefixLines(text, prefix string) string
- func RemoveDuplicates[S ~[]E, E cmp.Ordered](values S) S
- func SliceDiff[S ~[]E, E cmp.Ordered](a, b []E) []E
- func SplitLabel(label string) []string
- func SplitLabelVars(label string) (string, string)
- func ToAnySlice[T any](a []T) []any
- func ToBoolE(val any) (bool, error)
- func ToKebabCase(s string) string
- func ToStringSlice(a []any) []string
- func ToStringSliceDelimited(val any) []string
- func Validate(cmd *cobra.Command, args []string) error
- func ValidateLenient(cmd *cobra.Command, args []string) error
- func ValidateRequiredFlags(flags *pflag.FlagSet, names ...string) error
- func WeekdayFromString(s string) (time.Weekday, error)
- func Wrap(key string, value any) map[string]any
- func YesNo(b bool) string
- type ResourceState
Constants ¶
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
AddGroup adds a group to the passed command and adds the passed commands to the group.
func AnyToAnySlice ¶ added in v1.44.0
func AnyToStringSlice ¶ added in v1.44.0
func DescribeDeprecation ¶ added in v1.35.0
func DescribeDeprecation(resource hcloud.Deprecatable) string
func DescribeJSON ¶
func DescribeLabels ¶ added in v1.56.0
func DescribeYAML ¶ added in v1.41.0
func DisplayZoneName ¶ added in v1.54.0
DisplayZoneName prepares the zone name for user display by converting the ASCII punycode encoding to Unicode.
func ExactlyOneSet ¶
func FormatHcloudError ¶ added in v1.52.0
func GrossPrice ¶ added in v1.45.0
func IterateInOrder ¶ added in v1.51.0
IterateInOrder returns an iterator that iterates over the map in order of the keys.
func LabelsToString ¶
func ListLongDescription ¶
func OptionalString ¶ added in v1.55.0
func OrZero ¶ added in v1.54.0
func OrZero[T any](ptr *T) T
OrZero returns the zero value of T if ptr is nil, otherwise it returns the dereferenced value.
func ParseBoolLenient ¶ added in v1.44.0
ParseBoolLenient parses the passed string as a boolean. It is different from strconv.ParseBool in that it is case-insensitive and also accepts "yes"/"y" and "no"/"n" as valid values.
func ParseZoneIDOrName ¶ added in v1.54.0
ParseZoneIDOrName converts user input for the zone name into an API compatible form. We want to accept Unicode and Punycode/ASCII variants from the user, but the API always expects Punycode/ASCII.
func PrefixLines ¶ added in v1.35.0
PrefixLines will prefix all individual lines in the text with the passed prefix.
func RemoveDuplicates ¶ added in v1.45.0
RemoveDuplicates removes duplicates from the passed slice while preserving the order of the elements. The first occurrence of an element is kept, all following occurrences are removed.
func SliceDiff ¶ added in v1.44.0
SliceDiff returns the difference between the two passed slices. The returned slice contains all elements that are present in a but not in b. The order of a is preserved.
func SplitLabel ¶
func SplitLabelVars ¶ added in v1.23.0
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 ToAnySlice ¶ added in v1.44.0
func ToBoolE ¶ added in v1.45.0
ToBoolE converts the provided value to a bool. It is more lenient than cast.ToBoolE (see ParseBoolLenient).
func ToKebabCase ¶ added in v1.43.0
ToKebabCase converts the passed string to kebab-case.
func ToStringSlice ¶ added in v1.44.0
func ToStringSliceDelimited ¶ added in v1.45.0
ToStringSliceDelimited is like AnyToStringSlice but also accepts a string that is comma-separated.
func Validate ¶ added in v1.43.0
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
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
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 WeekdayFromString ¶ added in v1.55.0
WeekdayFromString converts a string representation of a weekday to a time.Weekday. It accepts full names (e.g., "Monday") and abbreviations (e.g., "Mon"). It is case-insensitive. It also accepts numbers (0-6) where 0 is Sunday, 1 is Monday, ..., and 6 is Saturday. For API compatibility reasons 7 is also accepted as Sunday.