args

package
v0.0.0-...-e053da5 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package args parses a posix arguments string using shlex.Split() and proposes methods to drop options and option-values.

Example:

args, _ := Parse("-f -c /tmp/foo --comment foo --comment 'foo bar'")
args.DropOption("-f")
args.DropOptionAndAnyValue("-c")
args.DropOptionAndAnyValue("--comment")
args.Get()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type T

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

func New

func New(s ...string) *T

New allocates a new T and returns its address

func Parse

func Parse(s string) (*T, error)

Parse splits the string using the shlex splitter and store the resulting string slice.

func (*T) Append

func (t *T) Append(s ...string)

func (*T) DropOption

func (t *T) DropOption(s string)

DropOption removes from args the elements matching s. If multiple elements match, they are all removed.

func (*T) DropOptionAndAnyValue

func (t *T) DropOptionAndAnyValue(s string)

DropOptionAndAnyValue removes from args the elements matching s and the following element, considered the value of the option. If multiple elements match, they are all removed.

func (*T) DropOptionAndExactValue

func (t *T) DropOptionAndExactValue(s, v string)

DropOptionAndExactValue removes from args the elements matching s and the following element exactly matching v.

func (*T) DropOptionAndMatchingValue

func (t *T) DropOptionAndMatchingValue(s, v string)

DropOptionAndMatchingValue removes from args the elements matching s and the following element matching the v regular expression.

func (T) Get

func (t T) Get() []string

Get returns the arguments string slice installed by Parse() or T.Set()

func (*T) HasOption

func (t *T) HasOption(s string) bool

HasOption returns true if any of the elements is matching s

func (*T) HasOptionAndMatchingValue

func (t *T) HasOptionAndMatchingValue(s, v string) bool

HasOptionAndMatchingValue returns true if any of the elements is matching s and the following element is matching the v regular expression.

func (*T) Set

func (t *T) Set(args []string)

Set stores the string slice, which must have been formatted by the caller as a shlex splitted string slice.

Jump to

Keyboard shortcuts

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