Skip to content

Allow the use of environment variables to supply provider and ide options not supplied on the command line#256

Merged
dubinsky merged 3 commits intoskevetter:mainfrom
dubinsky:environment-variables-for-provider-options
Jan 8, 2026
Merged

Allow the use of environment variables to supply provider and ide options not supplied on the command line#256
dubinsky merged 3 commits intoskevetter:mainfrom
dubinsky:environment-variables-for-provider-options

Conversation

@dubinsky
Copy link

@dubinsky dubinsky commented Jan 7, 2026

This is the last piece of the environment variables puzzle: with this pull request, all the CLI options that it makes sense to me to supply via environment variables can be, including provider and ide options :)

@dubinsky dubinsky force-pushed the environment-variables-for-provider-options branch 2 times, most recently from fd9d18d to dbec5cd Compare January 7, 2026 21:28
…ons not supplied explicitly

Signed-off-by: Leonid Dubinsky <dub@podval.org>
@dubinsky dubinsky force-pushed the environment-variables-for-provider-options branch from dbec5cd to e63fdf5 Compare January 7, 2026 21:58
@dubinsky dubinsky requested a review from skevetter January 7, 2026 22:23
@skevetter skevetter requested a review from Copilot January 7, 2026 22:32
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 enables the use of environment variables to supply provider options that are not provided via command-line arguments. It introduces a reusable utility function for merging environment variables with command-line options, refactors existing Git environment variable propagation to use this utility, and extends environment variable support to provider options.

Key Changes:

  • New utility function for assigning environment variables to unassigned options
  • Refactored Git environment variable handling to use the new utility
  • Provider options can now be supplied via environment variables with the pattern DEVPOD_PROVIDER_<PROVIDER_NAME>_<OPTION_NAME>

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
pkg/options/options.go New utility package with AssignUnassignedFromEnvironment function for merging environment variables with option assignments
cmd/up.go Refactored to use new utility function for Git environment variable propagation; renamed variable from gitEnvironmentVariables to propagatedEnvironmentVariables
cmd/provider/use.go Added environment variable support for provider options using the new utility function with provider-specific prefix
cmd/provider/set_options.go Minor parameter renaming to avoid shadowing the flags package

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

Comment on lines +8 to +20
func AssignUnassignedFromEnvironment(
assignments []string,
names []string,
environmentVariablePrefix string,
) []string {
var result = assignments
for _, name := range names {
if value, exists := os.LookupEnv(environmentVariablePrefix + name); exists && !isAssigned(assignments, name) {
result = append(result, name+"="+value)
}
}
return result
}
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

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

The new function AssignUnassignedFromEnvironment lacks test coverage. Since the pkg/options package has comprehensive testing (as seen in resolve_test.go), this new functionality should also have tests to verify: 1) environment variables are correctly added for unassigned options, 2) already assigned options are not overridden by environment variables, 3) the environment variable prefix is correctly applied, and 4) edge cases like empty values or missing environment variables are handled properly.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

done

Comment on lines +8 to +12
func AssignUnassignedFromEnvironment(
assignments []string,
names []string,
environmentVariablePrefix string,
) []string {
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

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

The exported function AssignUnassignedFromEnvironment is missing documentation. According to Go conventions, all exported functions should have a comment describing what they do. Add a comment describing that this function takes a list of assignments in KEY=VALUE format, a list of option names to check, and an environment variable prefix, and returns a new list with additional assignments from environment variables for any names not already assigned.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

done

@dubinsky dubinsky force-pushed the environment-variables-for-provider-options branch 5 times, most recently from f203cbb to 7d0866b Compare January 8, 2026 00:46
Comment on lines -1066 to +1067
var gitEnvironmentVariables = [...]string{
var propagatedEnvironmentVariables = []string{
Copy link
Owner

Choose a reason for hiding this comment

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

why are we renaming this?

Copy link
Author

Choose a reason for hiding this comment

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

for generality: I am sure there are other variables that should be propagated, not just git-related...

"strings"
)

func AssignUnassignedFromEnvironment(
Copy link
Owner

Choose a reason for hiding this comment

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

Do you find the function name somewhat confusing? Based on the usage, I was thinking something along the lines of GetWorkspaceEnvironment, PropagateFromEnvironment, or InheritFromEnvironment.

Copy link
Author

@dubinsky dubinsky Jan 8, 2026

Choose a reason for hiding this comment

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

The function is used in up.go to augment the environment, but in provider/use.go - to set the options from the environment... I think PropagateFromEnvironment would do it; thanks.

Comment on lines +13 to +19
var result = assignments
for _, name := range names {
if value, exists := os.LookupEnv(environmentVariablePrefix + name); exists && !isAssigned(assignments, name) {
result = append(result, name+"="+value)
}
}
return result
Copy link
Owner

Choose a reason for hiding this comment

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

What are your thoughts on reducing the complexity from O(n x m) to O(n + m).

func PropagateFromEnvironment(
	assignments []string,
	names []string,
	prefix string,
) []string {
	assigned := assignedNames(assignments)

	result := assignments
	for _, name := range names {
		if assigned[name] {
			continue
		}
		if value, exists := os.LookupEnv(prefix + name); exists {
			result = append(result, name+"="+value)
		}
	}
	return result
}

func assignedNames(assignments []string) map[string]bool {
	names := make(map[string]bool, len(assignments))
	for _, assignment := range assignments {
		if idx := strings.Index(assignment, "="); idx != -1 {
			names[assignment[:idx]] = true
		}
	}
	return names
}

Copy link
Author

Choose a reason for hiding this comment

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

Great! Stealing your code :) Thank you!

Signed-off-by: Leonid Dubinsky <dub@podval.org>
@dubinsky dubinsky force-pushed the environment-variables-for-provider-options branch from 7d0866b to 73f238b Compare January 8, 2026 01:20
@dubinsky dubinsky requested a review from skevetter January 8, 2026 01:47
…ot supplied explicitly

Signed-off-by: Leonid Dubinsky <dub@podval.org>
@dubinsky dubinsky changed the title feat(cli/environment): allow the use of environment variables to supply provider options not supplied on the command line Allow the use of environment variables to supply provider and ide options not supplied on the command line Jan 8, 2026
@dubinsky
Copy link
Author

dubinsky commented Jan 8, 2026

@skevetter sorry, I couldn't resist adding the environment variables support for ide options also; could you please take a look at ed85343? Thanks!

@dubinsky dubinsky merged commit cf74eea into skevetter:main Jan 8, 2026
35 checks passed
@dubinsky dubinsky deleted the environment-variables-for-provider-options branch January 8, 2026 04:33
@dubinsky
Copy link
Author

dubinsky commented Jan 8, 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