cmdutil

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 17 Imported by: 17

Documentation

Index

Constants

This section is empty.

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 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 CloseResource

func CloseResource(closer io.Closer, logger ErrorLoggerFunc)

CloseResource try to close the resource and log error if occurs.

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 DecodeFlags

func DecodeFlags(cmd *cobra.Command, output interface{}) error

DecodeFlags decodes the set flags of a cobra.Command and unpacks all the values to the specified pointer of the passed "output" 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 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 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 NoneOrBothFlags added in v1.2.0

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

NoneOrBothFlags checks if none or both flags have been specified, and if not returns an error.

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

Types

type ErrorLoggerFunc

type ErrorLoggerFunc func(err error)

ErrorLoggerFunc is the callback for logging error

Jump to

Keyboard shortcuts

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