You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(cli): add unified --format=json output to commands - #314
Adds a unified machine-readable output mode so scripts, CI and AI agents can parse MageForge commands reliably.
New shared --format=table|json option (and --json shortcut) in AbstractCommand (addFormatOption(), writeJson(), isJsonOutput()).
Wired into theme:list, theme:info, theme:build, template:obsolete, dependencies:update, hyva:compatibility:check, system:version and system:check.
theme:info --json and template:obsolete --format=json keep their existing output; they now use the shared helper.
In JSON mode stdout contains only the JSON document, progress and messages go to stderr, prompts and spinners are disabled, and failures write {"error": "..."} with a non-zero exit code.
Invalid --format values fail with an error.
JSON structures are documented in docs/commands_reference.md.
Testing
Unit tests for the shared behaviour (stdout/stderr separation, error documents, invalid format) and for each command's JSON output.
ddev phpunit, ddev phpcs, ddev mago lint|fmt --check|analyze are clean. PHPStan (level 9) shows no new findings in the changed code.
Add a shared --format=table|json option (plus --json shortcut) to AbstractCommand and
use it in theme:list, theme:info, theme:build, template:obsolete, dependencies:update,
hyva:compatibility:check, system:version and system:check.
In JSON mode stdout only carries the JSON document; progress and messages go to stderr,
prompts are disabled and failures write {"error": "..."} with a non-zero exit code.
Refs #307
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unmatched wildcard builds omit the requested JSON output, and the JSON shortcut bypasses format validation, allowing invalid invocations to execute commands.
- Validate the --format value before applying the --json shortcut so that
--format=xml --json is rejected instead of executing the command.
- theme:build and dependencies:update write an empty JSON result when a
wildcard matches no theme, keeping the no-op success exit code.
- Return a list from the obsolete override serialiser to satisfy mago analyze.
Refs #307
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The command reference incorrectly implies that all non-zero exits include an error key, which could cause CI consumers to mishandle unsuccessful commands that retain normal result documents.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Distinguish execution errors from unsuccessful result documents
docs/commands_reference.md:31
Several commands return a non-zero exit code while retaining their normal result document: build/update failures, critical compatibility findings, and template:obsolete --fail-on-found. Since writeJsonError() deliberately preserves an already-written document, these responses have no error key. Please distinguish execution-error documents from unsuccessful result documents so CI consumers do not rely on an incorrect failure schema.
- Assert exact JSON documents, error messages, stderr separation, unicode
handling and success/failure exit codes in the JSON output tests.
- Move duration rounding into AbstractCommand::roundSeconds() so it can be
tested deterministically.
- Remove equivalent mutants: drop the redundant jsonOutput reset, the
nullable stdout, the redundant failedCount check and the 0 initialiser for
the Tailwind CSS v4 error count.
Refs #307
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because the documented non-zero-exit contract can mislead agents when failed commands retain result reports instead of returning an error object.
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
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.
Summary
Adds a unified machine-readable output mode so scripts, CI and AI agents can parse MageForge commands reliably.
--format=table|jsonoption (and--jsonshortcut) inAbstractCommand(addFormatOption(),writeJson(),isJsonOutput()).theme:list,theme:info,theme:build,template:obsolete,dependencies:update,hyva:compatibility:check,system:versionandsystem:check.theme:info --jsonandtemplate:obsolete --format=jsonkeep their existing output; they now use the shared helper.{"error": "..."}with a non-zero exit code.--formatvalues fail with an error.docs/commands_reference.md.Testing
ddev phpunit,ddev phpcs,ddev mago lint|fmt --check|analyzeare clean. PHPStan (level 9) shows no new findings in the changed code.Closes #307
Refs #306