flags

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2019 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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

OptsString convert all options to string

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 Arguments added in v1.2.1

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

Arguments definition

func (*Arguments) Add added in v1.2.1

func (ags *Arguments) Add(name, description string)

Add a new argument

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

func NewOpt added in v1.2.1

func NewOpt(name, description string) *Option

NewOpt create new option

func (*Option) StrVar added in v1.2.1

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

StrVar binding

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