Go: cmd/go/internal/cmdflag Index | Files

package cmdflag

import "cmd/go/internal/cmdflag"

Package cmdflag handles flag processing common to several go tools.


Package Files


func AddKnownFlags Uses

func AddKnownFlags(cmd string, defns []*Defn)

AddKnownFlags registers the flags in defns with base.AddKnownFlag.

func FindGOFLAGS Uses

func FindGOFLAGS(defns []*Defn) []string

FindGOFLAGS extracts and returns the flags matching defns from GOFLAGS. Ideally the caller would mention that the flags were from GOFLAGS when reporting errors, but that's too hard for now.

func IsBool Uses

func IsBool(v flag.Value) bool

IsBool reports whether v is a bool flag.

func SetBool Uses

func SetBool(cmd string, flag *bool, value string)

SetBool sets the addressed boolean to the value.

func SetInt Uses

func SetInt(cmd string, flag *int, value string)

SetInt sets the addressed integer to the value.

func SyntaxError Uses

func SyntaxError(cmd, msg string)

SyntaxError reports an argument syntax error and exits the program.

type Defn Uses

type Defn struct {
    Name       string     // Name on command line.
    BoolVar    *bool      // If it's a boolean flag, this points to it.
    Value      flag.Value // The flag.Value represented.
    PassToTest bool       // Pass to the test binary? Used only by go test.
    Present    bool       // Flag has been seen.

Defn defines a flag we know about.

func Parse Uses

func Parse(cmd string, usage func(), defns []*Defn, args []string, i int) (f *Defn, value string, extra bool)

Parse sees if argument i is present in the definitions and if so, returns its definition, value, and whether it consumed an extra word. If the flag begins (cmd.Name()+".") it is ignored for the purpose of this function.

Package cmdflag imports 6 packages (graph) and is imported by 8 packages. Updated 2020-05-19. Refresh now. Tools for package owners.