Documentation ¶
Index ¶
- Constants
- Variables
- func ArgumentsOptionValue(args []string, flag string, option string) string
- func CheckErr(err error)
- func InvalidArg(value string, values []string) error
- func InvalidArgError(value string, err error) error
- func InvalidArgf(value string, message string, a ...interface{}) error
- func InvalidOption(name string, value string, values []string) error
- func InvalidOptionf(option string, value interface{}, message string, a ...interface{}) error
- func MissingOption(name string) error
- func SuggestionsFor(typedName string, values []string, suggestionsMinimumDistance int, ...) []string
- type BaseOptions
Constants ¶
View Source
const ( // OptionBatchMode command line option to enable batch mode OptionBatchMode = "batch-mode" // OptionVerbose command line option to enable verbose logging OptionVerbose = "verbose" )
View Source
const ( // DefaultErrorExitCode is the default exit code in case of an error DefaultErrorExitCode = 1 // DefaultSuggestionsMinimumDistance default distance when generating suggestions if an option/arg is wrong DefaultSuggestionsMinimumDistance = 2 )
Variables ¶
View Source
var ( // ErrExit can be used to exit with a non 0 exit code without any error message ErrExit = fmt.Errorf("exit") )
Functions ¶
func ArgumentsOptionValue ¶
ArgumentsOptionValue returns the argument
func CheckErr ¶
func CheckErr(err error)
CheckErr prints a user friendly error to STDERR and exits with a non-zero exit code.
func InvalidArg ¶
func InvalidArgError ¶
func InvalidArgf ¶
func InvalidOptionf ¶
InvalidOptionf returns an error that shows the invalid option.
func MissingOption ¶
MissingOption reports a missing command line option using the full name expression.
Types ¶
type BaseOptions ¶
type BaseOptions struct { BatchMode bool `env:"JX_BATCH_MODE"` Verbose bool `env:"JX_VERBOSE"` LogLevel string `env:"JX_LOG_LEVEL"` Ctx context.Context Command *cobra.Command Out io.Writer }
BaseOptions a few common options we tend to use in command line tools
func (*BaseOptions) AddBaseFlags ¶
func (o *BaseOptions) AddBaseFlags(cmd *cobra.Command)
AddBaseFlags adds the base flags for all commands
func (*BaseOptions) GetContext ¶
func (o *BaseOptions) GetContext() context.Context
GetContext lazily creates the context if its not already set
Click to show internal directories.
Click to hide internal directories.