microcks-cli icon indicating copy to clipboard operation
microcks-cli copied to clipboard

feat: add global output formatter support (text/json/yaml)

Open cotishq opened this issue 6 months ago • 10 comments

Description

  • Added a global --output flag to microcks test with supported values: text (default), json, and yaml.
  • Introduced a reusable output layer in pkg/output with shared formatter routing and dedicated formatters (TextFormatter, JSONFormatter, YAMLFormatter) so other commands can reuse the same pattern later.
  • Added TestResultJSON mapping structs that mirror connectors.TestResult fields (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 to stdout for automation use-cases, with progress/info logs routed to stderr.
  • Added/updated tests in pkg/output for JSON/YAML formatting and formatter factory selection.
  • Updated command docs in documentation/cmd/test.md to include the new --output flag and supported values.

Related issue(s)

Resolves #301

cotishq avatar May 12 '26 06:05 cotishq

@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

cotishq avatar May 12 '26 06:05 cotishq

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-actions as 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

cotishq avatar May 14 '26 14:05 cotishq

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-actions as 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

I won't advise this been merge as it is now. Check my other comments, the PR is not doing what's it stated

Caesarsage avatar May 14 '26 14:05 Caesarsage

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-actions as 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

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

cotishq avatar May 14 '26 15:05 cotishq

few thoughts

  1. Moving the --output flag to rootCmd.PersistentFlags() would make it truly global and match the maintainer's direction from #301
  2. The formatter interface could accept a FormatResult(result) method so all branching lives inside the formatter, not the polling loop
  3. Once this lands, happy to add github-actions format as a follow-up

Harishrs2006 avatar May 14 '26 18:05 Harishrs2006

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-actions as 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

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

cotishq avatar May 14 '26 19:05 cotishq

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-actions as 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

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 — PersistentFlags on root, clientOpts.OutputFormat plumbed through. microcks import-dir --output=json will work now
  • Abstraction leak: very nicely refactored. The outputWriter.Progressf / Infof API at the call sites reads much better than the old if isTextOutput / else branches
  • Formatter interface scope: Writer is now generic and reusable, but the Formatter interface 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.

Caesarsage avatar May 15 '26 18:05 Caesarsage

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-actions as 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

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 — PersistentFlags on root, clientOpts.OutputFormat plumbed through. microcks import-dir --output=json will work now
  • Abstraction leak: very nicely refactored. The outputWriter.Progressf / Infof API at the call sites reads much better than the old if isTextOutput / else branches
  • Formatter interface scope: Writer is now generic and reusable, but the Formatter interface 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.

addressed this too

cotishq avatar May 21 '26 15:05 cotishq

Please resolve conflicts

Vaishnav88sk avatar May 25 '26 11:05 Vaishnav88sk

Please resolve conflicts

ya resolved it

cotishq avatar May 25 '26 13:05 cotishq