options

package
v12.41.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: Apache-2.0 Imports: 4 Imported by: 28

Documentation

Overview

Package options provides methods for working with command-line options

Index

Constants

View Source
const (
	STRING = iota // String option
	INT           // Int/Uint option
	BOOL          // Boolean option
	FLOAT         // Floating number option
	MIXED         // String or boolean option
)

Options types

View Source
const (
	ERROR_UNSUPPORTED = iota
	ERROR_NO_NAME
	ERROR_DUPLICATE_LONGNAME
	ERROR_DUPLICATE_SHORTNAME
	ERROR_OPTION_IS_NIL
	ERROR_EMPTY_VALUE
	ERROR_REQUIRED_NOT_SET
	ERROR_WRONG_FORMAT
	ERROR_CONFLICT
	ERROR_BOUND_NOT_SET
	ERROR_UNSUPPORTED_VALUE
)

Error codes

Variables

This section is empty.

Functions

func Add

func Add(name string, opt *V) error

Add add new supported option

func AddMap

func AddMap(optMap Map) []error

AddMap add supported option as map

func GetB

func GetB(name string) bool

GetB returns option value as boolean

func GetF

func GetF(name string) float64

GetF returns option value as floating number

func GetI

func GetI(name string) int

GetI returns option value as integer

func GetS

func GetS(name string) string

GetS returns option value as string

func Has

func Has(name string) bool

Has check that option exists and set

func ParseOptionName

func ParseOptionName(name string) (string, string)

ParseOptionName parses combined name and returns long and short options

func Q

func Q(opts ...string) string

Q merges several options to string

Types

type Arguments

type Arguments []string

func Parse

func Parse(optMap ...Map) (Arguments, []error)

Parse parse options

func (Arguments) Get

func (a Arguments) Get(index int) string

Get returns argument with given index

func (Arguments) GetB

func (a Arguments) GetB(index int) (bool, error)

GetB returns argument with given index as bool

func (Arguments) GetF

func (a Arguments) GetF(index int) (float64, error)

GetF returns argument with given index as float

func (Arguments) GetI

func (a Arguments) GetI(index int) (int, error)

GetI returns argument with given index as int

func (Arguments) Has

func (a Arguments) Has(index int) bool

Has returns true if arguments contains argument with given index

type Map

type Map map[string]*V

Map is map with list of options

type OptionError

type OptionError struct {
	Option      string
	BoundOption string
	Type        int
}

OptionError is argument parsing error

func (OptionError) Error

func (e OptionError) Error() string

type Options

type Options struct {
	// contains filtered or unexported fields
}

Options is options struct

func NewOptions

func NewOptions() *Options

NewOptions create new options struct

func (*Options) Add

func (opts *Options) Add(name string, option *V) error

Add adds a new supported option

func (*Options) AddMap

func (opts *Options) AddMap(optMap Map) []error

AddMap adds supported options as map

func (*Options) GetB

func (opts *Options) GetB(name string) bool

GetB returns option value as boolean

func (*Options) GetF

func (opts *Options) GetF(name string) float64

GetF returns option value as floating number

func (*Options) GetI

func (opts *Options) GetI(name string) int

GetI returns option value as integer

func (*Options) GetS

func (opts *Options) GetS(name string) string

GetS returns option value as string

func (*Options) Has

func (opts *Options) Has(name string) bool

Has check that option exists and set

func (*Options) Parse

func (opts *Options) Parse(rawOpts []string, optMap ...Map) (Arguments, []error)

Parse parse options

type V

type V struct {
	Type      int     // option type
	Max       float64 // maximum integer option value
	Min       float64 // minimum integer option value
	Alias     string  // list of aliases
	Conflicts string  // list of conflicts options
	Bound     string  // list of bound options
	Mergeble  bool    // option supports options value merging
	Required  bool    // option is required

	Value interface{} // default value
	// contains filtered or unexported fields
}

V is basic option struct

Jump to

Keyboard shortcuts

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