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
@@ -109,10 +109,7 @@ func (a *application) pullStateCommand(closing bool) *cobra.Command {
if deleteBranch {
a.deleteHead(cmd, service, item, false)
}
if a.options.json != "" {
return a.writeJSON(cmd, item)
}
return nil
return a.jsonResult(cmd, item)
}}
cmd.Flags().StringVarP(&comment, "comment", "c", "", "Leave a comment before changing the state")
cmd.ValidArgsFunction = a.completePulls(map[bool]string{true: "open", false: "closed"}[closing])
@@ -302,10 +299,7 @@ the base branch.`, Annotations: pullArgumentsAnnotation(map[string]string{"tea.c
switch {
case item.Merged:
a.warn(cmd, "Pull request %s is already merged", ref)
if a.options.json != "" {
return a.writeJSON(cmd, item)
}
return nil
return a.jsonResult(cmd, item)
case item.State == "closed":
return fmt.Errorf("pull request %s is closed; reopen it with: tea pr reopen %d", ref, n)
case item.Draft:
@@ -362,10 +356,7 @@ the base branch.`, Annotations: pullArgumentsAnnotation(map[string]string{"tea.c
a.deleteHead(cmd, service, merged, true)
}
}
if a.options.json != "" {
return a.writeJSON(cmd, merged)
}
return nil
return a.jsonResult(cmd, merged)
}}
enumFlag(cmd, &method, "method", "s", "", "Merge method (default: the repository's default merge style)", mergeMethods...)
cmd.Flags().StringVar(&method, "style", "", "Alias of --method")