args

package
v3.0.0-rc50 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 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

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

func MaskSecrets

func MaskSecrets(argv []string) []string

MaskSecrets returns a copy of argv with the values of the secretFlags masked, as given in the "--flag value" or the "--flag=value" form.

An --env value keeps the name of the variable it sets, as NAME=xxx: which variable an action got is worth reading, its value is not.

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

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

HasOptionAndAnyValue returns true if any of the elements is matching s with any value

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 split string slice.

func (T) String

func (t T) String() string

String returns a shell-escaped string representation of the arguments. It quotes arguments containing spaces or special characters so the output can be safely pasted into a shell.

Jump to

Keyboard shortcuts

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