common

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package common contains common functions used by the cmd packages.

Index

Constants

This section is empty.

Variables

View Source
var (
	// CliBinName is the name of the CLI binary as invoked by the user, e.g. "kubectl-mapr-ticket"
	CliBinName = filepath.Base(os.Args[0])
)

Functions

func CliExample

func CliExample(example string, args ...any) string

CliExample returns a normalized example of a CLI command, the example string is passed through fmt.Sprintf() with the args as arguments.

func CliLongDesc

func CliLongDesc(desc string, args ...any) string

CliShortDesc returns a normalized long description of a CLI command, the desc string is passed through fmt.Sprintf() with the args as arguments.

func CompleteNamespaceNames

func CompleteNamespaceNames(client kubernetes.Interface, toComplete string) ([]string, cobra.ShellCompDirective)

CompleteNamespaceNames returns a list of suggestions for the given available namespaces and the toComplete string. If toComplete is empty, all namespaces are returned. Otherwise, only namespaces that start with toComplete are returned.

func CompleteStringSliceValues added in v0.4.0

func CompleteStringSliceValues(values []string, toComplete string) ([]string, cobra.ShellCompDirective)

CompleteStringSliceValues returns a list of suggestions for the given available values and the toComplete string. If toComplete is empty, all values are returned. Otherwise, only values that start the the substring of toComplete starting at the last comma are returned.

func CompleteStringValues

func CompleteStringValues(values []string, toComplete string) ([]string, cobra.ShellCompDirective)

CompleteStringValues returns a list of suggestions for the given available values and the toComplete string. If toComplete is empty, all values are returned. Otherwise, only values that start with toComplete are returned.

func CompleteTicketNames

func CompleteTicketNames(client kubernetes.Interface, namespace string, args []string, toComplete string) ([]string, cobra.ShellCompDirective)

CompleteTicketNames returns a list of suggestions for the given available tickets and the toComplete string. If toComplete is empty, all tickets are returned. Otherwise, only tickets that start with toComplete are returned. Tickets that have already been completed as part of the command are not returned.

func StringSliceToFlagOptions

func StringSliceToFlagOptions(slice []string) string

StringSliceToFlagOptions returns a normalized string representation of a string slice separated by commas and spaces, suitable for use in CLI flag usage strings, e.g. "one, two, three".

Types

type DurationValue

type DurationValue time.Duration

DurationValue is a wrapper around time.Duration that implements the pflag.Value interface.

Reason: the default time.Duration implementation of pflag.Value only supports units up to hours. That's not really enough for us as we most likely want to check for tickets that expire in a few days or even weeks. This wrapper uses the go-str2duration library to additionally support days and weeks.

func (*DurationValue) Duration

func (d *DurationValue) Duration() time.Duration

Duration returns the underlying time.Duration value

func (*DurationValue) Set

func (d *DurationValue) Set(s string) error

Set implements the pflag.Value interface for DurationValue

func (*DurationValue) String

func (d *DurationValue) String() string

String implements the pflag.Value interface for DurationValue

func (*DurationValue) Type

func (d *DurationValue) Type() string

Type implements the pflag.Value interface for DurationValue

type Options

type Options struct {
	KubernetesConfigFlags *genericclioptions.ConfigFlags
	IOStreams             genericiooptions.IOStreams

	// Debug flag to enable Debug logging
	Debug bool
}

Options is a struct to hold common options for all commands

func NewOptions

func NewOptions(flags *genericclioptions.ConfigFlags, streams genericiooptions.IOStreams) *Options

NewOptions returns a new common options struct

Jump to

Keyboard shortcuts

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