Skip to content

Conversation

@osterman
Copy link
Member

@osterman osterman commented Oct 6, 2025

what

  • Add --version persistent flag to RootCmd as a simple alias for atmos version command
  • Update isVersionCommand() helper to detect both version and --version forms
  • Add test case for atmos --version in empty directory (no config required)
  • Add test case for --version flag to TestIsVersionCommand

why

  • Provides a conventional CLI experience - most command-line tools support --version flag
  • Aligns with standard POSIX/GNU conventions for version flags
  • Makes version checking easier for users and scripts
  • Both atmos version and atmos --version now work without requiring atmos.yaml configuration

references

  • atmos --version outputs simple format: atmos <version>
  • atmos version outputs full styled format with update checks
  • The --version flag does not support additional flags like --check or --format (use atmos version for those features)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added a global --version flag that prints the Atmos CLI version and exits; help/usage updated across commands.
  • Bug Fixes

    • Treat "--version" as a valid version invocation (equivalent to "version").
  • Tests

    • Added tests for flag parsing and execution, updated help snapshots, added empty-dir CLI test, and isolated flag state between tests.
  • Documentation

    • Updated CLI docs and cheatsheet; added guidance on version disambiguation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@osterman osterman requested a review from a team as a code owner October 6, 2025 13:35
@github-actions github-actions bot added the size/s Small size PR label Oct 6, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 6, 2025

Warning

Rate limit exceeded

@aknysh has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 4 minutes and 25 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 78ade74 and 436dedf.

📒 Files selected for processing (1)
  • cmd/root_test.go (2 hunks)
📝 Walkthrough

Walkthrough

Adds a persistent global --version flag to RootCmd, treats --version as a version invocation, routes it through the existing version execution path (prints CLI version and exits), and updates tests, snapshots, and documentation to reflect the new flag.

Changes

Cohort / File(s) Summary
Command utilities
cmd/cmd_utils.go
Extend isVersionCommand to accept --version as a version invocation in addition to version.
Command utils tests
cmd/cmd_utils_test.go
Add test asserting ["--version"] yields true for isVersionCommand.
Root command & tests
cmd/root.go, cmd/root_test.go, cmd/terraform_generate_backend_test.go
Register persistent --version flag on RootCmd; PersistentPreRun detects the flag and invokes NewVersionExec(&tmpConfig).Execute(false, "") then exits. Add tests for parsing/execution and reset persistent flags between tests to avoid cross-test pollution.
E2E test case
tests/test-cases/empty-dir.yaml
Add e2e test verifying atmos --version prints CLI version, exits 0, and has no stderr in the empty-dir fixture.
CLI help snapshots
tests/snapshots/*
Update many golden help-output snapshots to include the new global --version flag under Global Flags.
Docs / Website
website/docs/**
Add documentation and disambiguation about --version (usage, note that it prints Atmos CLI version only) across CLI guides, cheatsheets, and global flags docs.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User
  participant Root as RootCmd
  participant Flags as FlagParser
  participant Exec as VersionExec
  participant OS as Stdout/Process

  U->>Root: atmos --version
  Root->>Flags: parse persistent/global flags
  Note over Root,Flags: PersistentPreRun detects `--version`
  Flags-->>Root: version=true
  Root->>Exec: NewVersionExec(&tmpConfig).Execute(false, "")
  Exec-->>Root: "atmos <version>"
  Root->>OS: print version
  Root->>OS: exit(0)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • aknysh

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly indicates the PR’s primary update—adding the --version flag as an alias for the version command—and succinctly summarizes the change without including unrelated details or extraneous wording.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
cmd/root.go (1)

60-65: Minor: Consider checking the error from GetBool.

The implementation correctly handles the --version flag with early exit and simple output. However, the error from cmd.Flags().GetBool("version") is silently ignored. While this is low risk since the flag is guaranteed to exist, explicit error handling aligns better with the project's error handling guidelines.

Consider this adjustment:

-if versionFlag, _ := cmd.Flags().GetBool("version"); versionFlag {
+if versionFlag, err := cmd.Flags().GetBool("version"); err == nil && versionFlag {
     fmt.Printf("atmos %s\n", version.Version)
     utils.OsExit(0)
     return
 }

Based on coding guidelines.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 94ad05f and 2f28383.

📒 Files selected for processing (4)
  • cmd/cmd_utils.go (1 hunks)
  • cmd/cmd_utils_test.go (1 hunks)
  • cmd/root.go (3 hunks)
  • tests/test-cases/empty-dir.yaml (1 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
cmd/**/*.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

cmd/**/*.go: Use Cobra's recommended command structure with a root command and subcommands
Implement each CLI command in a separate file under cmd/
Use Viper for managing configuration, environment variables, and flags in the CLI
Keep separation of concerns between CLI interface (cmd) and business logic
Use kebab-case for command-line flags
Provide comprehensive help text for all commands and flags
Include examples in Cobra command help
Use Viper for configuration management; support files, env vars, and flags with precedence flags > env > config > defaults
Follow single responsibility; separate command interface from business logic
Provide meaningful user feedback and include progress indicators for long-running operations
Provide clear error messages to users and troubleshooting hints where appropriate

cmd/**/*.go: For CLI examples, load content via //go:embed and render with utils.PrintfMarkdown(); register examples in cmd/markdown_help.go.
One Cobra command per file in cmd/.
For non-standard execution paths, capture telemetry via telemetry.CaptureCmd or telemetry.CaptureCmdString without collecting user data.

Files:

  • cmd/cmd_utils_test.go
  • cmd/cmd_utils.go
  • cmd/root.go
**/*_test.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

**/*_test.go: Every new feature must include comprehensive unit tests
Test both happy paths and error conditions
Use table-driven tests for multiple scenarios

**/*_test.go: Test quality: test behavior not implementation; avoid testing stubs or tautologies; use DI to avoid hard deps (os.Exit, CheckErrorPrintAndExit); remove always-skipped tests; table-driven tests must use real scenarios.
Always use t.Skipf with a clear reason instead of t.Skip; never call t.Skipf without a reason.
Co-locate test files alongside implementations using *_test.go naming.

Files:

  • cmd/cmd_utils_test.go
**/*.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

**/*.go: All code must pass golangci-lint checks
Follow Go error handling idioms and use meaningful error messages
Wrap errors with context using fmt.Errorf("context: %w", err)
Consider custom error types for domain-specific errors
Follow standard Go coding style; run gofmt and goimports
Use snake_case for environment variables
Document complex logic with inline comments

**/*.go: All comments in Go code must end with periods; enforced by golangci-lint's godot.
Organize imports into three groups (stdlib, 3rd-party, Atmos) separated by blank lines; sort alphabetically within each group; maintain existing import aliases.
Add defer perf.Track() to all public functions and critical private functions, with a blank line after the call; use package-qualified names (e.g., "exec.ProcessComponent"); pass atmosConfig if available, else nil.
Error handling: wrap errors using static errors from errors/errors.go; prefer errors.Join for multiple errors; add context with fmt.Errorf("%w", ...); use errors.Is for checks; never compare error strings or return dynamic errors directly.
Always bind environment variables with viper.BindEnv; every env var must have an ATMOS_ alternative (e.g., viper.BindEnv("ATMOS_GITHUB_TOKEN", "GITHUB_TOKEN")).
Use structured logging for system/debug info and direct UI output to stderr; never use logging for UI elements; data/results intended for piping must go to stdout.
Most text UI must go to stderr (e.g., utils.PrintfMessageToTUI or fmt.Fprintf(os.Stderr,...)); only data/results go to stdout.
Ensure cross-platform compatibility: prefer SDKs over shelling out to binaries, use filepath/os utilities, and guard OS-specific logic with build constraints or runtime.GOOS when necessary.

Files:

  • cmd/cmd_utils_test.go
  • cmd/cmd_utils.go
  • cmd/root.go
cmd/**/*_test.go

📄 CodeRabbit inference engine (CLAUDE.md)

Place command tests under cmd/ as *_test.go files.

Files:

  • cmd/cmd_utils_test.go
**/!(*_test).go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

Document all exported functions, types, and methods with Go doc comments

Files:

  • cmd/cmd_utils.go
  • cmd/root.go
cmd/root.go

📄 CodeRabbit inference engine (CLAUDE.md)

Telemetry: standard Cobra commands added to RootCmd get telemetry via RootCmd.ExecuteC() (see cmd/root.go:174); do not add extra telemetry for standard paths.

Files:

  • cmd/root.go
tests/{test-cases,testdata}/**

📄 CodeRabbit inference engine (CLAUDE.md)

Never modify golden snapshot files under tests/test-cases/ or tests/testdata/ unless explicitly instructed.

Files:

  • tests/test-cases/empty-dir.yaml
🧠 Learnings (3)
📚 Learning: 2025-09-05T14:57:37.360Z
Learnt from: RoseSecurity
PR: cloudposse/atmos#1448
File: cmd/ansible.go:26-28
Timestamp: 2025-09-05T14:57:37.360Z
Learning: The Atmos codebase uses a consistent pattern for commands that delegate to external tools: `PersistentFlags().Bool("", false, doubleDashHint)` where doubleDashHint provides help text about using double dashes to separate Atmos options from native command arguments. This pattern is used across terraform, packer, helmfile, atlantis, aws, and ansible commands.

Applied to files:

  • cmd/root.go
📚 Learning: 2024-12-13T15:28:13.630Z
Learnt from: Listener430
PR: cloudposse/atmos#844
File: cmd/version.go:34-44
Timestamp: 2024-12-13T15:28:13.630Z
Learning: In `cmd/version.go`, when handling the `--check` flag in the `versionCmd`, avoid using `CheckForAtmosUpdateAndPrintMessage(cliConfig)` as it updates the cache timestamp, which may not be desired in this context.

Applied to files:

  • cmd/root.go
📚 Learning: 2025-01-30T19:30:59.120Z
Learnt from: samtholiya
PR: cloudposse/atmos#959
File: cmd/workflow.go:74-74
Timestamp: 2025-01-30T19:30:59.120Z
Learning: Error handling for `cmd.Usage()` is not required in the Atmos CLI codebase, as confirmed by the maintainer.

Applied to files:

  • cmd/root.go
🧬 Code graph analysis (1)
cmd/root.go (1)
pkg/utils/log_utils.go (1)
  • OsExit (16-16)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Analyze (go)
  • GitHub Check: Lint (golangci)
  • GitHub Check: Summary
🔇 Additional comments (5)
cmd/cmd_utils.go (1)

594-596: LGTM!

The updated logic correctly identifies both version and --version as valid version commands. Clean and straightforward implementation.

cmd/root.go (2)

34-34: LGTM!

Import addition is necessary for the version flag implementation.


526-526: LGTM!

Flag definition is correct. Using PersistentFlags ensures --version works consistently across all commands.

cmd/cmd_utils_test.go (1)

167-171: LGTM!

Test case properly verifies the new --version flag behavior. Well-structured and consistent with existing test patterns.

tests/test-cases/empty-dir.yaml (1)

17-31: LGTM!

E2E test properly verifies --version works without configuration. The regex pattern correctly matches the simple output format, and testing in the empty-dir fixture confirms the version flag doesn't require atmos.yaml.

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 6, 2025
@osterman osterman added the minor New features that do not break anything label Oct 6, 2025
- Add error check for GetBool("version") flag per CodeRabbit review
- Regenerate 17 help snapshot files to include --version flag
- All help outputs now correctly show the new --version flag

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Oct 6, 2025

Codecov Report

❌ Patch coverage is 72.72727% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.22%. Comparing base (72ea7ed) to head (436dedf).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cmd/root.go 70.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1600      +/-   ##
==========================================
+ Coverage   63.06%   63.22%   +0.15%     
==========================================
  Files         325      325              
  Lines       37370    37380      +10     
==========================================
+ Hits        23568    23632      +64     
+ Misses      11812    11756      -56     
- Partials     1990     1992       +2     
Flag Coverage Δ
unittests 63.22% <72.72%> (+0.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cmd/cmd_utils.go 18.79% <100.00%> (ø)
cmd/root.go 42.44% <70.00%> (+0.62%) ⬆️

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Move --version handling to call exec.NewVersionExec().Execute()
- Both commands now produce identical rich formatted output
- Update flag description to "Alias for 'atmos version' command"
- Update test expectations for rich format output
- Regenerate help snapshots with new flag description
- Remove unused version import from root.go

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 6, 2025
- Reset --version flag state before tests to prevent pollution
- Add comprehensive TestVersionFlagParsing with multiple scenarios
- Fix TestTerraformGenerateBackendCmd by resetting flag states
- Remove unused contains() helper function
- All cmd tests now pass without cross-test interference

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions bot added size/m Medium size PR and removed size/s Small size PR labels Oct 6, 2025
osterman and others added 2 commits October 6, 2025 09:57
- Mock utils.OsExit to test version flag execution without exiting
- Verify version handler calls os.Exit(0) when --version is set
- Test properly resets flag state to prevent pollution
- Achieves comprehensive coverage of the --version code path

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Change description from "Alias for 'atmos version' command"
  to "Alias for \`atmos version\` command" for consistency
- Update test to match new description
- Regenerate help snapshots with updated formatting

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 65fb3be and 427b7ee.

📒 Files selected for processing (20)
  • cmd/root.go (2 hunks)
  • cmd/root_test.go (2 hunks)
  • cmd/terraform_generate_backend_test.go (2 hunks)
  • tests/snapshots/TestCLICommands_atmos_--help.stdout.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_about_--help.stdout.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_atlantis_--help.stdout.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_atlantis_generate_--help.stdout.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_atlantis_generate_help.stdout.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_atlantis_generate_repo-config_--help.stdout.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_atlantis_generate_repo-config_help.stdout.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_atlantis_help.stdout.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_helmfile_--help.stdout.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_helmfile_apply_--help.stdout.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_helmfile_apply_help.stdout.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_helmfile_help.stdout.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_terraform_--help.stdout.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_terraform_--help_alias_subcommand_check.stdout.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_terraform_apply_--help.stdout.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_terraform_apply_help.stdout.golden (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_terraform_help.stdout.golden (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (9)
  • tests/snapshots/TestCLICommands_atmos_atlantis_generate_repo-config_--help.stdout.golden
  • tests/snapshots/TestCLICommands_atmos_helmfile_apply_help.stdout.golden
  • cmd/root.go
  • tests/snapshots/TestCLICommands_atmos_--help.stdout.golden
  • tests/snapshots/TestCLICommands_atmos_atlantis_generate_--help.stdout.golden
  • tests/snapshots/TestCLICommands_atmos_terraform_apply_--help.stdout.golden
  • tests/snapshots/TestCLICommands_atmos_helmfile_help.stdout.golden
  • tests/snapshots/TestCLICommands_atmos_terraform_apply_help.stdout.golden
  • tests/snapshots/TestCLICommands_atmos_helmfile_apply_--help.stdout.golden
🧰 Additional context used
📓 Path-based instructions (4)
cmd/**/*.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

cmd/**/*.go: Use Cobra's recommended command structure with a root command and subcommands
Implement each CLI command in a separate file under cmd/
Use Viper for managing configuration, environment variables, and flags in the CLI
Keep separation of concerns between CLI interface (cmd) and business logic
Use kebab-case for command-line flags
Provide comprehensive help text for all commands and flags
Include examples in Cobra command help
Use Viper for configuration management; support files, env vars, and flags with precedence flags > env > config > defaults
Follow single responsibility; separate command interface from business logic
Provide meaningful user feedback and include progress indicators for long-running operations
Provide clear error messages to users and troubleshooting hints where appropriate

cmd/**/*.go: For CLI examples, load content via //go:embed and render with utils.PrintfMarkdown(); register examples in cmd/markdown_help.go.
One Cobra command per file in cmd/.
For non-standard execution paths, capture telemetry via telemetry.CaptureCmd or telemetry.CaptureCmdString without collecting user data.

Files:

  • cmd/terraform_generate_backend_test.go
  • cmd/root_test.go
**/*_test.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

**/*_test.go: Every new feature must include comprehensive unit tests
Test both happy paths and error conditions
Use table-driven tests for multiple scenarios

**/*_test.go: Test quality: test behavior not implementation; avoid testing stubs or tautologies; use DI to avoid hard deps (os.Exit, CheckErrorPrintAndExit); remove always-skipped tests; table-driven tests must use real scenarios.
Always use t.Skipf with a clear reason instead of t.Skip; never call t.Skipf without a reason.
Co-locate test files alongside implementations using *_test.go naming.

Files:

  • cmd/terraform_generate_backend_test.go
  • cmd/root_test.go
**/*.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

**/*.go: All code must pass golangci-lint checks
Follow Go error handling idioms and use meaningful error messages
Wrap errors with context using fmt.Errorf("context: %w", err)
Consider custom error types for domain-specific errors
Follow standard Go coding style; run gofmt and goimports
Use snake_case for environment variables
Document complex logic with inline comments

**/*.go: All comments in Go code must end with periods; enforced by golangci-lint's godot.
Organize imports into three groups (stdlib, 3rd-party, Atmos) separated by blank lines; sort alphabetically within each group; maintain existing import aliases.
Add defer perf.Track() to all public functions and critical private functions, with a blank line after the call; use package-qualified names (e.g., "exec.ProcessComponent"); pass atmosConfig if available, else nil.
Error handling: wrap errors using static errors from errors/errors.go; prefer errors.Join for multiple errors; add context with fmt.Errorf("%w", ...); use errors.Is for checks; never compare error strings or return dynamic errors directly.
Always bind environment variables with viper.BindEnv; every env var must have an ATMOS_ alternative (e.g., viper.BindEnv("ATMOS_GITHUB_TOKEN", "GITHUB_TOKEN")).
Use structured logging for system/debug info and direct UI output to stderr; never use logging for UI elements; data/results intended for piping must go to stdout.
Most text UI must go to stderr (e.g., utils.PrintfMessageToTUI or fmt.Fprintf(os.Stderr,...)); only data/results go to stdout.
Ensure cross-platform compatibility: prefer SDKs over shelling out to binaries, use filepath/os utilities, and guard OS-specific logic with build constraints or runtime.GOOS when necessary.

Files:

  • cmd/terraform_generate_backend_test.go
  • cmd/root_test.go
cmd/**/*_test.go

📄 CodeRabbit inference engine (CLAUDE.md)

Place command tests under cmd/ as *_test.go files.

Files:

  • cmd/terraform_generate_backend_test.go
  • cmd/root_test.go
🧠 Learnings (2)
📚 Learning: 2025-08-15T14:43:41.030Z
Learnt from: aknysh
PR: cloudposse/atmos#1352
File: pkg/store/artifactory_store_test.go:108-113
Timestamp: 2025-08-15T14:43:41.030Z
Learning: In test files for the atmos project, it's acceptable to ignore errors from os.Setenv/Unsetenv operations during test environment setup and teardown, as these are controlled test scenarios.

Applied to files:

  • cmd/terraform_generate_backend_test.go
📚 Learning: 2024-12-07T16:16:13.038Z
Learnt from: Listener430
PR: cloudposse/atmos#825
File: internal/exec/helmfile_generate_varfile.go:28-31
Timestamp: 2024-12-07T16:16:13.038Z
Learning: In `internal/exec/helmfile_generate_varfile.go`, the `--help` command (`./atmos helmfile generate varfile --help`) works correctly without requiring stack configurations, and the only change needed was to make `ProcessCommandLineArgs` exportable by capitalizing its name.

Applied to files:

  • tests/snapshots/TestCLICommands_atmos_helmfile_--help.stdout.golden
🧬 Code graph analysis (2)
cmd/terraform_generate_backend_test.go (1)
cmd/root.go (1)
  • RootCmd (53-153)
cmd/root_test.go (2)
cmd/root.go (2)
  • RootCmd (53-153)
  • Execute (422-469)
pkg/utils/log_utils.go (1)
  • OsExit (16-16)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Build (macos-latest, macos)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Build (ubuntu-latest, linux)
  • GitHub Check: Analyze (go)
  • GitHub Check: Lint (golangci)
  • GitHub Check: Summary
🔇 Additional comments (3)
cmd/root_test.go (1)

12-15: Imports LGTM.

Grouped and ordered per guidelines; alias usage is consistent.

tests/snapshots/TestCLICommands_atmos_terraform_--help.stdout.golden (1)

216-218: Consistent snapshot update.

Matches the new global --version flag semantics.

tests/snapshots/TestCLICommands_atmos_terraform_help.stdout.golden (1)

216-218: Global flag wording consistent across all help snapshots.

osterman and others added 2 commits October 6, 2025 11:10
- Add periods to all inline comments for godot linter compliance
- Use assert.Contains instead of assert.Equal for usage text (more robust)
- Replace defer with t.Cleanup for test cleanup
- Fix flag reset in TestTerraformGenerateBackendCmd to only reset version flag
  (VisitAll on all flags was causing test failures with complex flag types)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Convert TestVersionFlagExecutionPath to table-driven test
- Add test case for version command (ensures flag check doesn't interfere)
- Add test case for --version flag (covers successful exit path)
- Improves patch coverage by testing multiple execution scenarios

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
cmd/root_test.go (2)

349-350: Comment doesn't match the code.

The comment claims to create a fresh instance, but cmd := RootCmd just assigns the same global pointer. The actual state isolation happens via the flag reset on lines 343-347, so the test works correctly—the comment is just misleading.

Consider updating the comment:

-			// Create a fresh command instance to avoid state pollution.
-			cmd := RootCmd
-			cmd.SetArgs(tt.args)
+			// Use the global RootCmd; state isolation is handled by flag reset above.
+			RootCmd.SetArgs(tt.args)

Then reference RootCmd directly in the assertions instead of cmd.


390-401: Test case name is confusing.

The case is labeled "version flag false does not exit" but it's actually testing the version subcommand (not the --version flag). The intent is to verify the subcommand doesn't trigger the flag handler's exit path, which is correct behavior—but the name doesn't clearly convey this.

Consider renaming for clarity:

 		{
-			name: "version flag false does not exit",
+			name: "version subcommand bypasses flag handler",
 			setup: func() {
 				versionFlag := RootCmd.PersistentFlags().Lookup("version")
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between bd1d316 and 3336637.

📒 Files selected for processing (1)
  • cmd/root_test.go (2 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
cmd/**/*.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

cmd/**/*.go: Use Cobra's recommended command structure with a root command and subcommands
Implement each CLI command in a separate file under cmd/
Use Viper for managing configuration, environment variables, and flags in the CLI
Keep separation of concerns between CLI interface (cmd) and business logic
Use kebab-case for command-line flags
Provide comprehensive help text for all commands and flags
Include examples in Cobra command help
Use Viper for configuration management; support files, env vars, and flags with precedence flags > env > config > defaults
Follow single responsibility; separate command interface from business logic
Provide meaningful user feedback and include progress indicators for long-running operations
Provide clear error messages to users and troubleshooting hints where appropriate

cmd/**/*.go: For CLI examples, load content via //go:embed and render with utils.PrintfMarkdown(); register examples in cmd/markdown_help.go.
One Cobra command per file in cmd/.
For non-standard execution paths, capture telemetry via telemetry.CaptureCmd or telemetry.CaptureCmdString without collecting user data.

Files:

  • cmd/root_test.go
**/*_test.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

**/*_test.go: Every new feature must include comprehensive unit tests
Test both happy paths and error conditions
Use table-driven tests for multiple scenarios

**/*_test.go: Test quality: test behavior not implementation; avoid testing stubs or tautologies; use DI to avoid hard deps (os.Exit, CheckErrorPrintAndExit); remove always-skipped tests; table-driven tests must use real scenarios.
Always use t.Skipf with a clear reason instead of t.Skip; never call t.Skipf without a reason.
Co-locate test files alongside implementations using *_test.go naming.

Files:

  • cmd/root_test.go
**/*.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

**/*.go: All code must pass golangci-lint checks
Follow Go error handling idioms and use meaningful error messages
Wrap errors with context using fmt.Errorf("context: %w", err)
Consider custom error types for domain-specific errors
Follow standard Go coding style; run gofmt and goimports
Use snake_case for environment variables
Document complex logic with inline comments

**/*.go: All comments in Go code must end with periods; enforced by golangci-lint's godot.
Organize imports into three groups (stdlib, 3rd-party, Atmos) separated by blank lines; sort alphabetically within each group; maintain existing import aliases.
Add defer perf.Track() to all public functions and critical private functions, with a blank line after the call; use package-qualified names (e.g., "exec.ProcessComponent"); pass atmosConfig if available, else nil.
Error handling: wrap errors using static errors from errors/errors.go; prefer errors.Join for multiple errors; add context with fmt.Errorf("%w", ...); use errors.Is for checks; never compare error strings or return dynamic errors directly.
Always bind environment variables with viper.BindEnv; every env var must have an ATMOS_ alternative (e.g., viper.BindEnv("ATMOS_GITHUB_TOKEN", "GITHUB_TOKEN")).
Use structured logging for system/debug info and direct UI output to stderr; never use logging for UI elements; data/results intended for piping must go to stdout.
Most text UI must go to stderr (e.g., utils.PrintfMessageToTUI or fmt.Fprintf(os.Stderr,...)); only data/results go to stdout.
Ensure cross-platform compatibility: prefer SDKs over shelling out to binaries, use filepath/os utilities, and guard OS-specific logic with build constraints or runtime.GOOS when necessary.

Files:

  • cmd/root_test.go
cmd/**/*_test.go

📄 CodeRabbit inference engine (CLAUDE.md)

Place command tests under cmd/ as *_test.go files.

Files:

  • cmd/root_test.go
🧠 Learnings (1)
📚 Learning: 2024-12-13T15:28:13.630Z
Learnt from: Listener430
PR: cloudposse/atmos#844
File: cmd/version.go:34-44
Timestamp: 2024-12-13T15:28:13.630Z
Learning: In `cmd/version.go`, when handling the `--check` flag in the `versionCmd`, avoid using `CheckForAtmosUpdateAndPrintMessage(cliConfig)` as it updates the cache timestamp, which may not be desired in this context.

Applied to files:

  • cmd/root_test.go
🧬 Code graph analysis (1)
cmd/root_test.go (2)
cmd/root.go (2)
  • RootCmd (53-153)
  • Execute (422-469)
pkg/utils/log_utils.go (1)
  • OsExit (16-16)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Build (ubuntu-latest, linux)
  • GitHub Check: Build (macos-latest, macos)
  • GitHub Check: Analyze (go)
  • GitHub Check: Lint (golangci)
  • GitHub Check: Summary
🔇 Additional comments (2)
cmd/root_test.go (2)

12-14: LGTM on imports.

The new utils import enables mocking OsExit for the execution path test, and the explicit log import aligns with existing usage in the file.


317-442: Solid test coverage for the --version flag.

Both tests follow the table-driven pattern, properly isolate state with cleanup, and verify the key behaviors: flag parsing and execution path with exit codes. Previous review feedback has been fully addressed.

- Change VisitAll to Visit in TestTerraformGenerateBackendCmd
- Only reset flags that were actually changed, avoiding issues with complex flag types
- This addresses CodeRabbit feedback while maintaining test stability
- All cmd tests pass successfully

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 6, 2025
- Document --version flag in global-flags.mdx as a core global flag
- Update version.mdx to show both 'atmos version' and 'atmos --version' usage
- Add version disambiguation warning explaining flag shows Atmos version, not tool versions
- Update cli.mdx with tip about --version flag availability
- Update commands.mdx cheatsheet to show both version command forms
- Website build verified successfully with no errors

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3336637 and cd1b8bd.

📒 Files selected for processing (5)
  • cmd/terraform_generate_backend_test.go (2 hunks)
  • website/docs/cheatsheets/commands.mdx (1 hunks)
  • website/docs/cli/cli.mdx (1 hunks)
  • website/docs/cli/commands/version.mdx (2 hunks)
  • website/docs/cli/global-flags.mdx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
cmd/**/*.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

cmd/**/*.go: Use Cobra's recommended command structure with a root command and subcommands
Implement each CLI command in a separate file under cmd/
Use Viper for managing configuration, environment variables, and flags in the CLI
Keep separation of concerns between CLI interface (cmd) and business logic
Use kebab-case for command-line flags
Provide comprehensive help text for all commands and flags
Include examples in Cobra command help
Use Viper for configuration management; support files, env vars, and flags with precedence flags > env > config > defaults
Follow single responsibility; separate command interface from business logic
Provide meaningful user feedback and include progress indicators for long-running operations
Provide clear error messages to users and troubleshooting hints where appropriate

cmd/**/*.go: For CLI examples, load content via //go:embed and render with utils.PrintfMarkdown(); register examples in cmd/markdown_help.go.
One Cobra command per file in cmd/.
For non-standard execution paths, capture telemetry via telemetry.CaptureCmd or telemetry.CaptureCmdString without collecting user data.

Files:

  • cmd/terraform_generate_backend_test.go
**/*_test.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

**/*_test.go: Every new feature must include comprehensive unit tests
Test both happy paths and error conditions
Use table-driven tests for multiple scenarios

**/*_test.go: Test quality: test behavior not implementation; avoid testing stubs or tautologies; use DI to avoid hard deps (os.Exit, CheckErrorPrintAndExit); remove always-skipped tests; table-driven tests must use real scenarios.
Always use t.Skipf with a clear reason instead of t.Skip; never call t.Skipf without a reason.
Co-locate test files alongside implementations using *_test.go naming.

Files:

  • cmd/terraform_generate_backend_test.go
**/*.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

**/*.go: All code must pass golangci-lint checks
Follow Go error handling idioms and use meaningful error messages
Wrap errors with context using fmt.Errorf("context: %w", err)
Consider custom error types for domain-specific errors
Follow standard Go coding style; run gofmt and goimports
Use snake_case for environment variables
Document complex logic with inline comments

**/*.go: All comments in Go code must end with periods; enforced by golangci-lint's godot.
Organize imports into three groups (stdlib, 3rd-party, Atmos) separated by blank lines; sort alphabetically within each group; maintain existing import aliases.
Add defer perf.Track() to all public functions and critical private functions, with a blank line after the call; use package-qualified names (e.g., "exec.ProcessComponent"); pass atmosConfig if available, else nil.
Error handling: wrap errors using static errors from errors/errors.go; prefer errors.Join for multiple errors; add context with fmt.Errorf("%w", ...); use errors.Is for checks; never compare error strings or return dynamic errors directly.
Always bind environment variables with viper.BindEnv; every env var must have an ATMOS_ alternative (e.g., viper.BindEnv("ATMOS_GITHUB_TOKEN", "GITHUB_TOKEN")).
Use structured logging for system/debug info and direct UI output to stderr; never use logging for UI elements; data/results intended for piping must go to stdout.
Most text UI must go to stderr (e.g., utils.PrintfMessageToTUI or fmt.Fprintf(os.Stderr,...)); only data/results go to stdout.
Ensure cross-platform compatibility: prefer SDKs over shelling out to binaries, use filepath/os utilities, and guard OS-specific logic with build constraints or runtime.GOOS when necessary.

Files:

  • cmd/terraform_generate_backend_test.go
cmd/**/*_test.go

📄 CodeRabbit inference engine (CLAUDE.md)

Place command tests under cmd/ as *_test.go files.

Files:

  • cmd/terraform_generate_backend_test.go
website/**

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

website/**: Update website documentation in website/ when adding features
Ensure consistency between CLI help text and website documentation
Follow the website's documentation structure and style
Keep website code in website/ and follow its architecture/style; test changes locally
Keep CLI and website documentation in sync; document new features with examples and use cases

Files:

  • website/docs/cli/commands/version.mdx
  • website/docs/cli/cli.mdx
  • website/docs/cheatsheets/commands.mdx
  • website/docs/cli/global-flags.mdx
website/docs/cli/commands/**/*.mdx

📄 CodeRabbit inference engine (CLAUDE.md)

All new commands/flags/parameters must have Docusaurus docs at website/docs/cli/commands//.mdx using definition lists (

) for Arguments and Flags, with prescribed frontmatter and section order.

Files:

  • website/docs/cli/commands/version.mdx
🧠 Learnings (6)
📚 Learning: 2025-08-15T14:43:41.030Z
Learnt from: aknysh
PR: cloudposse/atmos#1352
File: pkg/store/artifactory_store_test.go:108-113
Timestamp: 2025-08-15T14:43:41.030Z
Learning: In test files for the atmos project, it's acceptable to ignore errors from os.Setenv/Unsetenv operations during test environment setup and teardown, as these are controlled test scenarios.

Applied to files:

  • cmd/terraform_generate_backend_test.go
📚 Learning: 2024-10-27T16:59:26.187Z
Learnt from: osterman
PR: cloudposse/atmos#729
File: internal/exec/help.go:48-51
Timestamp: 2024-10-27T16:59:26.187Z
Learning: In the Atmos CLI help messages, when providing examples that include the version number, use the actual version variable (e.g., `version.Version`) instead of placeholders like `<version>`.

Applied to files:

  • website/docs/cli/commands/version.mdx
📚 Learning: 2025-09-13T16:39:20.007Z
Learnt from: samtholiya
PR: cloudposse/atmos#1466
File: cmd/markdown/atmos_toolchain_aliases.md:2-4
Timestamp: 2025-09-13T16:39:20.007Z
Learning: In the cloudposse/atmos repository, CLI documentation files in cmd/markdown/ follow a specific format that uses " $ atmos command" (with leading space and dollar sign prompt) in code blocks. This is the established project convention and should not be changed to comply with standard markdownlint rules MD040 and MD014.

Applied to files:

  • website/docs/cli/commands/version.mdx
  • website/docs/cli/cli.mdx
  • website/docs/cheatsheets/commands.mdx
📚 Learning: 2025-01-19T15:49:15.593Z
Learnt from: samtholiya
PR: cloudposse/atmos#955
File: tests/snapshots/TestCLICommands_atmos_validate_editorconfig_--help.stdout.golden:0-0
Timestamp: 2025-01-19T15:49:15.593Z
Learning: In future commits, the help text for Atmos CLI commands should be limited to only show component and stack parameters for commands that actually use them. This applies to the example usage section in command help text.

Applied to files:

  • website/docs/cli/commands/version.mdx
📚 Learning: 2025-09-05T14:57:37.360Z
Learnt from: RoseSecurity
PR: cloudposse/atmos#1448
File: cmd/ansible.go:26-28
Timestamp: 2025-09-05T14:57:37.360Z
Learning: The Atmos codebase uses a consistent pattern for commands that delegate to external tools: `PersistentFlags().Bool("", false, doubleDashHint)` where doubleDashHint provides help text about using double dashes to separate Atmos options from native command arguments. This pattern is used across terraform, packer, helmfile, atlantis, aws, and ansible commands.

Applied to files:

  • website/docs/cli/commands/version.mdx
  • website/docs/cli/global-flags.mdx
📚 Learning: 2024-12-13T15:28:13.630Z
Learnt from: Listener430
PR: cloudposse/atmos#844
File: cmd/version.go:34-44
Timestamp: 2024-12-13T15:28:13.630Z
Learning: In `cmd/version.go`, when handling the `--check` flag in the `versionCmd`, avoid using `CheckForAtmosUpdateAndPrintMessage(cliConfig)` as it updates the cache timestamp, which may not be desired in this context.

Applied to files:

  • website/docs/cli/commands/version.mdx
🧬 Code graph analysis (1)
cmd/terraform_generate_backend_test.go (1)
cmd/root.go (1)
  • RootCmd (53-153)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Build (ubuntu-latest, linux)
  • GitHub Check: Build (macos-latest, macos)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Run pre-commit hooks
  • GitHub Check: Lint (golangci)
  • GitHub Check: Analyze (go)
  • GitHub Check: website-deploy-preview
  • GitHub Check: Summary
🔇 Additional comments (2)
cmd/terraform_generate_backend_test.go (2)

9-9: Import addition looks good.

Clean addition of the pflag package to support the flag reset logic below.


25-30: Proper test isolation pattern.

This flag reset logic correctly addresses cross-test pollution from persistent flags (like the newly added --version flag). The implementation properly resets both the flag value and the Changed state, using Visit() to target only flags that were actually changed—avoiding issues with complex flag types as discussed in previous reviews.

osterman and others added 2 commits October 6, 2025 12:10
- Update global-flags.mdx to explain --version prints minimal single-line output
- Clarify --version does not perform update checks or support --check/--format flags
- Add note directing users to 'atmos version' for richer output and additional functionality
- Update version.mdx to distinguish between the flag and command behavior
- Remove misleading "equivalent" claim that suggested identical functionality
- Website build verified successfully

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 6, 2025
- Complete the work started in commit 9cc0720 which updated only 6 auth command golden files
- Update 17 additional help command golden files with new --version flag text
- Change from "Alias for atmos version command (default false)" to "Display the Atmos CLI version"
- This matches the DefValue="" change in cmd/root.go that hides the confusing "(default false)"

Files updated:
- Main help: atmos --help
- About: atmos about --help
- Atlantis commands (6 files): atlantis --help, generate --help/help, repo-config --help/help
- Helmfile commands (5 files): helmfile --help/help, apply --help/help
- Terraform commands (5 files): terraform --help/help, apply --help/help, alias check

This resolves the CI test failures caused by mismatched golden snapshots.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 6, 2025
- Update test assertion to check for "Atmos CLI version" instead of "atmos version"
- This matches the updated flag description from commit 9cc0720
- The new description is "Display the Atmos CLI version" which doesn't contain "atmos version" as a substring
- Test was failing on Windows CI with: "Display the Atmos CLI version" does not contain "atmos version"

This resolves the Windows CI test failure in TestVersionFlagParsing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Fix misleading comment: clarify that state isolation is via flag reset, not creating new instance
- Remove unnecessary cmd variable alias; use RootCmd directly for clarity
- Rename test case from "version flag false does not exit" to "version subcommand bypasses flag handler"
  to accurately reflect that it tests the version subcommand, not the --version flag

These are code clarity improvements that make the test more self-documenting without changing behavior.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
cmd/root_test.go (1)

349-351: Clarify comment about command instance.

The comment says "Create a fresh command instance" but the code assigns the existing RootCmd pointer, not creating a new instance. This could confuse readers about what's actually happening.

Apply this diff to clarify:

-			// Create a fresh command instance to avoid state pollution.
-			cmd := RootCmd
-			cmd.SetArgs(tt.args)
+			// Use RootCmd and set test arguments.
+			RootCmd.SetArgs(tt.args)

Or if you truly need a fresh instance to avoid state pollution, create one properly. The current approach relies on flag reset (lines 343-347) rather than instance isolation.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 8c74737 and 78ade74.

📒 Files selected for processing (1)
  • cmd/root_test.go (2 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
cmd/**/*.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

cmd/**/*.go: Use Cobra's recommended command structure with a root command and subcommands
Implement each CLI command in a separate file under cmd/
Use Viper for managing configuration, environment variables, and flags in the CLI
Keep separation of concerns between CLI interface (cmd) and business logic
Use kebab-case for command-line flags
Provide comprehensive help text for all commands and flags
Include examples in Cobra command help
Use Viper for configuration management; support files, env vars, and flags with precedence flags > env > config > defaults
Follow single responsibility; separate command interface from business logic
Provide meaningful user feedback and include progress indicators for long-running operations
Provide clear error messages to users and troubleshooting hints where appropriate

cmd/**/*.go: For CLI examples, load content via //go:embed and render with utils.PrintfMarkdown(); register examples in cmd/markdown_help.go.
One Cobra command per file in cmd/.
For non-standard execution paths, capture telemetry via telemetry.CaptureCmd or telemetry.CaptureCmdString without collecting user data.

Files:

  • cmd/root_test.go
**/*_test.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

**/*_test.go: Every new feature must include comprehensive unit tests
Test both happy paths and error conditions
Use table-driven tests for multiple scenarios

**/*_test.go: Test quality: test behavior not implementation; avoid testing stubs or tautologies; use DI to avoid hard deps (os.Exit, CheckErrorPrintAndExit); remove always-skipped tests; table-driven tests must use real scenarios.
Always use t.Skipf with a clear reason instead of t.Skip; never call t.Skipf without a reason.
Co-locate test files alongside implementations using *_test.go naming.

Files:

  • cmd/root_test.go
**/*.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

**/*.go: All code must pass golangci-lint checks
Follow Go error handling idioms and use meaningful error messages
Wrap errors with context using fmt.Errorf("context: %w", err)
Consider custom error types for domain-specific errors
Follow standard Go coding style; run gofmt and goimports
Use snake_case for environment variables
Document complex logic with inline comments

**/*.go: All comments in Go code must end with periods; enforced by golangci-lint's godot.
Organize imports into three groups (stdlib, 3rd-party, Atmos) separated by blank lines; sort alphabetically within each group; maintain existing import aliases.
Add defer perf.Track() to all public functions and critical private functions, with a blank line after the call; use package-qualified names (e.g., "exec.ProcessComponent"); pass atmosConfig if available, else nil.
Error handling: wrap errors using static errors from errors/errors.go; prefer errors.Join for multiple errors; add context with fmt.Errorf("%w", ...); use errors.Is for checks; never compare error strings or return dynamic errors directly.
Always bind environment variables with viper.BindEnv; every env var must have an ATMOS_ alternative (e.g., viper.BindEnv("ATMOS_GITHUB_TOKEN", "GITHUB_TOKEN")).
Use structured logging for system/debug info and direct UI output to stderr; never use logging for UI elements; data/results intended for piping must go to stdout.
Most text UI must go to stderr (e.g., utils.PrintfMessageToTUI or fmt.Fprintf(os.Stderr,...)); only data/results go to stdout.
Ensure cross-platform compatibility: prefer SDKs over shelling out to binaries, use filepath/os utilities, and guard OS-specific logic with build constraints or runtime.GOOS when necessary.

Files:

  • cmd/root_test.go
cmd/**/*_test.go

📄 CodeRabbit inference engine (CLAUDE.md)

Place command tests under cmd/ as *_test.go files.

Files:

  • cmd/root_test.go
🧠 Learnings (1)
📚 Learning: 2024-12-13T15:28:13.630Z
Learnt from: Listener430
PR: cloudposse/atmos#844
File: cmd/version.go:34-44
Timestamp: 2024-12-13T15:28:13.630Z
Learning: In `cmd/version.go`, when handling the `--check` flag in the `versionCmd`, avoid using `CheckForAtmosUpdateAndPrintMessage(cliConfig)` as it updates the cache timestamp, which may not be desired in this context.

Applied to files:

  • cmd/root_test.go
🧬 Code graph analysis (1)
cmd/root_test.go (2)
cmd/root.go (2)
  • RootCmd (53-153)
  • Execute (422-469)
pkg/utils/log_utils.go (1)
  • OsExit (16-16)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Build (ubuntu-latest, linux)
  • GitHub Check: Build (macos-latest, macos)
  • GitHub Check: Analyze (go)
  • GitHub Check: website-deploy-preview
  • GitHub Check: Lint (golangci)
  • GitHub Check: Summary
🔇 Additional comments (2)
cmd/root_test.go (2)

12-14: Imports look good.

The addition of the utils package and the reordering of imports properly maintain the three-group structure (stdlib, 3rd-party, Atmos) with alphabetical sorting within each group.


390-401: Resolve confusing expectations in version flag test
The version subcommand does not call OsExit, so invoking atmos version when the --version flag isn’t set won’t panic. The test’s expectation of no exit is valid.

@aknysh aknysh added no-release Do not create a new release (wait for additional code changes) and removed minor New features that do not break anything labels Oct 6, 2025
@aknysh aknysh merged commit 088e325 into main Oct 7, 2025
53 checks passed
@aknysh aknysh deleted the add-version-flag-alias branch October 7, 2025 00:35
osterman added a commit that referenced this pull request Oct 7, 2025
* Add --version flag as alias for atmos version command

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Address CodeRabbit review and update help snapshots

- Add error check for GetBool("version") flag per CodeRabbit review
- Regenerate 17 help snapshot files to include --version flag
- All help outputs now correctly show the new --version flag

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Use same code path for --version and version command

- Move --version handling to call exec.NewVersionExec().Execute()
- Both commands now produce identical rich formatted output
- Update flag description to "Alias for 'atmos version' command"
- Update test expectations for rich format output
- Regenerate help snapshots with new flag description
- Remove unused version import from root.go

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix test flag state pollution and increase coverage

- Reset --version flag state before tests to prevent pollution
- Add comprehensive TestVersionFlagParsing with multiple scenarios
- Fix TestTerraformGenerateBackendCmd by resetting flag states
- Remove unused contains() helper function
- All cmd tests now pass without cross-test interference

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Add comprehensive --version flag execution path test

- Mock utils.OsExit to test version flag execution without exiting
- Verify version handler calls os.Exit(0) when --version is set
- Test properly resets flag state to prevent pollution
- Achieves comprehensive coverage of the --version code path

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Use backticks in --version flag description

- Change description from "Alias for 'atmos version' command"
  to "Alias for \`atmos version\` command" for consistency
- Update test to match new description
- Regenerate help snapshots with updated formatting

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Address CodeRabbit review comments

- Add periods to all inline comments for godot linter compliance
- Use assert.Contains instead of assert.Equal for usage text (more robust)
- Replace defer with t.Cleanup for test cleanup
- Fix flag reset in TestTerraformGenerateBackendCmd to only reset version flag
  (VisitAll on all flags was causing test failures with complex flag types)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Expand test coverage with table-driven execution path tests

- Convert TestVersionFlagExecutionPath to table-driven test
- Add test case for version command (ensures flag check doesn't interfere)
- Add test case for --version flag (covers successful exit path)
- Improves patch coverage by testing multiple execution scenarios

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Use Visit to reset only changed flags in test cleanup

- Change VisitAll to Visit in TestTerraformGenerateBackendCmd
- Only reset flags that were actually changed, avoiding issues with complex flag types
- This addresses CodeRabbit feedback while maintaining test stability
- All cmd tests pass successfully

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Add documentation for --version persistent flag

- Document --version flag in global-flags.mdx as a core global flag
- Update version.mdx to show both 'atmos version' and 'atmos --version' usage
- Add version disambiguation warning explaining flag shows Atmos version, not tool versions
- Update cli.mdx with tip about --version flag availability
- Update commands.mdx cheatsheet to show both version command forms
- Website build verified successfully with no errors

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Clarify --version flag behavior vs atmos version command

- Update global-flags.mdx to explain --version prints minimal single-line output
- Clarify --version does not perform update checks or support --check/--format flags
- Add note directing users to 'atmos version' for richer output and additional functionality
- Update version.mdx to distinguish between the flag and command behavior
- Remove misleading "equivalent" claim that suggested identical functionality
- Website build verified successfully

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Update golden snapshots for auth command help outputs

- Add --version flag to help output snapshots for all auth subcommands
- Fixes 18 failing acceptance tests (6 commands × 3 platforms)
- Snapshots now include the new persistent --version flag

Affected snapshots:
- atmos auth validate --help
- atmos auth whoami --help
- atmos auth env --help
- atmos auth exec --help
- atmos auth login --help
- atmos auth user configure --help

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Improve --version flag help text and remove confusing default value

- Change description from "Alias for atmos version command" to "Display the Atmos CLI version"
- Set DefValue to empty string to hide "(default false)" in help output
- Update all 6 auth command golden snapshots with cleaner help text

The "(default false)" was technically correct but semantically confusing for
an action flag. Setting DefValue="" tells Cobra's help system to skip showing
the default value, which is standard practice for boolean trigger flags.

Files changed:
- cmd/root.go: Improve description and hide default value
- tests/snapshots/TestCLICommands_atmos_auth_*.stdout.golden: Update help text

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Update remaining golden snapshots for --version flag text change

- Complete the work started in commit 9cc0720 which updated only 6 auth command golden files
- Update 17 additional help command golden files with new --version flag text
- Change from "Alias for atmos version command (default false)" to "Display the Atmos CLI version"
- This matches the DefValue="" change in cmd/root.go that hides the confusing "(default false)"

Files updated:
- Main help: atmos --help
- About: atmos about --help
- Atlantis commands (6 files): atlantis --help, generate --help/help, repo-config --help/help
- Helmfile commands (5 files): helmfile --help/help, apply --help/help
- Terraform commands (5 files): terraform --help/help, apply --help/help, alias check

This resolves the CI test failures caused by mismatched golden snapshots.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix TestVersionFlagParsing assertion for updated --version flag text

- Update test assertion to check for "Atmos CLI version" instead of "atmos version"
- This matches the updated flag description from commit 9cc0720
- The new description is "Display the Atmos CLI version" which doesn't contain "atmos version" as a substring
- Test was failing on Windows CI with: "Display the Atmos CLI version" does not contain "atmos version"

This resolves the Windows CI test failure in TestVersionFlagParsing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Address CodeRabbit review feedback for cmd/root_test.go

- Fix misleading comment: clarify that state isolation is via flag reset, not creating new instance
- Remove unnecessary cmd variable alias; use RootCmd directly for clarity
- Rename test case from "version flag false does not exit" to "version subcommand bypasses flag handler"
  to accurately reflect that it tests the version subcommand, not the --version flag

These are code clarity improvements that make the test more self-documenting without changing behavior.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Andriy Knysh <aknysh@users.noreply.github.com>
@github-actions
Copy link

github-actions bot commented Oct 8, 2025

These changes were released in v1.194.0.

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

Labels

no-release Do not create a new release (wait for additional code changes) size/m Medium size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants