flagset

package
v2.2.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2018 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package flagset provides functions for handling command line arguments

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Arg

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

Arg represents an argument

type Command

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

Command represents a command

type Flag

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

Flag represents a flag

func (*Flag) Command

func (f *Flag) Command() string

Command returns the command of the flag

func (*Flag) Delimiter

func (f *Flag) Delimiter() string

Delimiter returns the delimiter value of the flag

func (*Flag) Description

func (f *Flag) Description() string

Description returns the description of the flag

func (*Flag) Env

func (f *Flag) Env() string

Env returns the environment variable name of the flag

func (*Flag) FieldIndex added in v1.0.1

func (f *Flag) FieldIndex() []int

FieldIndex returns the parent flag id of the flag

func (*Flag) FormattedArg

func (f *Flag) FormattedArg() string

FormattedArg returns the formatted argument of the flag

func (*Flag) Global

func (f *Flag) Global() bool

Global returns whether the flag is global or not

func (*Flag) ID

func (f *Flag) ID() int

ID returns the id of the flag

func (*Flag) Kind

func (f *Flag) Kind() string

Kind returns the kind of the flag

func (*Flag) Long

func (f *Flag) Long() string

Long returns the long argument of the flag

func (*Flag) Name

func (f *Flag) Name() string

Name returns the name of the flag

func (*Flag) ParentID

func (f *Flag) ParentID() int

ParentID returns the parent flag id of the flag

func (*Flag) ParentIndex added in v1.0.1

func (f *Flag) ParentIndex() []int

ParentIndex returns the parent flag id of the flag

func (*Flag) Required

func (f *Flag) Required() bool

Required returns whether the flag is required or not

func (*Flag) Short

func (f *Flag) Short() string

Short returns the short argument of the flag

func (*Flag) Value

func (f *Flag) Value() interface{}

Value returns the value of the flag

func (*Flag) ValueBy

func (f *Flag) ValueBy() string

ValueBy returns the value by of the flag

func (*Flag) ValueDefault

func (f *Flag) ValueDefault() string

ValueDefault returns the default value of the flag

func (*Flag) ValueType

func (f *Flag) ValueType() string

ValueType returns the value type of the flag

type FlagSet

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

FlagSet represents a flag set

func New

func New(o Options) (*FlagSet, error)

New returns a flag set by the given options

func (*FlagSet) Errors

func (flagSet *FlagSet) Errors() []error

Errors returns the flag and argument errors

func (*FlagSet) FlagArgs

func (flagSet *FlagSet) FlagArgs(name string) []string

FlagArgs returns the flag arguments those exist in the argument list If the flag is an argument then it return it's values (i.e. [foo bar] for `-f=foo -f=bar`) If it's a command then it returns the command name and the rest of the arguments (i.e. [command -f=true --bar=baz qux] for `command -f --bar=baz qux`). Nested commands are separated by dot (i.e. Foo.Bar)

func (*FlagSet) FlagByArg

func (flagSet *FlagSet) FlagByArg(arg, command string) *Flag

FlagByArg returns a flag by the given argument name or returns nil if it doesn't exist Nested commands are separated by dot (i.e. Foo.Bar)

func (*FlagSet) FlagByName

func (flagSet *FlagSet) FlagByName(name string) *Flag

FlagByName returns a flag by the given name or returns nil if it doesn't exist Nested commands are separated by dot (i.e. Foo.Bar)

func (*FlagSet) Flags

func (flagSet *FlagSet) Flags() []*Flag

Flags returns the flags

type Options

type Options struct {
	// Flags represent the user defined command line arguments and commands.
	// When it's a struct type, each field represent an argument or command.
	Flags interface{}
	// Args hold command line arguments. Default is os.Args
	Args []string
}

Options represents the options that can be set when creating a new flag set

Jump to

Keyboard shortcuts

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