Skip to content

Global --json flag for machine-readable CLI output #199

Description

@krlmrr

Split from #198.

The problem

There's no stable way for another program to read Flock's state. Only flock services has --json, so a menu bar, launcher or script integration has to scrape human-readable output that can change wording at any time.

The solution you'd like

Make --json a global (persistent) flag on the root command:

  • Commands with structured output return JSON:
    • status: daemon state, each service's state, the default PHP version, and whether Xdebug and dump capture are on
    • sites: each site's URL, path, PHP version and secure flag
    • php list: installed versions, with the default marked
    • isolated, mail, dumps and version
  • services --json keeps its current shape.
  • Commands that stream or wrap another process (daemon, logs, share, debug) exit with a clear error that --json isn't supported for them, rather than ignoring the flag.
  • The CLI is shared, so this works the same on macOS, Windows and Linux. The apps and the default text output stay as they are.

I'll send the PRs: the global flag plus status, sites and php list first, then the remaining commands.

Alternatives you've considered

  • Adding --json per command: this is how services does it today, but every new command would need to remember to add it.
  • Documenting the daemon's local HTTP API: that would make a larger surface public than the CLI.

Activity

  1. added this to the v1.x milestone on Nov 22, 2026
  2. krlmrr commented on Nov 25, 2026

    @krlmrr
    Author

    The first PR is ready locally (global --json, plus status, sites and php list). A few questions before I open it, so the JSON shapes are settled before scripts start depending on them:

    1. status --json shape. Right now it prints the daemon's api.Status as-is: 21 fields, including internals like processes, capture_off, event_count and dumps_in_page. That makes all of them a public contract, which is close to the "document the daemon API" option this issue argued against. Should status get its own small shape instead (daemon state, each service's state, default PHP, whether Xdebug and dump capture are on), the way sites does?

    2. Site URLs with the daemon down. With the daemon running, sites --json URLs include non-default ports, as the daemon reports them. With it stopped, the fallback builds URLs from the config and leaves ports out (the text output already does this). The fields are the same either way, but the values change. Should the fallback include ports, or is that fine?

    3. Commands that don't support JSON yet. daemon, logs, share and debug reject --json with a clear error. Every other command without JSON output (link, isolated, …) currently ignores the flag and prints text. Should they reject it too until they get JSON output, so a script never gets text it can't parse?

    4. flock --json debug …. debug doesn't parse flags, so a leading --json shows up as its first argument. I treat that as the global flag and reject it, and flock debug --json … is rejected as well (PHP has no --json option). OK?

    5. Proxies in sites --json. Each proxy has name, url and upstream, without a separate secure field, since the URL's scheme already says it. OK?

    For reference, sites --json:

    {
      "sites": [
        { "name": "quill", "url": "https://quill.test", "path": "/home/me/Sites/quill", "php": "8.5", "secure": true }
      ],
      "proxies": []
    }

    php is left out for Node.js sites. php list --json is [{"version": "8.5", "default": true}]. services --json and conflicts --json print exactly what they did before.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions