cli

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package cli provides functions to build the selector command line interface

Package cli provides functions to build the selector command line interface

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandLineInterface

type CommandLineInterface struct {
	Command *cobra.Command
	Flags   map[string]interface{}
	// contains filtered or unexported fields
}

CommandLineInterface is a type to group CLI funcs and state

func New

func New(binaryName string, shortUsage string, longUsage, examples string, run runFunc) CommandLineInterface

New creates an instance of CommandLineInterface

func (*CommandLineInterface) BoolFlag

func (cl *CommandLineInterface) BoolFlag(name string, shorthand *string, defaultValue *bool, description string)

BoolFlag creates and registers a flag accepting a boolean

func (*CommandLineInterface) BoolFlagOnFlagSet

func (cl *CommandLineInterface) BoolFlagOnFlagSet(flagSet *pflag.FlagSet, name string, shorthand *string, defaultValue *bool, description string)

BoolFlagOnFlagSet creates and registers a flag accepting a boolean for configuration purposes.

func (*CommandLineInterface) BoolMe

func (*CommandLineInterface) BoolMe(i interface{}) *bool

BoolMe takes an interface and returns a pointer to a bool value If the underlying interface kind is not bool or *bool then nil is returned

func (*CommandLineInterface) ConfigBoolFlag

func (cl *CommandLineInterface) ConfigBoolFlag(name string, shorthand *string, defaultValue *bool, description string)

ConfigBoolFlag creates and registers a flag accepting a boolean for configuration purposes. Config flags will be grouped at the bottom in the output of --help

func (*CommandLineInterface) ConfigIntFlag

func (cl *CommandLineInterface) ConfigIntFlag(name string, shorthand *string, defaultValue *int, description string)

ConfigIntFlag creates and registers a flag accepting an Integer for configuration purposes. Config flags will be grouped at the bottom in the output of --help

func (*CommandLineInterface) ConfigStringFlag

func (cl *CommandLineInterface) ConfigStringFlag(name string, shorthand *string, defaultValue *string, description string, validationFn validator)

ConfigStringFlag creates and registers a flag accepting a String for configuration purposes. Config flags will be grouped at the bottom in the output of --help

func (*CommandLineInterface) ConfigStringOptionsFlag added in v1.1.0

func (cl *CommandLineInterface) ConfigStringOptionsFlag(name string, shorthand *string, defaultValue *string, description string, validOpts []string)

ConfigStringOptionsFlag creates and registers a flag accepting a string and valid options for use in validation. Config flags will be grouped at the bottom in the output of --help

func (*CommandLineInterface) ConfigStringSliceFlag added in v1.1.0

func (cl *CommandLineInterface) ConfigStringSliceFlag(name string, shorthand *string, defaultValue []string, description string)

ConfigStringSliceFlag creates and registers a flag accepting a list of strings. Suite flags will be grouped in the middle of the output --help

func (*CommandLineInterface) Float64Me

func (*CommandLineInterface) Float64Me(i interface{}) *float64

Float64Me takes an interface and returns a pointer to a float64 value If the underlying interface kind is not float64 or *float64 then nil is returned

func (*CommandLineInterface) IntFlag

func (cl *CommandLineInterface) IntFlag(name string, shorthand *string, defaultValue *int, description string)

IntFlag creates and registers a flag accepting an Integer

func (*CommandLineInterface) IntFlagOnFlagSet

func (cl *CommandLineInterface) IntFlagOnFlagSet(flagSet *pflag.FlagSet, name string, shorthand *string, defaultValue *int, description string)

IntFlagOnFlagSet creates and registers a flag accepting an Integer

func (*CommandLineInterface) IntMe

func (*CommandLineInterface) IntMe(i interface{}) *int

IntMe takes an interface and returns a pointer to an int value If the underlying interface kind is not int or *int then nil is returned

func (*CommandLineInterface) IntMinMaxRangeFlagOnFlagSet

func (cl *CommandLineInterface) IntMinMaxRangeFlagOnFlagSet(flagSet *pflag.FlagSet, name string, shorthand *string, defaultValue *int, description string)

IntMinMaxRangeFlagOnFlagSet creates and registers a min, max, and helper flag each accepting an Integer

func (*CommandLineInterface) IntMinMaxRangeFlags

func (cl *CommandLineInterface) IntMinMaxRangeFlags(name string, shorthand *string, defaultValue *int, description string)

IntMinMaxRangeFlags creates and registers a min, max, and helper flag each accepting an Integer

func (*CommandLineInterface) IntRangeMe

func (*CommandLineInterface) IntRangeMe(i interface{}) *selector.IntRangeFilter

IntRangeMe takes an interface and returns a pointer to an IntRangeFilter value If the underlying interface kind is not IntRangeFilter or *IntRangeFilter then nil is returned

func (*CommandLineInterface) ParseAndValidateFlags

func (cl *CommandLineInterface) ParseAndValidateFlags() (map[string]interface{}, error)

ParseAndValidateFlags will parse flags registered in this instance of CLI from os.Args and then perform validation

func (*CommandLineInterface) ParseFlags added in v0.8.1

func (cl *CommandLineInterface) ParseFlags() (map[string]interface{}, error)

ParseFlags will parse flags registered in this instance of CLI from os.Args

func (*CommandLineInterface) ProcessRangeFilterFlags

func (cl *CommandLineInterface) ProcessRangeFilterFlags() error

ProcessRangeFilterFlags sets min and max to the appropriate 0 or maxInt bounds based on the 3-tuple that a user specifies for base flag, min, and/or max

