diff options
| author | Alex Flint <[email protected]> | 2020-03-01 16:32:59 -0600 |
|---|---|---|
| committer | Alex Flint <[email protected]> | 2020-03-01 16:32:59 -0600 |
| commit | 17bbf2e7ef446f0ca0c06259676987ec6e79462a (patch) | |
| tree | 26f39c0737964ac3e480627a2b04d9550de37c4a /parse.go | |
| parent | ce4cd0ce03f9d0ca40a3090a63997bfaf6757aaa (diff) | |
add Config.IgnoreEnv to ignore environment variables
Diffstat (limited to 'parse.go')
| -rw-r--r-- | parse.go | 22 |
1 files changed, 15 insertions, 7 deletions
@@ -120,7 +120,11 @@ func flags() []string { // Config represents configuration options for an argument parser type Config struct { - Program string // Program is the name of the program used in the help text + // Program is the name of the program used in the help text + Program string + + // IgnoreEnv instructs the library not to read environment variables + IgnoreEnv bool } // Parser represents a set of command line options with destination values @@ -479,9 +483,11 @@ func (p *Parser) process(args []string) error { copy(specs, curCmd.specs) // deal with environment vars - err := p.captureEnvVars(specs, wasPresent) - if err != nil { - return err + if !p.config.IgnoreEnv { + err := p.captureEnvVars(specs, wasPresent) + if err != nil { + return err + } } // process each string from the command line @@ -517,9 +523,11 @@ func (p *Parser) process(args []string) error { specs = append(specs, subcmd.specs...) // capture environment vars for these new options - err := p.captureEnvVars(subcmd.specs, wasPresent) - if err != nil { - return err + if !p.config.IgnoreEnv { + err := p.captureEnvVars(subcmd.specs, wasPresent) + if err != nil { + return err + } } curCmd = subcmd |
