refactor(output): share the JSON, created-resource and batch tails

Mutations end with a.jsonResult or a.created instead of hand-rolled
--json branches, the two identical jsonResult/writeMutationJSON helpers
become one, and writeBatchJSON checks --json itself so batch commands
share one tail.

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-12 10:43:46 +02:00
1 parent 27e39ec4be
commit 6b204a34c0
32 files changed
+87 -217

No files matched your search

+3 -11
View File
@@ -300,12 +300,7 @@ $ tea release create v1.1.0-rc1 --target release/1.1 --draft --prerelease --titl
item.Assets = append(item.Assets, asset)
a.done(cmd, "Uploaded %s (%s)", asset.Name, terminal.Bytes(asset.Size))
}
if a.options.json != "" {
failures = append(failures, a.writeJSON(cmd, item))
} else {
failures = append(failures, a.printURL(cmd, item.URL))
}
return errors.Join(failures...)
return errors.Join(append(failures, a.created(cmd, item, item.URL))...)
},
}
fields.register(a, command)
@@ -402,11 +397,8 @@ func (a *application) releasePublishCommand() *cobra.Command {
a.done(cmd, "Published release %s in %s", item.Tag, target.Repo)
}
return item, err
}, func(services.Release) {})
if a.options.json != "" {
failures = append(failures, writeBatchJSON(a, cmd, len(args), results))
}
return errors.Join(failures...)
}, nil)
return errors.Join(append(failures, writeBatchJSON(a, cmd, len(args), results))...)
},
}
command.ValidArgsFunction = a.completeReleases()