Skip to content
This repository was archived by the owner on Feb 16, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions internals/cli/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,21 @@ func (a *App) PrintEnv(w io.Writer, verbose bool) error {
return nil
}

// CheckStrictEnv checks that every environment variable that starts with the app name is recognized by the application.
func (a *App) CheckStrictEnv() error {
for _, envVar := range os.Environ() {
key, _, match := splitVar(a.name, a.separator, envVar)
if match {
key = strings.ToUpper(key)
_, isKnown := a.knownEnvVars[key]
if !(isKnown || a.isExtraEnvVar(key)) {
return fmt.Errorf("environment variable set, but not recognized: %s", key)
}
}
}
return nil
}

// CommandClause represents a command clause in a command0-line application.
type CommandClause struct {
*kingpin.CmdClause
Expand Down