Skip to content

Add --format flag support to rt commands#3456

Open
ehl-jf wants to merge 21 commits intomasterfrom
JGC-478-format-flag
Open

Add --format flag support to rt commands#3456
ehl-jf wants to merge 21 commits intomasterfrom
JGC-478-format-flag

Conversation

@ehl-jf
Copy link
Copy Markdown
Contributor

@ehl-jf ehl-jf commented Apr 28, 2026

  • All tests have passed. If this feature is not already covered by the tests, new tests have been added.
  • The pull request is targeting the master branch.
  • The code has been validated to compile successfully by running go vet ./....
  • The code has been formatted properly using go fmt ./....

Adds `--format table|json` to `jf access-token-create`. Default is
`json` for backward compatibility. Table mode renders a two-column
tabwriter output with access_token truncated to 40 chars. Includes
unit tests covering both formats, truncation, absent-field omission,
unsupported-format error, and default/explicit format resolution.

Also adds a general `Format` StringFlag entry and restores the
Xray-specific flag as `XrFormat` in commandsflags.go.
Adds `--format table|json` to `jf exchange-oidc-token`. Default is
`json` for backward compatibility (the command always emitted JSON via
PrintResponseToConsole). Table mode renders access_token (truncated to
40 chars), username, issued_token_type, scope, and token_type using
tabwriter. Works directly with the full OidcTokenResponseData struct
rather than the narrower ExchangeCommandOutputStruct, exposing all
response fields. Includes 9 unit tests covering both formats,
truncation, absent-field omission, unsupported-format error, and
default/explicit format resolution.
jf mc license-acquire: refactors LicenseAcquire() in jfrog-cli-core to
return the key string instead of printing it; CLI adds --format table|json
(default table) outputting a labeled tabwriter row or {"license_key":"..."}.

jf pl status: adds suppressOutput/Response() to StatusCommand in
jfrog-cli-core; when --format is set the command's internal colored output
is suppressed and the CLI formats the full PipelineRunStatusResponse —
table renders pipeline/branch/run/status/duration columns skipping unrun
pipelines, json emits the complete response struct.

7 tests for license-acquire, 9 tests for pl status — all 16 pass.
Adds utils/cliutils/httpformat.go with FormatHTTPResponseJSON(body, statusCode):
- If body is valid JSON, prints it indented.
- Otherwise prints {"status_code": N, "message": "..."} — using the body
  text as message when non-empty, or the HTTP status phrase when nil.

Applies the helper to jf pl trigger (--format json):
- jfrog-client-go discards the trigger response body, so nil is passed;
  on success (error == nil guarantees HTTP 200) the helper synthesises
  {"status_code": 200, "message": "OK"}.
- When the body IS available in future callers, the same helper will
  transparently surface the real JSON response.

4 unit tests cover: valid JSON passthrough, nil body fallback,
plain-text body fallback, and corrupt JSON fallback.
…igger (report)

pl sync (Pattern B): --format json emits {"status_code":200,"message":"OK"};
no table format as the client layer discards the response body.

pl sync-status (Pattern A): default table shows branch/status/is_syncing/
started/ended/commit_sha columns; --format json marshals full
[]PipelineSyncStatus. Requires SyncStatusCommand.SetSuppressOutput in core.

pl trigger report corrected: was already implemented in previous commit
(987c57db) but report still showed it as not done.
Both commands' core functions refactored to return ([]byte, error) instead
of printing internally. Default format is json (backward-compatible). Table
format uses generic map rendering for the unknown response schema, with
preferred key ordering.
Both commands are Pattern B: the client layer discards the response body.
--format json emits {"status_code":200,"message":"OK"}; table is rejected
with an error. Wrapper functions in plugins/cli.go handle the format guard
so the existing commands.InstallCmd and PublishCmd are unchanged.
The name = "name" constant in the Pipelines flags block was never
referenced in any flag slice, causing a recurring unused-const diagnostic.
Reads local config directly via config.GetAllServersConfigs / GetSpecificConfig.
--format table renders a FIELD/VALUE tabwriter table per server, omitting empty
fields and masking sensitive values as ***.  --format json marshals the sanitized
[]*ServerDetails slice. When no --format is set, delegates to commands.ShowConfig
unchanged for full backward compatibility.
jf worker list now supports --format (json, table; default: table).
The old --json flag has been removed. Updates summary counts and
adds a Priority Summary strikethrough entry.
…ls.GetOutputFormat

Remove 8 identical getXxxOutputFormat functions across config, general/token,
missioncontrol, and pipelines packages. All callers now use
commonCliUtils.GetOutputFormat from jfrog-cli-core/v2/common/cliutils.
@ehl-jf ehl-jf force-pushed the JGC-478-format-flag branch from 2d65caf to 6395942 Compare April 28, 2026 14:48
Comment thread go.mod Outdated

// replace github.com/jfrog/build-info-go => github.com/reshmifrog/build-info-go v1.8.9-0.20260106113011-c7f131cea484

replace github.com/jfrog/jfrog-cli-artifactory => github.com/ehl-jf/jfrog-cli-artifactory v0.0.0-20260428143325-08b067cf4746
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we change the dependency to the one from jfrog repo before merge?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

definitely

@ehl-jf ehl-jf force-pushed the JGC-471-format-support branch 7 times, most recently from 83d204e to 25b9864 Compare April 30, 2026 13:00
@ehl-jf ehl-jf force-pushed the JGC-471-format-support branch 2 times, most recently from fe21cb8 to 5af9d26 Compare April 30, 2026 14:26
Base automatically changed from JGC-471-format-support to master April 30, 2026 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants