feat: add --output=json to the profiles command#643
Open
fgrosse wants to merge 4 commits into
Open
Conversation
Render the profiles and groups listing as machine-readable JSON for scripting, alongside the existing plain text output: resticprofile profiles --output=json | jq '.profiles[].name' When a structured output format is requested, diagnostic log lines are routed to stderr so stdout stays valid for parsers.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #643 +/- ##
==========================================
+ Coverage 80.99% 81.33% +0.34%
==========================================
Files 162 163 +1
Lines 12113 12173 +60
==========================================
+ Hits 9810 9900 +90
+ Misses 1806 1772 -34
- Partials 497 501 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
- Refresh doc comments on parseOutputFormat and wantsStructuredOutput after the validation moved into displayProfilesCommand - Surface valid formats in the "unknown output format" error - Document the --output=json mode in the usage guide
Verify that an empty configuration still emits "profiles": [] and "groups": [] (not null), so scripts can always rely on the keys holding arrays.
fgrosse
commented
May 24, 2026
| action: displayProfilesCommand, | ||
| needConfiguration: true, | ||
| flags: map[string]string{ | ||
| "--output=<format>": "output format: plain (default) or json", |
Contributor
Author
There was a problem hiding this comment.
Note that I wanted to mirror the well-known pattern from tools such as kubectl. The existing behavior is retained with the plain output format, which remains the default.
Inline the YAML fixture into the helper and tighten the invalid-format assertion to match the full error message.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
I want to be able to retrieve all defined profiles and then run some scripts on them. Currently, I parse profile names using
resticprofile profiles | awk ..., but I would like a more flexible, robust approach that supports structured output such as JSON and pipes the result intojq.Summary
Disclaimer: The code was originally written by Claude and then I polished it myself until I was happy with the result. 🤖
--output=<format>to theprofilescommand (plaindefault,jsonavailable) so callers can pipe profile/group metadata intojqand friends.name,description,sections; each group hasname,description,profiles. Top-level object so it can grow non-breakingly later.Test plan
go test -count=1 -short .passesgolangci-lint run ./...cleanresticprofile profilesoutput is unchanged (plain text path is byte-identical)resticprofile profiles --output=json | jq '.profiles[].name'works end-to-endresticprofile profiles --output json(space form) worksresticprofile profiles --output=yamlerrors withunknown output format "yaml"resticprofile help profileslists the new flag