cmdutil

package
v1.0.0-beta1 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2019 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PlanRetriesFlagMessage is the message to be used by the --retries flag.
	PlanRetriesFlagMessage = "Number of times monitoring will be retried. Meaning it accepts an N number of API errors"
	// TrackFlagMessage is the message to be used by the --track flag.
	TrackFlagMessage = "Tracks the progress of the performed task"
)
View Source
const DefaultECERegion = "ece-region"

DefaultECERegion is the region for ECE

Variables

View Source
var (
	// ErrCannotSpecifyEnableAndDisable is returned when --enable and --disable are set.
	ErrCannotSpecifyEnableAndDisable = errors.New(`command only accepts one flag and it should be either "--enable" or "--disable"`)
	// ErrMustSpecifyOneOfEnableOrDisable is returned when --enable or --disable must be set.
	ErrMustSpecifyOneOfEnableOrDisable = errors.New(`command must specify one flag and it should be either "--enable" or "--disable"`)
)
View Source
var (
	// ErrEmptyStdinAndFile thrown when either the Sdin or the file are empty.
	ErrEmptyStdinAndFile = errors.New(
		"empty stdin and file definition, need one of the two to be populated",
	)
)
View Source
var (
	// ErrNodefinitionLoaded is returned by DecodeDefinition when no reader
	// has been returned from either File or Stdin.
	ErrNodefinitionLoaded = errors.New("failed obtaining a reader from file or stdin")
)

Functions

func ActionConfirm

func ActionConfirm(actionRaw, msg string) (*bool, error)

ActionConfirm asks you to confirm before performing an action

func CheckInputHas1ArgsOr0ArgAndAll

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

CheckInputHas1ArgsOr0ArgAndAll checks that the input has either: * 1 argument * 0 arguments and the --all flag.

func CheckInputHas2ArgsOr1ArgAndAll

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

CheckInputHas2ArgsOr1ArgAndAll checks that the input has either: * 2 arguments * 1 argument and the --all flag.

func ConfirmAction

func ConfirmAction(msg string, reader io.Reader, writer io.Writer) bool

ConfirmAction is used to print a message to the writer and read the input from the reader. If the first letter is "y" or "Y" it will return true.

func DecodeDefinition

func DecodeDefinition(cmd *cobra.Command, flagname string, v interface{}) error

DecodeDefinition takes a cobra command, a flagname and the desired structure on which to decode the contents of either the os.Stdin or the file contents. If both are empty, an error is returned.

func DecodeFile

func DecodeFile(filename string, v interface{}) error

DecodeFile takes a filename and the pointer to a structure, opening the file and dumping the contents into the desired structure. Make sure a pointer is passed rather than the copy of a structure.

func FileOrStdin

func FileOrStdin(cmd *cobra.Command, name string) error

FileOrStdin returns an error when the followong scenarios happen: * No Stdin and Flag value are empty. * Unredable Stdin * Both Stdin and Flag value present.

func GetHomePath

func GetHomePath(goos string) string

GetHomePath obtains a home path from a GOOS architecture.

based on spf13/viper (userHomeDir)

func GetInsecurePassword

func GetInsecurePassword(insecure string) ([]byte, error)

GetInsecurePassword retrieves an insecure password from a CLI command

func GetInstances

func GetInstances(cmd *cobra.Command, params util.ClusterParams, flagName string) ([]string, error)

GetInstances tries to obtain a slice with the elasticsearch cluster instance names either from the current cluster topology or from the specified --instance flag in the cobra.Command.

func IncompatibleFlags

func IncompatibleFlags(cmd *cobra.Command, first, second string) error

IncompatibleFlags checks if both flags have been specified, and if so returns an error.

func InsecureOrSecurePassword

func InsecureOrSecurePassword(insecure, message string, verify bool) ([]byte, error)

InsecureOrSecurePassword checks if an insecure password has been set and gets a password in a secure or insecure way.

func MinimumNArgsAndUUID

func MinimumNArgsAndUUID(argsCount int) func(cmd *cobra.Command, args []string) error

MinimumNArgsAndUUID ensures that the command has at least N number of arguments and the first argument is 32 characters long.

func OpenFile

func OpenFile(name string) (*os.File, error)

OpenFile encapsulates the stat and os.OpenFile into its own function

func ParseBoolP

func ParseBoolP(cmd *cobra.Command, name string) (*bool, error)

ParseBoolP parses a string flag that is meant to be a boolean with 3 values: * true * false * nil

func ParseQueryDSLFile

func ParseQueryDSLFile(f string) (models.SearchRequest, error)

ParseQueryDSLFile parses a file that contains a query dsl json and returns the corresponding binary representation

func PasswordVerify

func PasswordVerify(password []byte) error

PasswordVerify retrieves a password from terminal input and verifies a match

func Track

func Track(params TrackParams) error

Track will either print and track the parameter specified Response. If the formatter is not specified an error will be returned.

Types

type TrackParams

type TrackParams struct {
	depresource.TrackResourcesParams

	// Formatter used to print the structure.
	Formatter formatter.Formatter

	// When set to true, it tracks the progress of the resource change with the
	// specified TrackResourcesParams.
	Track bool

	// Template is the template name which the formatter will use.
	Template string

	// Response will be printed using the formatter and template name.
	Response interface{}
}

TrackParams is consumed by Track.

func (TrackParams) Validate

func (params TrackParams) Validate() error

Validate ensures the parameters are usable by the consuming function.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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