Skip to content

Uniform --format json on every read command #12

Description

@KKranthi6881

Problem

Some read-side commands (datalex validate, datalex info, datalex diff) support --format json, but the flag isn't uniform — some commands only emit human output, and the JSON shapes vary across commands that do. This makes it harder to script DataLex into CI and other tools.

Goal

Every read-side datalex subcommand should accept --format {human,json} (default human). When --format json is passed:

  • Output is a single top-level JSON document on stdout.
  • No log/warning/banner text on stdout; route those to stderr.
  • The schema is stable and documented — document each command's JSON shape in docs/cli.md.

Suggested approach

  1. Inventory the read commands (search packages/cli/src/datalex_cli/ for add_parser / subparsers).
  2. Factor a tiny helper — emit_result(result: Any, *, format: str) — that pretty-prints or JSON-dumps.
  3. Flip each command over to the helper.
  4. Add one test per command that asserts --format json output parses and includes expected keys.

Acceptance criteria

  • datalex validate --format json → diagnostics array.
  • datalex info --format json → project summary.
  • datalex diff --format json → structured diff (reuse diff.py's internal dataclasses).
  • datalex packages list --format json → resolved-packages list.
  • No stdout contamination when --format json is active.

Why this is a good first issue

Small surface per command, easy to verify, no core engine changes. Gives you a tour of the CLI layer and forces clean separation of presentation from logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions