parameters

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2022 License: BSD-3-Clause Imports: 2 Imported by: 2

Documentation

Overview

Package parameters provides an argument parser for dealing with a mix of quoted and unquoted arguments.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Flags

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

func NewFlags

func NewFlags(name string) *Flags

func (*Flags) Bool

func (f *Flags) Bool(name string, value bool, usage string)

Bool sets a boolean flag.

func (*Flags) Float

func (f *Flags) Float(name string, value float64, usage string)

Float sets an float64 flag.

func (*Flags) GetBool

func (f *Flags) GetBool(name string) (val bool, ok bool)

GetBool returns the flag called "name". ok is false if the flag is not found or if it isn't a boolean.

func (*Flags) GetFloat64

func (f *Flags) GetFloat64(name string) (val float64, ok bool)

GetFloat64 returns the flag called "name". ok is false if the flag is not found or if it isn't a float.

func (*Flags) GetInt64

func (f *Flags) GetInt64(name string) (val int64, ok bool)

GetInt64 returns the flag called "name". ok is false if the flag is not found or if it isn't an int.

func (*Flags) GetString

func (f *Flags) GetString(name string) (val string, ok bool)

GetString returns the flag called "name". ok is false if the flag is not found or if it isn't a string.

func (*Flags) Int

func (f *Flags) Int(name string, value int64, usage string)

Int sets an int64 flag.

func (*Flags) Parse

func (f *Flags) Parse(args []string) string

Parse parses the given args into f. If the return value isn't empty, an error was encountered and the generated help is returned.

func (*Flags) String

func (f *Flags) String(name string, value string, usage string)

String sets a string flag.

type Parameters

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

Parameters is an argument parser. It is not thread-safe.

func NewParameters

func NewParameters(s string, matchFlags bool) *Parameters

NewParameters returns a new Parameters. If matchFlags is false, flags (unquoted arguments starting with -) will be treated the same as other arguments.

func (*Parameters) Args

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

Args returns all remaining arguments as a slice of strings. Use p.Remainder to return all remaining arguments as a single string.

func (*Parameters) Flags

func (p *Parameters) Flags() []string

Flags returns p's parsed flags. if matchFlags is set to false, always returns nil.

func (*Parameters) FullCommand

func (p *Parameters) FullCommand() string

FullCommand returns the full command passed into parameters.New.

func (*Parameters) HasNext

func (p *Parameters) HasNext() bool

HasNext returns true if p has any parameters left.

func (*Parameters) Match

func (p *Parameters) Match(potentialMatches ...string) (string, bool)

Match returns (match, true) if any of the arguments matched, and ("", false) if none did. If an argument matches, the matched string is popped from p.

func (*Parameters) MatchFlags

func (p *Parameters) MatchFlags(flags ...string) bool

MatchFlags matches the given flags against the flags in p. Arguments should always be passed lowercase.

func (*Parameters) Peek

func (p *Parameters) Peek() string

Peek returns the next argument in the parameters, but doesn't move the pointer.

func (*Parameters) PeekMatch

func (p *Parameters) PeekMatch(potentialMatches ...string) (string, bool)

PeekMatch is like Match but doesn't pop the argument from p.

func (*Parameters) PeekPtr

func (p *Parameters) PeekPtr(ptr int) (string, int)

PeekPtr is like Pop, but uses a user-supplied pointer rather than p's.

func (*Parameters) Pop

func (p *Parameters) Pop() string

Pop returns the next argument in the parameters, skipping over flags.

func (*Parameters) Remainder

func (p *Parameters) Remainder(skipFlags bool) string

Remainder returns the remaining arguments. skipFlags only has an effect if matchFlags is set to true.

Jump to

Keyboard shortcuts

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