Skip to content

Add a --json flag to the read commands (logs, calls, projects) #162

Description

@mahimairaja

Want to work on this? Comment .take and it is yours (first comment wins). When your fix is ready, open a PR with Closes #162.


Good first issue. One small, repeated change across three commands. We already use --json elsewhere in the CLI, so there is a pattern to copy.

What's going on

Three CLI commands print a nice table for humans:

  • voicegw logs
  • voicegw calls
  • voicegw projects

Tables are great to read, but you cannot pipe them into another tool. If you want this data from a script (or piped into jq), there is no machine-readable option today.

We add a --json flag to each. With the flag, the command prints raw JSON instead of the table.

What to do

Files:

  • src/voicegateway/cli/logs_cli.py
  • src/voicegateway/cli/calls_cli.py
  • src/voicegateway/cli/projects_cli.py

For each command:

  1. Add a flag option:
    as_json: bool = typer.Option(False, "--json", help="Output raw JSON instead of a table"),
  2. Right before it builds the Rich Table, bail out early if the flag is set:
    import json
    ...
    if as_json:
        print(json.dumps(rows, indent=2, default=str))
        return

logs is the easiest place to start: its rows is already a list of dicts (see logs_cli.py, lines 29-31). Do that one first, then calls the same way.

For projects there is no ready-made list, so build one from the config first:

data = [
    {"id": pid, "name": p.name, "tags": list(p.tags),
     "daily_budget": p.daily_budget, "default_stack": p.default_stack}
    for pid, p in sorted(gw.config.projects.items())
]

There is an existing --json option to copy from in src/voicegateway/cli/livekit_cli.py (line 90).

Use plain print(...) for the JSON (not the Rich console), so the output pipes cleanly with no color codes.

How to test

voicegw logs --json | jq .
voicegw calls --json | jq .
voicegw projects --json | jq .

Each should print valid JSON. Without --json, the tables should look exactly as before.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions