flags

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2018 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseBool

func ParseBool(str string) (bool, error)

ParseBool parse string to bool

Types

type ArgsParser

type ArgsParser struct {
	// BoolOpts bool option names. list all bool value options.
	// eg. "--debug -h" -> []string{"debug", "h"}
	BoolOpts []string

	// ArrayOpts array option names. list all array value options.
	// eg. "--name tom --name john" should add []string{"name"}
	ArrayOpts []string
	// contains filtered or unexported fields
}

ArgsParser definition. a simple command line args parser

func ParseArgs

func ParseArgs(args []string, boolOpts []string, arrayOpts []string) *ArgsParser

ParseArgs parse os.Args to options.

func (*ArgsParser) Args

func (p *ArgsParser) Args() []string

Args get parsed args

func (*ArgsParser) Opts

func (p *ArgsParser) Opts() map[string]interface{}

Opts get parsed opts

func (*ArgsParser) OptsString

func (p *ArgsParser) OptsString() string

String the all options

func (*ArgsParser) Parse

func (p *ArgsParser) Parse(args []string)

Parse args list to options

Supports options format:

-e  // bool, short option
-e <value> // short option
-e=<value>
-aux // multi short bool options
--bool-opt // bool, lang option
--long-opt <value> // lang option
--long-opt=<value>

type Option

type Option struct {
	Name  string
	Short string
	// Type value type. allow: int, string, bool, ints, strings, bools
	Type string
	// Value of the option. allow: bool, string, array
	Value interface{}

	Required bool
	DefValue interface{}
	// Description
	Description string
}

Option is config info for a option usage:

cmd.AddOpt(Option{
	Name: "name"
	Short: "n"
	DType: "string"
})

cmd.Flags.String()

type Options

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

Options the values for parsed arguments and options

func (*Options) Bindings

func (r *Options) Bindings(longs, shorts map[string]interface{})

Bindings all parsed long and short option values to Option

func (*Options) Opt

func (r *Options) Opt(name string) *Option

Opt get

func (*Options) String

func (r *Options) String() string

String the options

func (*Options) VisitAll

func (r *Options) VisitAll()

VisitAll options

Jump to

Keyboard shortcuts

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