summaryrefslogtreecommitdiff
path: root/parse.go
diff options
context:
space:
mode:
authorAlex Flint <[email protected]>2020-03-01 16:47:25 -0600
committerGitHub <[email protected]>2020-03-01 16:47:25 -0600
commit6f3675fdf12421b56abafbc514ba723e6e4d696d (patch)
tree26f39c0737964ac3e480627a2b04d9550de37c4a /parse.go
parentce4cd0ce03f9d0ca40a3090a63997bfaf6757aaa (diff)
parent17bbf2e7ef446f0ca0c06259676987ec6e79462a (diff)
Merge pull request #109 from alexflint/ignore-env
Option to ignore environment variables
Diffstat (limited to 'parse.go')
-rw-r--r--parse.go22
1 files changed, 15 insertions, 7 deletions
diff --git a/parse.go b/parse.go
index 3370c31..b028168 100644
--- a/parse.go
+++ b/parse.go
@@ -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