osargs

package
v1.225.0-rc.6 Latest Latest
Warning

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

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

Documentation

Overview

Package osargs parses individual flag values directly from raw os.Args, before Cobra or Viper have processed them. It exists for the small set of callers that need a flag value before normal config loading (e.g. profile or edition pins consulted while building the Viper instance) or as a fallback for commands that run with Cobra's DisableFlagParsing=true (terraform, helmfile, packer, auth exec), where Cobra never populates a flag binding at all.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseString

func ParseString(args []string, flagName string) string

ParseString extracts a single string flag's value from raw args, or "" if the flag isn't present. Whitespace is trimmed by the caller if needed — this returns the raw pflag-parsed value.

func ParseStringSlice

func ParseStringSlice(args []string, flagName string) []string

ParseStringSlice extracts a comma-separated string-slice flag's value from raw args, or nil if the flag isn't present. Handles both `--flag=a,b` and `--flag a,b` syntax via pflag's own StringSlice parser.

func ParseStringWithShorthand

func ParseStringWithShorthand(args []string, flagName, shorthand string) string

ParseStringWithShorthand extracts a single string flag's value from raw args, matching either its long form (--flagName) or single-character shorthand (-X), or "" if neither is present. Uses pflag's own shorthand support, so it recognizes every syntax pflag does: --flag=value, --flag value, -X=value, -Xvalue (concatenated), and -X value.

Types

This section is empty.

Jump to

Keyboard shortcuts

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