cli

package
v3.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package cli provides functions to build the selector command line interface

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

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) ByteQuantityFlag

func (cl *CommandLineInterface) ByteQuantityFlag(name string, shorthand *string, defaultValue *bytequantity.ByteQuantity, description string)

ByteQuantityFlag creates and registers a flag accepting a byte quantity like 512mb.

func (*CommandLineInterface) ByteQuantityFlagOnFlagSet

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

ByteQuantityFlagOnFlagSet creates and registers a flag accepting a ByteQuantity.

func (*CommandLineInterface) ByteQuantityMe

func (*CommandLineInterface) ByteQuantityMe(i interface{}) *bytequantity.ByteQuantity

ByteQuantityMe takes an interface and returns a pointer to a ByteQuantity If the underlying interface kind is not bytequantity.ByteQuantity or *bytequantity.ByteQuantity then nil is returned.

func (*CommandLineInterface) ByteQuantityMinMaxRangeFlagOnFlagSet

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

ByteQuantityMinMaxRangeFlagOnFlagSet creates and registers a min, max, and helper flag each accepting a ByteQuantity like 5mb or 12gb.

func (*CommandLineInterface) ByteQuantityMinMaxRangeFlags

func (cl *CommandLineInterface) ByteQuantityMinMaxRangeFlags(name string, shorthand *string, defaultValue *bytequantity.ByteQuantity, description string)

ByteQuantityMinMaxRangeFlags creates and registers a min, max, and helper flag each accepting a byte quantity like 512mb.

func (*CommandLineInterface) ByteQuantityRangeMe

func (*CommandLineInterface) ByteQuantityRangeMe(i interface{}) *selector.ByteQuantityRangeFilter

ByteQuantityRangeMe takes an interface and returns a pointer to a ByteQuantityRangeFilter value If the underlying interface kind is not ByteQuantityRangeFilter or *ByteQuantityRangeFilter 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) ConfigPathFlag

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

ConfigPathFlag creates and registers a flag accepting a string representing a path and validates that it is a valid path. 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

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

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

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

func (*CommandLineInterface) Float64FlagOnFlagSet

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

Float64FlagOnFlagSet creates and registers a flag accepting a float64.

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) Float64MinMaxRangeFlagOnFlagSet

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

Float64MinMaxRangeFlagOnFlagSet creates and registers a min, max, and helper flag each accepting a float64.

func (*CommandLineInterface) Float64MinMaxRangeFlags

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

Float64MinMaxRangeFlags creates and registers a min, max, and helper flag each accepting a float64.

func (*CommandLineInterface) Float64RangeMe

func (*CommandLineInterface) Float64RangeMe(i interface{}) *selector.Float64RangeFilter

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

func (*CommandLineInterface) Int32FlagOnFlagSet

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

Int32FlagOnFlagSet creates and registers a flag accepting an int.

func (*CommandLineInterface) Int32Me

func (*CommandLineInterface) Int32Me(i interface{}) *int32

Int32Me 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) Int32MinMaxRangeFlagOnFlagSet

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

Int32MinMaxRangeFlagOnFlagSet creates and registers a min, max, and helper flag each accepting an int.

func (*CommandLineInterface) Int32MinMaxRangeFlags

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

Int32MinMaxRangeFlags creates and registers a min, max, and helper flag each accepting an int.

func (*CommandLineInterface) Int32RangeMe

func (*CommandLineInterface) Int32RangeMe(i interface{}) *selector.Int32RangeFilter

Int32RangeMe takes an interface and returns a pointer to an Int32RangeFilter value If the underlying interface kind is not Int32RangeFilter or *Int32RangeFilter 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 int.

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 int.

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 int.

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

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

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

func (*CommandLineInterface) PathFlag

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

PathFlag creates and registers a flag accepting a string representing a path and validates that it is a valid path.

func (*CommandLineInterface) PathFlagOnFlagSet

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

PathFlagOnFlagSet creates and registers a flag accepting a string as a path.

func (*CommandLineInterface) ProcessFlags

func (cl *CommandLineInterface) ProcessFlags() error

ProcessFlags iterates through any registered processors and executes them Processors are executed before validators.

func (*CommandLineInterface) ProcessRangeFilterFlags

func (cl *CommandLineInterface) ProcessRangeFilterFlags() error

ProcessRangeFilterFlags sets min and max to the appropriate 0 or max 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)

RatioFlag creates and registers a flag accepting a ratio.

func (*CommandLineInterface) RegexFlag

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

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

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, processorFn processor, 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

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

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

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

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

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

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

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

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