Add --json output to read commands - #77
Conversation
Add a --json flag to the read/query commands (list, info, list-ssh-keys, version) so agents and scripts can consume untruncated, structured output instead of the formatted tables. The default table rendering is unchanged. Shared serialization (emit_json) and field extraction are centralized: build_droplet_detail reuses build_droplet_record for the info command, and the same helper is used across commands rather than duplicated. Missing values are emitted as null rather than placeholder strings so consumers can branch on them. JSON mode suppresses decorative status lines. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Automated review —
|
ret2libc
left a comment
There was a problem hiding this comment.
The JSON error contract needs one more pass before approval. list --json, info --json, and list-ssh-keys --json all call load_config_and_api(), which still writes missing/invalid config errors to stdout and raises typer.Exit before these commands reach emit_error(). I reproduced this with an empty home directory: dropkit list --json exits 1, writes Error: Config not found. Run 'dropkit init' first. to stdout, and writes nothing to stderr. This breaks the documented clean-stdout/JSON-stderr behavior. info --json also reaches find_user_droplet(), whose username/listing API error branches still print plain text to stdout. Please route these helper failures through the JSON error path in JSON mode and cover them with CLI tests.
I ran the full suite on the PR head: 308 passed.
|
Thanks for the reproduction. I updated I also moved the existing list table rendering back to its original path to keep the diff focused. Validation passed: 441 pytest tests, |
ret2libc
left a comment
There was a problem hiding this comment.
Re-reviewed the latest head. The JSON error paths and output contract are addressed; no remaining relevant findings. Verified with 441 passing tests locally.
Adds a
--jsonflag to the read/query commands so agents and scripts can consume untruncated, structured output instead of the formatted tables. Default table rendering is unchanged.Commands
list --json— droplets (id, name, status, ip, tailscale_ip, region, size, cost_monthly, in_ssh_config, ssh_hostname, tags),hibernated,total_monthly_costinfo --json— the list fields plus created_at, vcpus, memory_mb, disk_gb, transfer_tb, image, features, full networks (incl. IPv6)list-ssh-keys --json— username and ssh_keys (name/id/fingerprint)version --json— version stringNotes
emit_json()and field-extraction builders are centralized;build_droplet_detailreusesbuild_droplet_recordrather than duplicating extraction.null, not placeholder strings.--json+ non-interactive--yesfor the mutating commands.Tests
New
tests/test_list.pyandtests/test_json_output.pycover the builders and all four commands. Full suite: 291 passed; coverage 30.61%. (The 12test_rename.pyfailures are pre-existing onmain, unrelated to this change.)🤖 Generated with Claude Code