Skip to content

feat(toolchain): add --format=plain/json to atmos toolchain get - #2845

Merged
Andriy Knysh (aknysh) merged 5 commits into
mainfrom
osterman/toolchain-get-clean-output
Aug 2, 2026
Merged

feat(toolchain): add --format=plain/json to atmos toolchain get#2845
Andriy Knysh (aknysh) merged 5 commits into
mainfrom
osterman/toolchain-get-clean-output

Conversation

@osterman

@osterman Erik Osterman (Cloud Posse) (osterman) commented Jul 31, 2026

Copy link
Copy Markdown
Member

what

  • Adds a --format flag to atmos toolchain get with three modes: table (default, unchanged), plain (bare version string only), and json (structured output with tool/version/installed fields, or a full version list under --all).
  • Routes the new plain/json output through the data channel (stdout, pipeable) instead of the styled UI channel (stderr), via new printVersionsPlain/printVersionsJSON helpers in pkg/toolchain/get.go.
  • Rejects --format=plain combined with --all with a new ErrToolchainPlainFormatWithAllFlag sentinel, since there's no single version to print in that case.
  • Adds a changelog post and links it into the toolchain roadmap milestone.

why

  • Extracting a tool's version in scripts/CI previously required regex-scraping the human-styled table output (checkmark indicator, ANSI colors, 2>&1 since 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=plain collapses that to version=$(atmos toolchain get vale-cli/vale --format=plain), and --format=json gives scripts structured access to installed status without adding a new dependency.

references

Summary by CodeRabbit

  • New Features
    • Added table, plain, and JSON output formats to atmos toolchain get.
    • Added --format/-f, environment-variable support, and shell completion.
    • Plain output provides version strings; JSON provides structured tool and installation details.
  • Bug Fixes
    • Added validation for unsupported formats and incompatible --all and plain output options.
  • Documentation
    • Updated command documentation, scripting examples, and roadmap information.

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>
@atmos-pro

atmos-pro Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Tip

Atmos Pro  

No affected stacks workflow was detected for this pull request.
If this is expected, no action is needed.
Learn More. Ask AI.

@osterman Erik Osterman (Cloud Posse) (osterman) added the minor New features that do not break anything label Jul 31, 2026
@github-actions github-actions Bot added the size/m Medium size PR label Jul 31, 2026
@github-actions

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues found.

Scanned Files

None

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: db641ffa-aaff-46ff-b69e-4ae5f9b2133b

📥 Commits

Reviewing files that changed from the base of the PR and between 2035f24 and db5f793.

📒 Files selected for processing (2)
  • errors/errors.go
  • website/src/data/roadmap.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • website/src/data/roadmap.js
  • errors/errors.go

📝 Walkthrough

Walkthrough

atmos toolchain get now supports validated table, plain, and json output. The command supports flag, environment-variable, and shell-completion configuration. The toolchain package serializes single-version and all-version results. Tests and documentation cover the behavior.

Changes

Toolchain get formats

Layer / File(s) Summary
Format flag and validation
cmd/toolchain/get.go, errors/errors.go
The command adds --format/-f, environment-variable binding, shell completion, format validation, and an error for plain with --all.
Version output serialization
pkg/toolchain/get.go
ListToolVersions supports table, plain, and JSON output for single-version and all-version results.
Output behavior tests
pkg/toolchain/get_test.go
Tests verify plain and JSON output, installed-version metadata, result limits, and invalid format combinations.
Command validation tests
cmd/toolchain/get_test.go
Tests verify the format flag, supported values, invalid and empty values, and the plain with --all restriction.
Format documentation and roadmap
website/docs/cli/commands/toolchain/toolchain-get.mdx, website/blog/2026-07-31-toolchain-get-plain-json-output.mdx, website/src/data/roadmap.js
Documentation and roadmap entries describe the formats, examples, environment variable, and format restrictions.

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
Loading

Suggested reviewers: aknysh

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the new plain and JSON format options for atmos toolchain get.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch osterman/toolchain-get-clean-output

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
cmd/toolchain/get_test.go (1)

84-104: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Test the validator that getCmd calls.

This test duplicates getCmd.RunE validation logic. A change to the command can leave this test green.

Extract validateGetFormat(format, all) into production code. Call it from getCmd.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 win

Add an example for --format=json combined with --all.

The flags section states json returns the full version list with --all. Add one example here showing atmos toolchain get terraform --all --format=json with 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

📥 Commits

Reviewing files that changed from the base of the PR and between 4706634 and 74cc3e2.

📒 Files selected for processing (8)
  • cmd/toolchain/get.go
  • cmd/toolchain/get_test.go
  • errors/errors.go
  • pkg/toolchain/get.go
  • pkg/toolchain/get_test.go
  • website/blog/2026-07-31-toolchain-get-plain-json-output.mdx
  • website/docs/cli/commands/toolchain/toolchain-get.mdx
  • website/src/data/roadmap.js

Comment thread pkg/toolchain/get.go
@codecov

codecov Bot commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.11%. Comparing base (f777b18) to head (db5f793).

Files with missing lines Patch % Lines
cmd/toolchain/get.go 66.66% 3 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            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     
Flag Coverage Δ
unittests 82.11% <91.66%> (+0.01%) ⬆️

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

Files with missing lines Coverage Δ
errors/errors.go 100.00% <ø> (ø)
pkg/toolchain/get.go 90.07% <100.00%> (+7.07%) ⬆️
cmd/toolchain/get.go 76.74% <66.66%> (+14.24%) ⬆️

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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>
coderabbitai[bot]
coderabbitai Bot previously approved these changes Aug 1, 2026
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>
coderabbitai[bot]
coderabbitai Bot previously approved these changes Aug 1, 2026
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>
@aknysh
Andriy Knysh (aknysh) merged commit f35e9f5 into main Aug 2, 2026
82 checks passed
@aknysh
Andriy Knysh (aknysh) deleted the osterman/toolchain-get-clean-output branch August 2, 2026 03:20
@atmos-pro

atmos-pro Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Tip

Atmos Pro  

No affected stacks workflow was detected for this pull request.
If this is expected, no action is needed.
Learn More. Ask AI.

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

Labels

minor New features that do not break anything size/m Medium size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants