Repository navigation
Conversation
spydon
added this pull request to stack #4135
October 24, 2026 09:04
spydon
removed this pull request from stack #4135
October 24, 2026 10:30
spydon
added this pull request to stack #4140
October 24, 2026 10:30
spydon
force-pushed
the
feat/cli-json-output
branch
from
October 25, 2026 09:47
8eee876 to
5d83110
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Every
flame_clicommand that prints a result now takes--json, so that scripts and AI coding agents never have to parse prose. That is all of them exceptrun, which passes its arguments on toflutter run(which has--machinefor this). Before this PR onlytree,inspectandoverlayshad it.With
--jsonthe result is printed as a single JSON value on stdout. For example,snapshotprints the path, width, height, pixel ratio and byte size of the image.diffprints the differing and total pixels, the percentage, the bounds and the output path.pause,resumeandstepprint the paused state, andstepadds the frames and times.debugprints the debug mode and its target.overlay show/hide/onlyprint the overlay and its state, andinput tap/drag/keyprint what was sent.reloadandrestartprintok,messageand alloutputlines.logsprints the log path and the last lines, andcreateprints the name, path and template.devtools --jsonstartsdart devtools --machine, so its output is one JSON object per line.--jsoncannot be combined withlogs --follow.When a command called with
--jsonfails,FlameCommandRunner.runprints{"error": {"message": ..., "exitCode": ..., "kind": ...}}instead of the text message, with the same exit code as without--json. Thekindis the name of the exit code (usage,data,unavailable,software,cantCreate). The error also goes to stdout, so stdout of a--jsoncommand always holds exactly one JSON value, either the result or the error. Other output that is not the result, such as the output offlutterinflame createor the "enabled the extension" notice ofdevtools, goes to stderr in JSON mode. Arguments that fail to parse are also reported as JSON when--jsonis among them.--jsonis a per command flag rather than a global one onFlameCommandRunner. Withpackage:args, global flags have to come before the command name, so a global flag would not have supportedflame tree --jsonas it works today. The shared plumbing lives injson_output.dart:addJsonFlag, aJsonOutputmixin withjsonOutputandwriteResult(result, text), andjsonError.FlameCommandadds the flag and mixes inJsonOutputitself, so new commands that talk to the game get--jsonwithout extra work. Other commands calladdJsonFlagand mix inJsonOutput. A test checks that every command exceptrunhas the flag.FlameCommandnow also uses theGameConnectorthat is passed toFlameCommandRunner, so the game commands can be tested with a fake connection.The exit code usage was audited and was already consistent with the docs. The docs now list every exit code with its
kind, including1fromdiff --exit-code. They also have a new section about using the CLI from scripts and agents, which describes the result of every command.Changes that scripts could notice:
--jsonhelp text oftree,inspectandoverlaysis now the shared one. Their JSON output is unchanged.diff --outputno longer prints the summary before failing when the diff image cannot be written. Only the error is printed now.--jsonare unchanged.Checklist
docsand added dartdoc comments with///.examplesordocs.Breaking Change?
Related Issues
Part of #4131