feat(toolchain): add --format=plain/json to atmos toolchain get - #2845
Conversation
Scripts and CI previously had to grep/regex-scrape the styled table output of `atmos toolchain get` to extract a version string. Adds a `--format` flag (table/plain/json) so `--format=plain` prints just the bare version and `--format=json` prints structured output including installed status, routed through the data channel (stdout) instead of the styled UI channel (stderr). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Tip Atmos Pro
No affected stacks workflow was detected for this pull request. |
Dependency Review✅ No vulnerabilities or license issues found.Scanned FilesNone |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthrough
ChangesToolchain get formats
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant GetCommand
participant ListToolVersions
participant VersionRenderers
GetCommand->>ListToolVersions: pass selected format
ListToolVersions->>VersionRenderers: provide resolved version data
VersionRenderers-->>ListToolVersions: render table, plain, or JSON output
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
cmd/toolchain/get_test.go (1)
84-104: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winTest the validator that
getCmdcalls.This test duplicates
getCmd.RunEvalidation logic. A change to the command can leave this test green.Extract
validateGetFormat(format, all)into production code. Call it fromgetCmd.RunE. Test that helper here.Proposed refactor
+func validateGetFormat(format string, all bool) error { + if !slices.Contains(supportedGetFormats, format) { + return fmt.Errorf("%w: %q (supported: %v)", errUtils.ErrInvalidFlagValue, format, supportedGetFormats) + } + if format == "plain" && all { + return errUtils.ErrToolchainPlainFormatWithAllFlag + } + return nil +}- v := viper.New() - v.Set("format", tt.format) - v.Set("all", tt.all) - // Mimic getCmd's RunE validation logic without invoking network/filesystem lookups. - testCmd := &cobra.Command{ ... } - err := testCmd.Execute() + err := validateGetFormat(tt.format, tt.all)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cmd/toolchain/get_test.go` around lines 84 - 104, Extract the format and all-flag validation duplicated in the test into a production helper named validateGetFormat(format, all). Update getCmd.RunE to call this helper and return its error, then revise the test to invoke validateGetFormat directly instead of recreating a Cobra command and duplicating the validation logic.Source: Coding guidelines
website/docs/cli/commands/toolchain/toolchain-get.mdx (1)
175-198: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd an example for
--format=jsoncombined with--all.The flags section states
jsonreturns the full version list with--all. Add one example here showingatmos toolchain get terraform --all --format=jsonwith its output, so readers see the all-versions JSON shape, not just the single-version shape shown at line 196.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@website/docs/cli/commands/toolchain/toolchain-get.mdx` around lines 175 - 198, Add a documentation example in the toolchain get format examples showing terraform with both --all and --format=json, including representative output that demonstrates the full all-versions JSON shape. Keep the existing single-version JSON example unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/toolchain/get.go`:
- Around line 42-47: Update ListToolVersions to validate format against the
supported table, plain, and json values before reading tool versions, returning
ErrInvalidFlagValue for unknown formats. Keep the existing plain-and-showAll
check after format validation and preserve the current rendering behavior for
supported formats.
---
Nitpick comments:
In `@cmd/toolchain/get_test.go`:
- Around line 84-104: Extract the format and all-flag validation duplicated in
the test into a production helper named validateGetFormat(format, all). Update
getCmd.RunE to call this helper and return its error, then revise the test to
invoke validateGetFormat directly instead of recreating a Cobra command and
duplicating the validation logic.
In `@website/docs/cli/commands/toolchain/toolchain-get.mdx`:
- Around line 175-198: Add a documentation example in the toolchain get format
examples showing terraform with both --all and --format=json, including
representative output that demonstrates the full all-versions JSON shape. Keep
the existing single-version JSON example unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: ec2f3378-9a77-4b37-b2aa-199adaa89ec0
📒 Files selected for processing (8)
cmd/toolchain/get.gocmd/toolchain/get_test.goerrors/errors.gopkg/toolchain/get.gopkg/toolchain/get_test.gowebsite/blog/2026-07-31-toolchain-get-plain-json-output.mdxwebsite/docs/cli/commands/toolchain/toolchain-get.mdxwebsite/src/data/roadmap.js
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2845 +/- ##
==========================================
+ Coverage 82.09% 82.11% +0.01%
==========================================
Files 1802 1802
Lines 175133 175175 +42
==========================================
+ Hits 143779 143842 +63
+ Misses 23589 23567 -22
- Partials 7765 7766 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Package-level ListToolVersions silently rendered any unrecognized format as the table view, so a direct caller bypassing the cmd-layer validation (e.g. passing "xml") got table output instead of an error. Validate against the supported table/plain/json set before dispatch. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The previous test reimplemented RunE's validation logic in a throwaway closure instead of calling getCmd.RunE itself, so the actual added lines in cmd/toolchain/get.go showed 0 coverage despite the behavior being asserted. Switch to setting flags on getCmd directly and invoking RunE, matching the pattern already used by env_test.go/ add_test.go/path_test.go in this package. Raises this patch's covered- line ratio on cmd/toolchain/get.go from ~17% to 80% (94.5% across the full patch); the remaining uncovered lines are the shell-completion closure body and its panic guard, which mirror an already-unexercised defensive pattern elsewhere in this same file. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Show the plain-format example as a conventional $ command / output pair in a single block instead of a "# 2.20.0" line, which read like a shell comment rather than the tool's actual stdout. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Tip Atmos Pro
No affected stacks workflow was detected for this pull request. |
what
--formatflag toatmos toolchain getwith three modes:table(default, unchanged),plain(bare version string only), andjson(structured output with tool/version/installed fields, or a full version list under--all).plain/jsonoutput through the data channel (stdout, pipeable) instead of the styled UI channel (stderr), via newprintVersionsPlain/printVersionsJSONhelpers inpkg/toolchain/get.go.--format=plaincombined with--allwith a newErrToolchainPlainFormatWithAllFlagsentinel, since there's no single version to print in that case.why
2>&1since it's written to stderr), e.g.atmos toolchain get vale-cli/vale 2>&1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1.--format=plaincollapses that toversion=$(atmos toolchain get vale-cli/vale --format=plain), and--format=jsongives scripts structured access to installed status without adding a new dependency.references
Summary by CodeRabbit
atmos toolchain get.--format/-f, environment-variable support, and shell completion.--alland plain output options.