mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
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:
32 files changed
+87
-217
No files matched your search
@@ -274,11 +274,8 @@ $ tea milestone create --title v2.0 --editor`, Args: usageArgs(cobra.MaximumNArg
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if a.options.json != "" {
|
||||
return a.writeJSON(cmd, item)
|
||||
}
|
||||
a.done(cmd, "Created %s", milestoneName(t, item))
|
||||
return a.printURL(cmd, milestoneURL(t, item))
|
||||
return a.created(cmd, item, milestoneURL(t, item))
|
||||
}}
|
||||
fields.register(cmd)
|
||||
enumFlag(cmd, &state, "state", "", "open", "State of the new milestone", "open", "closed")
|
||||
@@ -338,11 +335,8 @@ $ tea milestone edit 3 --editor`, Annotations: map[string]string{"tea.arguments"
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if a.options.json != "" {
|
||||
return a.writeJSON(cmd, item)
|
||||
}
|
||||
a.done(cmd, "Edited %s", milestoneName(t, item))
|
||||
return nil
|
||||
return a.jsonResult(cmd, item)
|
||||
}}
|
||||
fields.register(cmd)
|
||||
cmd.Flags().BoolVar(&byName, "by-name", false, "Match a numeric argument as a milestone title rather than an ID")
|
||||
@@ -369,11 +363,8 @@ $ tea milestone delete 7 --yes`, Annotations: map[string]string{"tea.confirm": "
|
||||
if err := s.Delete(cmd.Context(), item.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
if a.options.json != "" {
|
||||
return a.writeJSON(cmd, item)
|
||||
}
|
||||
a.done(cmd, "Deleted milestone %q from %s", item.Title, t.Repo)
|
||||
return nil
|
||||
return a.jsonResult(cmd, item)
|
||||
}}
|
||||
cmd.Flags().BoolVar(&byName, "by-name", false, "Match a numeric argument as a milestone title rather than an ID")
|
||||
cmd.ValidArgsFunction = a.completeMilestoneArgs(false)
|
||||
|
||||
Reference in new issue
Block a user