feat: add global output formatter support (text/json/yaml)
Description
- Added a global
--outputflag tomicrocks testwith supported values:text(default),json, andyaml. - Introduced a reusable output layer in
pkg/outputwith shared formatter routing and dedicated formatters (TextFormatter, JSONFormatter, YAMLFormatter) so other commands can reuse the same pattern later. - Added
TestResultJSONmapping structs that mirrorconnectors.TestResultfields (including nested test case/step fields) and used them for structured JSON/YAML serialization. - Updated test command execution flow to route by --output format while preserving existing default text behavior and existing exit code semantics.
- Ensured structured outputs
(json/yaml)are emitted tostdoutfor automation use-cases, with progress/info logs routed tostderr. - Added/updated tests in pkg/output for JSON/YAML formatting and formatter factory selection.
- Updated command docs in
documentation/cmd/test.mdto include the new--outputflag and supported values.
Related issue(s)
Resolves #301
@Harsh4902 so i raised this pr as you stated, a global --output flag with json, yaml and text format initially, would love your on this, if changes should be make, happy to iterate
Nice shape overall, left a few comment you could check out
Also worth noting per the #301 discussion, this PR and #339 were meant to unify under one flag with
github-actionsas a value. That coordination still hasn't landed
i stated there that , it could be good if this pr gets merged and then we apply github-actions as a value, for a clean repo state. Also thanks for the comments , i'll address all of them
Nice shape overall, left a few comment you could check out Also worth noting per the #301 discussion, this PR and #339 were meant to unify under one flag with
github-actionsas a value. That coordination still hasn't landedi stated there that , it could be good if this pr gets merged and then we apply github-actions as a value, for a clean repo state. Also thanks for the comments , i'll address all of them
I won't advise this been merge as it is now. Check my other comments, the PR is not doing what's it stated
Nice shape overall, left a few comment you could check out Also worth noting per the #301 discussion, this PR and #339 were meant to unify under one flag with
github-actionsas a value. That coordination still hasn't landedi stated there that , it could be good if this pr gets merged and then we apply github-actions as a value, for a clean repo state. Also thanks for the comments , i'll address all of them
I won't advise this been merge as it is now. Check my other comments, the PR is not doing what's it stated
ya so i will address all the changes you have commented first, the PR is intended to solve the issue, but yeah your comments are worth addressing and i will come up with the valid changes
few thoughts
- Moving the --output flag to rootCmd.PersistentFlags() would make it truly global and match the maintainer's direction from #301
- The formatter interface could accept a FormatResult(result) method so all branching lives inside the formatter, not the polling loop
- Once this lands, happy to add github-actions format as a follow-up
Nice shape overall, left a few comment you could check out Also worth noting per the #301 discussion, this PR and #339 were meant to unify under one flag with
github-actionsas a value. That coordination still hasn't landedi stated there that , it could be good if this pr gets merged and then we apply github-actions as a value, for a clean repo state. Also thanks for the comments , i'll address all of them
I won't advise this been merge as it is now. Check my other comments, the PR is not doing what's it stated
i have updated the pr as you stated, i think its good now
Nice shape overall, left a few comment you could check out Also worth noting per the #301 discussion, this PR and #339 were meant to unify under one flag with
github-actionsas a value. That coordination still hasn't landedi stated there that , it could be good if this pr gets merged and then we apply github-actions as a value, for a clean repo state. Also thanks for the comments , i'll address all of them
I won't advise this been merge as it is now. Check my other comments, the PR is not doing what's it stated
i have updated the pr as you stated, i think its good now
yes, I agress we are close,
- Global flag: cleanly addressed —
PersistentFlagson root,clientOpts.OutputFormatplumbed through.microcks import-dir --output=jsonwill work now - Abstraction leak: very nicely refactored. The
outputWriter.Progressf/InfofAPI at the call sites reads much better than the oldif isTextOutput / elsebranches - Formatter interface scope:
Writeris now generic and reusable, but theFormatterinterface itself is still test-specific. If you want to keep that split (Writer = reusable, Formatter = test-only), worth adjusting the PR body to reflect that scope, right now it still implies the formatters themselves are reusable across commands.
A small nit on the new code:
Writer.Infof and Writer.Progressf are functionally identical right now — both just fmt.Fprintf(w.out, ...) to the same writer chosen at construction. If the intent was to differentiate, Progressf should probably go to stderr unconditionally so microcks test --output=json > result.json still surfaces progress on the terminal. Otherwise drop one of them.
Nice shape overall, left a few comment you could check out Also worth noting per the #301 discussion, this PR and #339 were meant to unify under one flag with
github-actionsas a value. That coordination still hasn't landedi stated there that , it could be good if this pr gets merged and then we apply github-actions as a value, for a clean repo state. Also thanks for the comments , i'll address all of them
I won't advise this been merge as it is now. Check my other comments, the PR is not doing what's it stated
i have updated the pr as you stated, i think its good now
yes, I agress we are close,
- Global flag: cleanly addressed —
PersistentFlagson root,clientOpts.OutputFormatplumbed through.microcks import-dir --output=jsonwill work now- Abstraction leak: very nicely refactored. The
outputWriter.Progressf/InfofAPI at the call sites reads much better than the oldif isTextOutput / elsebranches- Formatter interface scope:
Writeris now generic and reusable, but theFormatterinterface itself is still test-specific. If you want to keep that split (Writer = reusable, Formatter = test-only), worth adjusting the PR body to reflect that scope, right now it still implies the formatters themselves are reusable across commands.A small nit on the new code:
Writer.InfofandWriter.Progressfare functionally identical right now — both justfmt.Fprintf(w.out, ...)to the same writer chosen at construction. If the intent was to differentiate,Progressfshould probably go to stderr unconditionally somicrocks test --output=json > result.jsonstill surfaces progress on the terminal. Otherwise drop one of them.
addressed this too
Please resolve conflicts
Please resolve conflicts
ya resolved it