Files
coder/cli/testdata/coder_ping_--help.golden
Nick Vigilante d469763bc0 feat: add JSON output to coder ping (#30148)
`coder ping` printed per-pong lines and a summary table with no
structured output, so monitoring scripts had to parse text.

It now accepts `-o table|json` (default `table`, today's output) through
the shared CLI output formatter.
JSON is a single document at the end with each attempt (sequence, time,
latency, direct or DERP region, error) and the summary.

**Behavior change:** Additive.
Default output is unchanged.
`-o json` requires `--num` and fails early without it, because pings
otherwise continue until interrupted.
In JSON mode, the per-pong and diagnostic lines that normally go to
stdout go to stderr, so stdout contains only the JSON document.

<details>
<summary>Decisions</summary>

- One document at the end rather than streaming, because it's simpler to
parse.
- Require `--num` with `-o json`. In the default continuous mode, a
single document would leave stdout empty until Ctrl+C and hold every
pong in memory. Newline-delimited JSON per pong is a possible follow-up
if continuous machine-readable output is needed.
- Durations are reported as `*_ms` floats because `time.Duration`
doesn't marshal to a portable unit.
- Output goes through the shared `cliui.NewOutputFormatter` (table and
JSON), matching `coder speedtest`. This also adds the standard `-c,
--column` flag for the summary table.

</details>

<details>
<summary>CI note</summary>

`Storybook` failed once on 61b39ef70b inside Pixel (`build finished with
status failed`). This PR changes no frontend files; the job passed on
rerun.

`test-go-pg (ubuntu-latest)` failed on 8e6276921e in [run
38948569950](https://github.com/coder/coder/actions/runs/38948569950/job/117134059011)
on `TestChatTurnStopsAtStepLimit/Default` in `coderd/x/chatd`. This PR
doesn't touch `coderd/x/chatd`, so the failed job was re-run.

</details>

Closes [CLI-32](https://linear.app/codercom/issue/CLI-32)

_This PR was generated by Coder Agents on behalf of @nickvigilante._
2026-10-26 13:17:51 -04:00

33 lines
907 B
Plaintext

coder v0.0.0-devel
USAGE:
coder ping [flags] <workspace>
Ping a workspace
OPTIONS:
-c, --column [workspace|total|successful|min|avg|max|variance] (default: workspace,total,successful,min,avg,max,variance)
Columns to display in table output.
-n, --num int
Specifies the number of pings to perform. By default, pings will
continue until interrupted. Required with --output json.
-o, --output table|json (default: table)
Output format.
--time bool
Show the response time of each pong in local time.
-t, --timeout duration (default: 5s)
Specifies how long to wait for a ping to complete.
--utc bool
Show the response time of each pong in UTC (implies --time).
--wait duration (default: 1s)
Specifies how long to wait between pings.
———
Run `coder --help` for a list of global options.