cmdflag

package standard library
go1.27.3 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0 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 cmdflag handles flag processing common to several go tools.

Index

Constants

This section is empty.

Variables

View Source
var ErrFlagTerminator = errors.New("flag terminator")

ErrFlagTerminator indicates the distinguished token "--", which causes the flag package to treat all subsequent arguments as non-flags.

Functions

func ParseOne added in go1.15

func ParseOne(fs *flag.FlagSet, args []string) (f *flag.Flag, remainingArgs []string, err error)

ParseOne sees if args[0] is present in the given flag set and if so, sets its value and returns the flag along with the remaining (unused) arguments.

ParseOne always returns either a non-nil Flag or a non-nil error, and always consumes at least one argument (even on error).

Unlike (*flag.FlagSet).Parse, ParseOne does not log its own errors.

Types

type FlagNotDefinedError added in go1.15

type FlagNotDefinedError struct {
	RawArg   string // the original argument, like --foo or -foo=value
	Name     string
	HasValue bool   // is this the -foo=value or --foo=value form?
	Value    string // only provided if HasValue is true
}

A FlagNotDefinedError indicates a flag-like argument that does not correspond to any registered flag in a FlagSet.

func (FlagNotDefinedError) Error added in go1.15

func (e FlagNotDefinedError) Error() string

type NonFlagError added in go1.15

type NonFlagError struct {
	RawArg string
}

A NonFlagError indicates an argument that is not a syntactically-valid flag.

func (NonFlagError) Error added in go1.15

func (e NonFlagError) Error() string

Jump to

Keyboard shortcuts

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