Skip to content

feat(cli/environment): use environment variables to set all flags not supplied explicitly#257

Merged
dubinsky merged 1 commit intoskevetter:mainfrom
dubinsky:better-environmen-variables-for-flags
Jan 9, 2026
Merged

feat(cli/environment): use environment variables to set all flags not supplied explicitly#257
dubinsky merged 1 commit intoskevetter:mainfrom
dubinsky:better-environmen-variables-for-flags

Conversation

@dubinsky
Copy link

@dubinsky dubinsky commented Jan 9, 2026

Tighter integration with the spf13/pflag and spf13/cobra libraries allows for a better approach to setting default values of the CLI flags from the environment variables:

  • this defaulting is done in one place (root.go);
  • all the code enabling defaulting of specific flags is reverted;
  • all the flags of all the commands can now be defaulted using environment variables;
  • names of the environment variables are calculated from the names of the flags in a consistent way;
  • there is no need to duplicate pflag code for the parsing of the non-string flags.

@dubinsky dubinsky force-pushed the better-environmen-variables-for-flags branch 2 times, most recently from 969caad to 1c2e870 Compare January 9, 2026 01:04
… supplied explicitly

Tighter integration with the 	`spf13/pflag` and `spf13/cobra` libraries allows for a better approach to setting default values of the CLI flags from the environment variables:
- this defaulting is done in one place (`root.go`);
- all the code enabling defaulting of specific flags is reverted;
- all the flags of all the commands can now be defaulted using environment variables;
- names of the environment variables are calculated from the names of the flags in a consistent way;
- there is no need to duplicate `pflag` code for the parsing of the non-string flags.

Signed-off-by: Leonid Dubinsky <dub@podval.org>
@dubinsky dubinsky force-pushed the better-environmen-variables-for-flags branch from 1c2e870 to a092b8f Compare January 9, 2026 01:12
@dubinsky dubinsky requested a review from skevetter January 9, 2026 02:29
@skevetter skevetter requested a review from Copilot January 9, 2026 03:12
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the CLI's environment variable handling for flags by centralizing the logic in a single location. Instead of manually specifying environment variables for each flag using custom wrapper functions, the new approach automatically generates environment variable names from flag names and applies them uniformly across all commands.

Key Changes

  • Centralized environment variable handling in cmd/root.go with new inheritCommandFlagsFromEnvironment and inheritFlagsFromEnvironment functions
  • Removed custom flag wrapper functions (StringVarE, BoolVarE, StringArrayVarE, StringSliceVarE) from cmd/flags/flags.go
  • Renamed functions from Propagate* to Inherit* for better semantic clarity
  • Updated all flag definitions across commands to use standard cobra/pflag methods

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
cmd/root.go Added centralized environment variable inheritance logic that automatically maps all flags to environment variables with consistent naming
cmd/flags/flags.go Removed custom flag wrapper functions and environment variable helper functions; simplified to use standard pflag methods
cmd/up.go Converted flag definitions from custom *VarE functions to standard pflag methods; renamed propagatedEnvironmentVariables to inheritedEnvironmentVariables
cmd/provider/use.go Converted flag definitions to standard methods; hardcoded environment variable prefix from constant to literal string
cmd/provider/set_options.go Converted flag definition to standard method
cmd/provider/add.go Converted flag definition to standard method
cmd/ide/use.go Updated function call and hardcoded environment variable prefix
pkg/options/options.go Renamed PropagateFromEnvironment and PropagateOptionsFromEnvironment to InheritFromEnvironment and InheritOptionsFromEnvironment
pkg/options/options_test.go Updated test function name to match the renamed function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +164 to +165
// do not prepend "DEVPOD_" to the environment variable name if the flag name starts with "devpod"
// (applies to one flag - "devpod-home").
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we made a TODO to update devpod-home to be consistent with the other variables?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change it to home? I think it is ok as is - home is too generic...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides, breaking people who use devpod-home flag is not worth it I think...

@dubinsky dubinsky merged commit 1cafe66 into skevetter:main Jan 9, 2026
41 checks passed
@dubinsky dubinsky deleted the better-environmen-variables-for-flags branch January 9, 2026 16:39
@dubinsky
Copy link
Author

dubinsky commented Jan 9, 2026

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants