Skip to content

CLI: Add "--json" as an additional output format to show commands #5220

Description

@lastzero

As an operator, developer, or CI automation user, I want consistent machine‑readable JSON output for all photoprism show … CLI commands so I can script checks, integrate with tooling, and validate configurations without parsing human‑formatted tables.

Implemented Changes

  • JSON format support across all “show” commands
    • Flag: --json, -j (part of shared report.CliFlags).
    • Renderer: pkg/txt/report supports Format(JSON) and renders tables as JSON.
  • JSON shape and keys
    • Single-table commands (file-formats, thumb-sizes, video-sizes, sources, search-filters) return a top-level array of row objects.
    • Keys derive from column names using snake_case (spaces/dashes → “_”, lowercase, punctuation removed).
    • Multi-section and special cases:
      • show config → { "sections": [{ "title", "items": [ {...} ] }, ...] } (unchanged).
      • show config-options → top-level array (flattened across sections).
      • show config-yaml → top-level array (flattened across sections).
      • show metadata → { "items": [ {...} ], "docs": [ {...} ] } (docs omitted when --short).
    • All values are strings (parity with CSV/TSV for stable tooling).
  • Flag conflict validation
    • Exactly one of --json | --md | --csv | --tsv; conflicts return cli.Exit with code 2.
  • Markdown output preserved for docs
    • show config-options --md and show config-yaml --md render section headings + tables for docs ingestion.
  • Help text and descriptions
    • report.CliFlags usage strings clarified (“print machine‑readable …”).
    • Command descriptions for show config-options and show config-yaml note that text/Markdown is sectioned while JSON/CSV/TSV are flat lists.
  • Plus/Pro builds
    • Commands that use report.CliFlags inherit --json automatically; config-options/config-yaml JSON is flat there as well.

Note: JSON output for the photoprism show config-options and photoprism show config-yaml commands is a flat, top-level array, unlike the standard and Markdown-formatted outputs.

How To Use

  • Examples
    • photoprism show sources --json | jq '.[0]'
    • photoprism show thumb-sizes --json | jq '.[0] | {name, width, height}'
    • photoprism show file-formats --json | jq 'map({format, type, extensions}) | .[0]'
    • photoprism show config --json | jq '.sections[0].items[0]' # still sectioned
    • photoprism show config-options --json | jq '.[0]' # now flat array
    • photoprism show config-yaml --json | jq '.[0]' # now flat array
    • photoprism show metadata --json | jq '{items: (.items|length), docs: (.docs//[])|length}'
    • photoprism show metadata --json --short | jq 'keys' # docs omitted
  • Flag conflict check
    • photoprism show sources --json --csv; echo $? # expect exit code 2

Manual Test Checklist

  • Single-table commands emit a JSON array of objects
    • Keys are snake_case, values are strings; sample keys match column intent (source, priority, description, …).
  • Multi-section and special cases
    • show config → sections[].title present; sections[].items is an array of objects.
    • show config-options → top-level array (no sections).
    • show config-yaml → top-level array (no sections).
    • show metadata → items present; docs present unless --short is set.
  • Markdown for docs remains sectioned
    • photoprism show config-options --md includes “### Authentication” and a valid Markdown table.
    • photoprism show config-yaml --md includes per-section headings and tables.
  • CSV/TSV behave unchanged (single table, delimited).
  • Plus/Pro (if available locally) accept --json and produce valid JSON; config-options/config-yaml are flat arrays there, too.

Acceptance Criteria

  • --json output is available and valid JSON for all photoprism show … commands.
  • Keys are canonicalized snake_case; values are strings.
  • Conflicting format flags return cli.Exit with code 2.
  • Markdown for config-options/config-yaml remains sectioned for docs ingestion.
  • No regressions in CSV/TSV/default output.
  • Plus/Pro CLIs using report.CliFlags accept --json and render valid JSON; config-options/config-yaml are flat.

Notes

  • Code: pkg/txt/report/* (JSON renderer, key canonicalization); internal/commands/show_*.go (CliFormatStrict; JSON assembly where needed).
  • CLI help updated to clarify sectioned text/Markdown vs flat machine formats.
  • Docs/specs updated (as of 2025-09-21) to reflect JSON shapes and Markdown docs integration.

Activity

  1. self-assigned this
    on Sep 21, 2025
  2. added
    cliCommand-Line Interface (CLI)
    configGlobal Configuration, CLI Flags, and Environment Variables
    on Sep 21, 2025
  3. added theissue type on Sep 21, 2025
  4. moved this to Development 🐝 in Roadmap 🚀✨on Sep 21, 2025
  5. moved this from Development 🐝 to Preview 🐳 in Roadmap 🚀✨on Sep 21, 2025
  6. added
    testedChanges have been tested successfully
    and removed
    please-testReady for manual testing & feedback
    on Oct 13, 2025
  7. moved this from Preview 🐳 to Release 🌈 in Roadmap 🚀✨on Dec 1, 2025
  8. added
    releasedAvailable in a stable release
    and removed
    testedChanges have been tested successfully
    on Dec 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

cliCommand-Line Interface (CLI)configGlobal Configuration, CLI Flags, and Environment VariablesreleasedAvailable in a stable release

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions