args

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateUsageString

func GenerateUsageString(obj interface{}, properties Properties) string

GenerateUsageString generates usage string for given list of properties. This can be used to generate usage strings for commands.

For ex., given struct type account struct

  AccountID string
  CompanyName string
  Email string
}

and call like this

  GenerateUsageString(&account{}, []Property{{Name: "AccountID", Required: true},
	{Name: "CompanyName"}})

Returns:

AccountID=STRING [CompanyName=STRING]

func LoadProperties

func LoadProperties(obj interface{}, properties Properties, argsList []string) error

LoadProperties loads properties from input arguments

func ValidatePropertyList

func ValidatePropertyList(obj interface{}, props Properties)

ValidatePropertyList validates given list is valid for a given object

Types

type Input

type Input struct {
	Key   string
	Value string
}

Input represents parsed input arg.

func ParseArgs

func ParseArgs(argsList []string) ([]Input, error)

ParseArgs parses given raw input args and returns list of Inputs

func (Input) KeyLower

func (i Input) KeyLower() string

KeyLower returns lowercase key

type InputArg

type InputArg string

InputArg - Represents command line input. This is in the format of: KEY=VALUE

func (InputArg) Split

func (ia InputArg) Split() (string, string, error)

Split splits input into key value pair

type InputArgs

type InputArgs []InputArg

InputArgs - list

type Inputs

type Inputs []Input

Inputs - list

type Properties

type Properties []Property

Properties - list of properties.

func GetProperties

func GetProperties(obj interface{}) Properties

GetProperties returns all properties in a given object

func (*Properties) Get

func (pl *Properties) Get(propName string) *Property

Get returns the property by name.

func (*Properties) Remove

func (pl *Properties) Remove(propName string)

Remove removes the given property from the list

func (*Properties) Sort

func (pl *Properties) Sort(moveRequiredPropertiesFirst bool, alphabeticSort bool)

Sort sorts the properties

func (*Properties) ToMap

func (pl *Properties) ToMap() map[string]Property

ToMap returns map.

type Property

type Property struct {
	Name     string   // Name of the property. The name should match the struct field name.
	Required bool     // Specifies if the property is required.
	Default  string   // Default value for the property.
	Enums    []string // List of enum values
}

Property represents a single key/value pair that is used to collect input from user. For ex., in a command, a property represents user input. Since many killbill APIs have tons of properties, it is tedious and error prone to define each property manually. So, we also provide helpers to load properties from a given struct.

func (Property) NameLower

func (p Property) NameLower() string

NameLower returns lowercase name

Jump to

Keyboard shortcuts

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