option

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2020 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package option - internal option struct and methods.

Index

Constants

This section is empty.

Variables

Debug Logger instance set to `ioutil.Discard` by default. Enable debug logging by setting: `Debug.SetOutput(os.Stderr)`.

Functions

func Sort

func Sort(list []*Option)

Sort Interface

Types

type Handler

type Handler func(optName string, argument string, usedAlias string) error

Handler - Signature for the function that handles saving to the option.

type Option

type Option struct {
	Name           string
	Aliases        []string
	EnvVar         string  // Env Var that sets the option value
	Called         bool    // Indicates if the option was passed on the command line
	UsedAlias      string  // Alias/Env var used when the option was called
	Handler        Handler // method used to handle the option
	IsOptional     bool    // Indicates if an option has an optional argument
	MapKeysToLower bool    // Indicates if the option of map type has it keys set ToLower
	OptType        Type    // Option Type
	MinArgs        int     // minimum args when using multi
	MaxArgs        int     // maximum args when using multi

	IsRequired    bool   // Indicates if the option is required
	IsRequiredErr string // Error message for the required option

	// Help
	DefaultStr   string // String representation of default value
	Description  string // Optional description used for help
	HelpArgName  string // Optional arg name used for help
	HelpSynopsis string // Help synopsis
	// contains filtered or unexported fields
}

Option - main object

func New

func New(name string, optType Type) *Option

New - Returns a new option object

func (*Option) CheckRequired

func (opt *Option) CheckRequired() error

CheckRequired - Returns error if the option is required.

func (*Option) Int

func (opt *Option) Int() int

Int - Get the option's data. Exposed due to handle increment. Maybe there is a better way.

func (*Option) Save

func (opt *Option) Save(a ...string) error

Save - Saves the data provided into the option

func (*Option) SetAlias

func (opt *Option) SetAlias(alias ...string) *Option

SetAlias - Adds aliases to an option.

func (*Option) SetBool

func (opt *Option) SetBool(b bool) *Option

SetBool - Set the option's data.

func (*Option) SetBoolPtr

func (opt *Option) SetBoolPtr(b *bool) *Option

SetBoolPtr - Set the option's data.

func (*Option) SetCalled

func (opt *Option) SetCalled(usedAlias string) *Option

SetCalled - Marks the option as called and records the alias used to call it.

func (*Option) SetDefaultStr

func (opt *Option) SetDefaultStr(s string) *Option

SetDefaultStr - Updates the DefaultStr.

func (*Option) SetDescription

func (opt *Option) SetDescription(s string) *Option

SetDescription - Updates the Description.

func (*Option) SetEnvVar added in v0.19.0

func (opt *Option) SetEnvVar(name string) *Option

SetEnvVar - Sets the name of the Env var that sets the option's value.

func (*Option) SetFloat64

func (opt *Option) SetFloat64(f float64) *Option

SetFloat64 - Set the option's data.

func (*Option) SetFloat64Ptr

func (opt *Option) SetFloat64Ptr(f *float64) *Option

SetFloat64Ptr - Set the option's data.

func (*Option) SetHelpArgName

func (opt *Option) SetHelpArgName(s string) *Option

SetHelpArgName - Updates the HelpArgName.

func (*Option) SetInt

func (opt *Option) SetInt(i int) *Option

SetInt - Set the option's data.

func (*Option) SetIntPtr

func (opt *Option) SetIntPtr(i *int) *Option

SetIntPtr - Set the option's data.

func (*Option) SetIntSlice

func (opt *Option) SetIntSlice(s []int) *Option

SetIntSlice - Set the option's data.

func (*Option) SetIntSlicePtr

func (opt *Option) SetIntSlicePtr(s *[]int) *Option

SetIntSlicePtr - Set the option's data.

func (*Option) SetKeyValueToStringMap

func (opt *Option) SetKeyValueToStringMap(k, v string) *Option

SetKeyValueToStringMap - Set the option's data.

func (*Option) SetRequired

func (opt *Option) SetRequired(msg string) *Option

SetRequired - Marks an option as required.

func (*Option) SetString

func (opt *Option) SetString(s string) *Option

SetString - Set the option's data.

func (*Option) SetStringMapPtr

func (opt *Option) SetStringMapPtr(m *map[string]string) *Option

SetStringMapPtr - Set the option's data.

func (*Option) SetStringPtr

func (opt *Option) SetStringPtr(s *string) *Option

SetStringPtr - Set the option's data.

func (*Option) SetStringSlice

func (opt *Option) SetStringSlice(s []string) *Option

SetStringSlice - Set the option's data.

func (*Option) SetStringSlicePtr

func (opt *Option) SetStringSlicePtr(s *[]string) *Option

SetStringSlicePtr - Set the option's data.

func (*Option) Value

func (opt *Option) Value() interface{}

Value - Get untyped option value

type Type

type Type int

Type - Indicates the type of option.

const (
	BoolType Type = iota
	StringType
	IntType
	Float64Type
	StringRepeatType
	IntRepeatType
	StringMapType
)

Option Types

Jump to

Keyboard shortcuts

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