goflags

package
v1.0.2 Latest Latest
Warning

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

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

Documentation

Overview

Package goflags allows parsing go command invocations and storing their flags in a CommandFlags structure. It also provides utilities to backtrack through the process stack to find and parse the flags of the first parent go command found in the process hierarchy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetFlags

func SetFlags(wd string, args []string)

SetFlags sets the flags for this process to those parsed from the provided slice. Does nothing if SetFlags or Flags has already been called once.

Types

type CommandFlags

type CommandFlags struct {
	Long    map[string]string
	Short   map[string]struct{}
	Unknown []string // flags we don't process but store anyway
}

CommandFlags represents the flags provided to a go command invocation

func Flags

func Flags() (CommandFlags, error)

Flags return the top level go command flags

func ParseCommandFlags

func ParseCommandFlags(wd string, args []string) (CommandFlags, error)

ParseCommandFlags parses a slice representing a go command invocation and returns its flags. Direct arguments to the command are ignored. The value of $GOFLAGS is also included in the returned flags.

func (CommandFlags) Get

func (f CommandFlags) Get(flag string) (val string, found bool)

Get returns the value of the specified long-form flag if present. The name is provided including the leading hyphen, e.g: "-tags".

func (CommandFlags) Slice

func (f CommandFlags) Slice() []string

Slice returns the command flags as a string slice - long flags are returned as a string of the form '-flagName="flagVal"' - short flags are returned as a string of the form '-flagName' - unknow flags and values are ignored

func (CommandFlags) Trim

func (f CommandFlags) Trim(flags ...string)

Trim removes the specified flags and their value from the long and short flags

Directories

Path Synopsis
Package quoted provides string manipulation utilities.
Package quoted provides string manipulation utilities.

Jump to

Keyboard shortcuts

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