func (*CommandLineInterface) RatioFlag

func (cl *CommandLineInterface) RatioFlag(name string, shorthand *string, defaultValue *string, description string) error

RatioFlag creates and registers a flag accepting a Ratio

func (*CommandLineInterface) RegexFlag added in v1.2.0

func (cl *CommandLineInterface) RegexFlag(name string, shorthand *string, defaultValue *string, description string)

RegexFlag creates and registers a flag accepting a string and validates that it is a valid regex.

func (*CommandLineInterface) RegexFlagOnFlagSet added in v1.2.0

func (cl *CommandLineInterface) RegexFlagOnFlagSet(flagSet *pflag.FlagSet, name string, shorthand *string, defaultValue *string, description string)

RegexFlagOnFlagSet creates and registers a flag accepting a string slice of regular expressions.

func (*CommandLineInterface) RegexMe added in v1.2.0

func (*CommandLineInterface) RegexMe(i interface{}) *regexp.Regexp

RegexMe takes an interface and returns a pointer to a regex If the underlying interface kind is not regexp.Regexp or *regexp.Regexp then nil is returned

func (*CommandLineInterface) SetUntouchedFlagValuesToNil

func (cl *CommandLineInterface) SetUntouchedFlagValuesToNil() error

SetUntouchedFlagValuesToNil iterates through all flags and sets their value to nil if they were not specifically set by the user This allows for a specified value, a negative value (like false or empty string), or an unspecified (nil) entry.

func (*CommandLineInterface) StringFlag

func (cl *CommandLineInterface) StringFlag(name string, shorthand *string, defaultValue *string, description string, validationFn validator)

StringFlag creates and registers a flag accepting a String and a validator function. The validator function is provided so that more complex flags can be created from a string input.

func (*CommandLineInterface) StringFlagOnFlagSet

func (cl *CommandLineInterface) StringFlagOnFlagSet(flagSet *pflag.FlagSet, name string, shorthand *string, defaultValue *string, description string, validationFn validator)

StringFlagOnFlagSet creates and registers a flag accepting a String and a validator function. The validator function is provided so that more complex flags can be created from a string input.

func (*CommandLineInterface) StringMe

func (*CommandLineInterface) StringMe(i interface{}) *string

StringMe takes an interface and returns a pointer to a string value If the underlying interface kind is not string or *string then nil is returned

func (*CommandLineInterface) StringOptionsFlag added in v1.1.0

func (cl *CommandLineInterface) StringOptionsFlag(name string, shorthand *string, defaultValue *string, description string, validOpts []string)

StringOptionsFlag creates and registers a flag accepting a string and valid options for use in validation.

func (*CommandLineInterface) StringOptionsFlagOnFlagSet added in v1.1.0

func (cl *CommandLineInterface) StringOptionsFlagOnFlagSet(flagSet *pflag.FlagSet, name string, shorthand *string, defaultValue *string, description string, validOpts []string)

StringOptionsFlagOnFlagSet creates and registers a flag accepting a String with valid options. The validOpts slice of strings will be used to perform validation

func (*CommandLineInterface) StringSliceFlag added in v1.1.0

func (cl *CommandLineInterface) StringSliceFlag(name string, shorthand *string, defaultValue []string, description string)

StringSliceFlag creates and registers a flag accepting a list of strings.

func (*CommandLineInterface) StringSliceFlagOnFlagSet added in v1.1.0

func (cl *CommandLineInterface) StringSliceFlagOnFlagSet(flagSet *pflag.FlagSet, name string, shorthand *string, defaultValue []string, description string)

StringSliceFlagOnFlagSet creates and registers a flag accepting a String Slice.

func (*CommandLineInterface) StringSliceMe added in v1.1.0

func (*CommandLineInterface) StringSliceMe(i interface{}) *[]string

StringSliceMe takes an interface and returns a pointer to a string slice If the underlying interface kind is not []string or *[]string then nil is returned

func (*CommandLineInterface) SuiteBoolFlag

func (cl *CommandLineInterface) SuiteBoolFlag(name string, shorthand *string, defaultValue *bool, description string)

SuiteBoolFlag creates and registers a flag accepting a boolean for aggregate filters. Suite flags will be grouped in the middle of the output --help

func (*CommandLineInterface) SuiteStringFlag added in v1.1.0

func (cl *CommandLineInterface) SuiteStringFlag(name string, shorthand *string, defaultValue *string, description string, validationFn validator)

SuiteStringFlag creates and registers a flag accepting a string for aggreagate filters. Suite flags will be grouped in the middle of the output --help

func (*CommandLineInterface) SuiteStringOptionsFlag added in v1.1.0

func (cl *CommandLineInterface) SuiteStringOptionsFlag(name string, shorthand *string, defaultValue *string, description string, validOpts []string)

SuiteStringOptionsFlag creates and registers a flag accepting a string and valid options for use in validation. Suite flags will be grouped in the middle of the output --help

func (*CommandLineInterface) SuiteStringSliceFlag added in v1.1.0

func (cl *CommandLineInterface) SuiteStringSliceFlag(name string, shorthand *string, defaultValue []string, description string)

SuiteStringSliceFlag creates and registers a flag accepting a list of strings. Suite flags will be grouped in the middle of the output --help

func (*CommandLineInterface) ValidateFlags

func (cl *CommandLineInterface) ValidateFlags() error

ValidateFlags iterates through any registered validators and executes them

Jump to

Keyboard shortcuts

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