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 ¶
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.
func SetFlagsFromPid ¶ added in v1.0.3
SetFlagsFromPid sets the top level go command flags by looking up the process tree from the specified PID. This is used by the job server when it is started as a daemon (and hence cannot crawl it's own process tree to find this information).
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(ctx context.Context) (CommandFlags, error)
Flags return the top level go command flags
func ParseCommandFlags ¶
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) Except ¶ added in v1.0.3
func (f CommandFlags) Except(remove ...string) CommandFlags
Except returns a copy of this CommandFlags with the specified flags removed. The [CommandFlags.Unknown] field is not modified, even if it is in the list of flags to be removed.
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