ff icon indicating copy to clipboard operation
ff copied to clipboard

Use os.LookupEnv instead of os.Getenv

Open ryan-bunker opened this issue 8 months ago • 0 comments

In parse.go on line 94, environment variables are retrieved using os.Getenv. Unfortunately, Getenv returns an empty string if the environment variable doesn't exist. This creates an ambiguity because the parser can't know if the value is empty because the variable doesn't exist, or if exists but was explicitly empty. This makes it impossible to override a flag's default value to the empty string using environment variables.

The fix is to use os.LookupEnv instead which also returns a boolean indicating whether the variable exists. This bool could be checked in the if statement instead of the string value, and skipped if the variable doesn't exist. Otherwise the flag's value can be set to the empty string, knowing that's what the user intended.

ryan-bunker avatar Apr 23 '25 16:04 ryan-bunker