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 -12
View File
@@ -226,15 +226,12 @@ func (a *application) askLabelDetails(cmd *cobra.Command, opts *services.LabelOp
// reportLabel reports a created or updated label as JSON or with a ✓ line.
func (a *application) reportLabel(cmd *cobra.Command, s services.Labels, item services.Label, updated bool) error {
if a.options.json != "" {
return a.writeJSON(cmd, item)
}
verb := "Created"
if updated {
verb = "Updated"
}
a.done(cmd, "%s %s", verb, labelName(s, item))
return nil
return a.jsonResult(cmd, item)
}
func (a *application) labelEditCommand(scope labelScope, complete cobra.CompletionFunc) *cobra.Command {
@@ -262,11 +259,8 @@ $ tea label edit old-stuff --archived`, Annotations: map[string]string{"tea.argu
if err != nil {
return err
}
if a.options.json != "" {
return a.writeJSON(cmd, item)
}
a.done(cmd, "Edited %s", labelName(s, item))
return nil
return a.jsonResult(cmd, item)
}}
fields.register(cmd, "Rename the label")
cmd.Flags().BoolVar(&byName, "by-name", false, "Match a numeric argument as a label name rather than an ID")
@@ -359,10 +353,7 @@ func (a *application) createLabels(cmd *cobra.Command, s services.Labels, rows [
}, func(item services.Label) {
a.done(cmd, "%s %s", outcome[item.Name], labelName(s, item))
})
if a.options.json != "" {
failures = append(failures, writeBatchJSON(a, cmd, len(rows), results))
}
return errors.Join(failures...)
return errors.Join(append(failures, writeBatchJSON(a, cmd, len(rows), results))...)
}
// completeScopedLabels completes the label names of the repository or, with --org, of the