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

+1 -12
View File
@@ -23,14 +23,6 @@ var visibilities = []string{"public", "limited", "private"}
// visibilityColors color the visibility of organizations and accounts.
var visibilityColors = map[string]string{"public": "green", "limited": "yellow", "private": "red"}
// jsonResult writes the result of a mutation when --json asks for it; people get a done line instead.
func (a *application) jsonResult(cmd *cobra.Command, item any) error {
if a.options.json == "" {
return nil
}
return a.writeJSON(cmd, item)
}
// timeField shows an API timestamp relative to now on a TTY, and as RFC3339 for scripts.
func timeField(label, raw string, d terminal.Display) terminal.Field {
t := terminal.ParseTime(raw)
@@ -250,10 +242,7 @@ $ tea org create acme-internal --visibility private`,
return err
}
a.done(cmd, "Created organization %s", org.Name)
if err := a.printURL(cmd, webURL(target, org.Name)); err != nil {
return err
}
return a.jsonResult(cmd, org)
return a.created(cmd, org, webURL(target, org.Name))
}
return cmd
}