Documentation ¶
Index ¶
- Variables
- func CheckInputHas1ArgsOr0ArgAndAll(cmd *cobra.Command, args []string) error
- func CheckInputHas2ArgsOr1ArgAndAll(cmd *cobra.Command, args []string) error
- func CloseResource(closer io.Closer, logger ErrorLoggerFunc)
- func ConfirmAction(msg string, reader io.Reader, writer io.Writer) bool
- func DecodeDefinition(cmd *cobra.Command, flagname string, v interface{}) error
- func DecodeFile(filename string, v interface{}) error
- func DecodeFlags(cmd *cobra.Command, output interface{}) error
- func FileOrStdin(cmd *cobra.Command, name string) error
- func GetHomePath(goos string) string
- func IncompatibleFlags(cmd *cobra.Command, first, second string) error
- func MinimumNArgsAndUUID(argsCount int) func(cmd *cobra.Command, args []string) error
- func NoneOrBothFlags(cmd *cobra.Command, first, second string) error
- func OpenFile(name string) (*os.File, error)
- func ParseBoolP(cmd *cobra.Command, name string) (*bool, error)
- func ParseQueryDSLFile(f string) (models.SearchRequest, error)
- type ErrorLoggerFunc
Constants ¶
This section is empty.
Variables ¶
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"`) )
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", ) )
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 ¶
CheckInputHas1ArgsOr0ArgAndAll checks that the input has either: * 1 argument * 0 arguments and the --all flag.
func CheckInputHas2ArgsOr1ArgAndAll ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
GetHomePath obtains a home path from a GOOS architecture.
based on spf13/viper (userHomeDir)
func IncompatibleFlags ¶
IncompatibleFlags checks if both flags have been specified, and if so returns an error.
func MinimumNArgsAndUUID ¶
MinimumNArgsAndUUID ensures that the command has at least N number of arguments and the first argument is 32 characters long.
func NoneOrBothFlags ¶
NoneOrBothFlags checks if none or both flags have been specified, and if not returns an error.
func ParseBoolP ¶
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