argv

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package argv reads another program's argument vector without knowing that program's option table: whether a POSIX short flag or a GNU long option is present, the way getopt and getopt_long would see it.

It is a pure library. It starts no goroutines and crosses no boundary.

Knowing no option table has one limit, and it is the price of reading any program: a value is indistinguishable from a flag. In "-ofile" where -o takes a value, the bundle is read as -o -f -i -l -e; in "-p -f" where -p takes a value, "-f" is read as a flag. A caller that must be exact for one program parses with that program's table instead.

Index

Constants

View Source
const (
	// Terminator ends the options: every argument after it is an operand.
	Terminator = "--"
)

The spellings getopt_long gives special meaning to.

Variables

This section is empty.

Functions

func HasFlag

func HasFlag(arguments []string, flag Flag) bool

HasFlag reports whether arguments carry flag before the terminator: the short form alone (-f) or bundled with other short flags (-af, -fl), or the long form alone (--full) or with an attached value (--full=yes). A zero Flag matches nothing; "-" alone is an operand (standard input), not a flag.

Types

type Flag

type Flag struct {
	// Short is the option's letter, as in -f; zero when it has none.
	Short rune
	// Long is the option's name without its dashes, as in full for --full;
	// empty when it has none.
	Long string
}

Flag names one option in its short form, its long form or both.

Jump to

Keyboard shortcuts

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