Skip to content

feat: support "1" for environment variables#8246

Merged
rfay merged 7 commits intoddev:mainfrom
deviantintegral:20260321_deviantintegral_env_true_or_1
Apr 10, 2026
Merged

feat: support "1" for environment variables#8246
rfay merged 7 commits intoddev:mainfrom
deviantintegral:20260321_deviantintegral_env_true_or_1

Conversation

@deviantintegral
Copy link
Copy Markdown
Collaborator

The Issue

I keep trying to use DDEV_VERBOSE=1 instead of true as I use it just rarely enough to remember. It's pretty common for variables in shells use 0 / 1, so let's support that here! Feel free to close this if you think it's overcomplicated.

How This PR Solves The Issue

Updates all user-facing environment variables to support 1 as well as true.

AI generated, but human reviewed and tested.

Manual Testing Instructions

Try DDEV_VERBOSE=1 ddev start ...

Automated Testing Overview

Adds an automated test to cover the new behaviour.

@deviantintegral deviantintegral requested a review from a team as a code owner March 21, 2026 18:40
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 21, 2026

@deviantintegral
Copy link
Copy Markdown
Collaborator Author

I'm not sure why the quickstart test failed - I don't see any errors in the logs, it just seems to have died.

@rfay
Copy link
Copy Markdown
Member

rfay commented Mar 22, 2026

I didn't understand either (on main). So

But couldn't figure out what happened to make it appear.

@rfay rfay force-pushed the 20260321_deviantintegral_env_true_or_1 branch from 55a8b1e to 649c283 Compare March 22, 2026 15:50
@rfay
Copy link
Copy Markdown
Member

rfay commented Mar 22, 2026

Rebased

Copy link
Copy Markdown
Member

@rfay rfay left a comment

Choose a reason for hiding this comment

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

I didn't study carefully, but it sure looks fine.

What I have really been hoping to do over the years is to add global flags for these.

@deviantintegral
Copy link
Copy Markdown
Collaborator Author

I agree! Would you like me instead to work on supporting those?

@rfay
Copy link
Copy Markdown
Member

rfay commented Mar 22, 2026

I'd loe to have you do those, but finish this first, it's a good thing, and I think env-based control will still be valuable.

Comment thread cmd/ddev-hostname/ddev-hostname.go
Comment thread pkg/output/output_setup.go Outdated
Copy link
Copy Markdown
Member

@rfay rfay left a comment

Choose a reason for hiding this comment

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

I manually tested and did fine, and the code looks fine. But why isEnvTrue() and IsEnvTrue()?

Comment thread pkg/output/output_setup.go Outdated
// has a value accepted by strconv.ParseBool.
// This duplicates nodeps.IsEnvTrue() because pkg/nodeps imports pkg/output
// (via wsl.go), creating an import cycle if we import nodeps here.
func isEnvTrue(envVar string) bool {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we need this duplicate of IsEnvTrue()?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

There's the import cycle mentioned in the comment. Is there some other way I could fix this?

@deviantintegral deviantintegral force-pushed the 20260321_deviantintegral_env_true_or_1 branch from 5802773 to 2998ed6 Compare March 31, 2026 18:14
@rfay
Copy link
Copy Markdown
Member

rfay commented Mar 31, 2026

Hate those import cycles!!! I guess that's the only thing I hate about go!

@rfay
Copy link
Copy Markdown
Member

rfay commented Mar 31, 2026

This comment is from Claude Code (AI assistant), at the request of @rfay.

Looking at the import cycle that forced the duplication of isEnvTrue in pkg/output, the root cause is in pkg/nodeps/wsl.go.

pkg/nodeps is meant to be a low-level package with no dependencies on other DDEV packages (the name says so). But IsWSL2MirroredMode() imports pkg/output just to emit a warning on an error path:

output.UserErr.Warnf("Unable to get WSL2 networking mode: %v", err)

This creates the cycle: pkg/nodepspkg/output, which then prevents pkg/output from importing pkg/nodeps to use IsEnvTrue.

The fix is to have IsWSL2MirroredMode return the error instead of swallowing it with a warning:

func IsWSL2MirroredMode() (bool, error) {
    if !IsWSL2() {
        return false, nil
    }
    mode, err := GetWSL2NetworkingMode()
    if err != nil {
        return false, err
    }
    return mode == "mirrored", nil
}

The caller (in a higher-level package that is allowed to import pkg/output) handles the warning. That restores proper layering, breaks the cycle, and lets pkg/output use nodeps.IsEnvTrue directly — eliminating the duplicate.

@rfay
Copy link
Copy Markdown
Member

rfay commented Mar 31, 2026

I imagine that conflicts with #8262 but it can be fixed there. OK to solve this problem in this PR. It's poor existing usage I think.

deviantintegral and others added 4 commits April 9, 2026 17:56
Add nodeps.IsEnvTrue() helper that treats both "true" and "1" as truthy,
matching common Unix conventions. Applied to DDEV_DEBUG, DDEV_VERBOSE,
DDEV_NO_INSTRUMENTATION, and DDEV_NONINTERACTIVE.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@stasadev stasadev force-pushed the 20260321_deviantintegral_env_true_or_1 branch from 2998ed6 to 3851b5a Compare April 9, 2026 15:11
@stasadev
Copy link
Copy Markdown
Member

stasadev commented Apr 9, 2026

Changes:

  1. Behavior improvements

    • DDEV_NO_TUI=1 now correctly disables TUI (old code only responded to empty/non-empty)
    • NO_COLOR now follows no-color.org spec: any non-empty value disables color (old code accidentally treated NO_COLOR=0 as "colors enabled")
    • DDEV_GOROUTINES changed from != "" to IsEnvTrue - only truthy values enable goroutine reporting
  2. Required fix: import cycle
    pkg/nodeps/wsl.go removed output.UserErr.Warnf(...) and its import of pkg/output. This was necessary because pkg/output/output_setup.go now imports pkg/nodeps (for IsEnvTrue), so the reverse import would cause a cycle.

  3. Test cleanup
    Manual save/restore of DDEV_DEBUG replaced with t.Setenv("DDEV_DEBUG", "") throughout - cleaner and race-safe.

  4. Correctly left unchanged (external env vars, always set to "true" by infrastructure)

    • os.Getenv("GITHUB_ACTIONS") == "true" - set by GitHub Actions
    • os.Getenv("CI") == "true" - set by CI systems (GitHub Actions, GitLab, etc.)
    • os.Getenv("CODESPACES") == "true" - set by GitHub Codespaces
    • os.Getenv("IN_DEVCONTAINER") == "true" - set by VS Code devcontainers

Copy link
Copy Markdown
Member

@rfay rfay left a comment

Choose a reason for hiding this comment

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

Yay, thank you!

@deviantintegral
Copy link
Copy Markdown
Collaborator Author

Thank you both for picking this up!

Copy link
Copy Markdown
Member

@stasadev stasadev left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@rfay rfay merged commit f01e6db into ddev:main Apr 10, 2026
40 of 43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants