feat(app): make -json opt-in via App.JSON (v1.3.0)

App now registers -json only when App.JSON is true, so a CLI whose
commands do not use cli.Emit never advertises a flag it cannot honor.
Driven by the first real consumer (evpnc), whose commands print text
directly and are not yet converted to Emit. The example opts in
(JSON: true). Backward-additive: existing App users that want -json set
JSON: true.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-05 22:18:27 +02:00
parent 9e0a98ed07
commit 496557858d
3 changed files with 17 additions and 7 deletions
+2 -1
View File
@@ -201,9 +201,10 @@ func buildTree() *cli.Node[inventory] {
func main() {
(&cli.App[inventory]{
Name: "example",
Version: "1.1.0",
Version: "1.3.0",
Prompt: "inv> ",
Root: buildTree(),
JSON: true, // commands use cli.Emit, so advertise -json
Greeting: "golang-cli example — try: show server, ping db1, colors, '?' for help, TAB to complete",
// Local CLI: no -server flag. Connect just hands over the in-memory data,
// proving App is transport-agnostic (it never dials anything itself).