cli

package
v0.0.0-...-3a5d5d8 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: LGPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBoolFlagValue

func GetBoolFlagValue(cmd *cobra.Command, flag BoolFlag) bool

GetBoolFlagValue get the bool value for the given BoolFlag from the local flags of the cobra command.

func GetBoolPersistentFlagValue

func GetBoolPersistentFlagValue(cmd *cobra.Command, flag BoolFlag) bool

GetBoolPersistentFlagValue get the bool value for the given BoolFlag from the persistent flags of the given cobra command.

func GetIntFlagValue

func GetIntFlagValue(cmd *cobra.Command, flag IntFlag) int

GetIntFlagValue get the int value for the given IntFlag from the local flags of the cobra command.

func GetIntPersistentFlagValue

func GetIntPersistentFlagValue(cmd *cobra.Command, flag IntFlag) int

GetIntPersistentFlagValue get the int value for the given IntFlag from the persistent flags of the cobra command.

func GetIntSliceFlagValue

func GetIntSliceFlagValue(cmd *cobra.Command, flag IntSliceFlag) []int

GetIntSliceFlagValue get the int slice value for the given IntSliceFlag from the local flags of the cobra command.

func GetIntSlicePersistentFlagValue

func GetIntSlicePersistentFlagValue(cmd *cobra.Command, flag IntSliceFlag) []int

GetIntSlicePersistentFlagValue get the int slice value for the given IntSliceFlag from the persistent flags of the cobra command.

func GetStringFlagValue

func GetStringFlagValue(cmd *cobra.Command, flag StringFlag) string

GetStringFlagValue get the string value for the given StringFlag from the local flags of the cobra command.

func GetStringPersistentFlagValue

func GetStringPersistentFlagValue(cmd *cobra.Command, flag StringFlag) string

GetStringPersistentFlagValue get the string value for the given StringFlag from the persistent flags of the cobra command.

func GetStringSliceFlagValue

func GetStringSliceFlagValue(cmd *cobra.Command, flag StringSliceFlag) []string

GetStringSliceFlagValue get the string slice value for the given StringSliceFlag from the local flags of the cobra command.

func GetStringSlicePersistentFlagValue

func GetStringSlicePersistentFlagValue(cmd *cobra.Command, flag StringSliceFlag) []string

GetStringSlicePersistentFlagValue get the string slice value for the given StringSliceFlag from the persistent flags of the cobra command.

func HasFlagsChanged

func HasFlagsChanged(cmd *cobra.Command, flags []Flag) bool

HasFlagsChanged returns whether any of the flags is set by user in the command

func IsFlagChanged

func IsFlagChanged(cmd *cobra.Command, flag Flag) bool

IsFlagChanged returns whether the flag has been changed in command

func RegisterFlags

func RegisterFlags(cmd *cobra.Command, flags []Flag) error

RegisterFlags register the flags to command's local flag

func RegisterPFlags

func RegisterPFlags(cmd *cobra.Command, flags []Flag) error

RegisterPFlags register the flags to command's persistent flag

func SetParseErrorHandle

func SetParseErrorHandle(f errorHandle)

SetParseErrorHandle set the error handle function used for cli parsing flags. An error handle example:

cli.SetParseErrorHandle(func(err error) {
	fmt.Println(err)
	os.Exit(3)
})

Types

type BoolFlag

type BoolFlag struct {
	Name       string
	Shorthand  string
	Usage      string
	Deprecated string
	Hidden     bool

	DefValue bool
}

BoolFlag is the flag with boolean value

func (BoolFlag) RegisterTo

func (f BoolFlag) RegisterTo(fs *pflag.FlagSet) error

RegisterTo register the boolean flag to FlagSet

type Flag

type Flag interface {
	RegisterTo(fs *pflag.FlagSet) error
}

Flag is the interface for cli flags. To get the value after cli parsing, use fs.GetString(flag.Name)

type IntFlag

type IntFlag struct {
	Name       string
	Shorthand  string
	Usage      string
	Deprecated string
	Hidden     bool

	DefValue int
}

IntFlag is the flag with int value

func (IntFlag) RegisterTo

func (f IntFlag) RegisterTo(fs *pflag.FlagSet) error

RegisterTo register the int flag to FlagSet

type IntSliceFlag

type IntSliceFlag struct {
	Name       string
	Shorthand  string
	Usage      string
	Deprecated string
	Hidden     bool

	DefValue []int
}

IntSliceFlag is the flag with int slice value

func (IntSliceFlag) RegisterTo

func (f IntSliceFlag) RegisterTo(fs *pflag.FlagSet) error

RegisterTo register the string slice flag to FlagSet

type StringFlag

type StringFlag struct {
	Name       string
	Shorthand  string
	Usage      string
	Deprecated string
	Hidden     bool

	DefValue string
}

StringFlag is the flag with string value

func (StringFlag) RegisterTo

func (f StringFlag) RegisterTo(fs *pflag.FlagSet) error

RegisterTo register the string flag to FlagSet

type StringSliceFlag

type StringSliceFlag struct {
	Name       string
	Shorthand  string
	Usage      string
	Deprecated string
	Hidden     bool

	DefValue []string
}

StringSliceFlag is the flag with string slice value

func (StringSliceFlag) RegisterTo

func (f StringSliceFlag) RegisterTo(fs *pflag.FlagSet) error

RegisterTo register the string slice flag to FlagSet

Jump to

Keyboard shortcuts

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