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
+7
-14
@@ -317,7 +317,7 @@ $ tea issue create --title "Idea" --web`, Args: argsExact(0), RunE: func(cmd *co
|
||||
failures = append(failures, fmt.Errorf("issue %d created; attachment %s upload failed: %w", item.Number, filepath.Base(file.Name()), err))
|
||||
}
|
||||
}
|
||||
return errors.Join(append(failures, a.created(cmd, target, item))...)
|
||||
return errors.Join(append(failures, a.issueCreated(cmd, target, item))...)
|
||||
}}
|
||||
flags := cmd.Flags()
|
||||
flags.StringVarP(&title, "title", "t", "", "Issue title")
|
||||
@@ -340,13 +340,10 @@ $ tea issue create --title "Idea" --web`, Args: argsExact(0), RunE: func(cmd *co
|
||||
return cmd
|
||||
}
|
||||
|
||||
// created reports a new issue: as JSON, or its URL on stdout after a ✓ line for people.
|
||||
func (a *application) created(cmd *cobra.Command, t target, item services.Issue) error {
|
||||
if a.options.json != "" {
|
||||
return a.writeJSON(cmd, item)
|
||||
}
|
||||
// issueCreated reports a new issue: as JSON, or its URL on stdout after a ✓ line for people.
|
||||
func (a *application) issueCreated(cmd *cobra.Command, t target, item services.Issue) error {
|
||||
a.done(cmd, "Created issue %s", refLabel(t.Repo, item.Number, item.Title))
|
||||
return a.printURL(cmd, item.URL)
|
||||
return a.created(cmd, item, item.URL)
|
||||
}
|
||||
|
||||
func (a *application) createIssueInteractively(cmd *cobra.Command) (runErr error) {
|
||||
@@ -379,7 +376,7 @@ func (a *application) createIssueInteractively(cmd *cobra.Command) (runErr error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return a.created(cmd, target, item)
|
||||
return a.issueCreated(cmd, target, item)
|
||||
}
|
||||
|
||||
// issueTemplateBody seeds a body from markdown content, or from the description of form templates.
|
||||
@@ -445,12 +442,8 @@ $ tea issue %[1]s 12 13 --comment "Done in #14"`, verb), Annotations: map[string
|
||||
}
|
||||
a.done(cmd, "%s %s %s", past, discussionNoun(item.Kind), refLabel(target.Repo, n, item.Title))
|
||||
return item, nil
|
||||
}, func(services.Issue) {})
|
||||
var err2 error
|
||||
if a.options.json != "" {
|
||||
err2 = writeBatchJSON(a, cmd, len(numbers), results)
|
||||
}
|
||||
return errors.Join(append(failures, err2)...)
|
||||
}, nil)
|
||||
return errors.Join(append(failures, writeBatchJSON(a, cmd, len(numbers), results))...)
|
||||
}}
|
||||
cmd.Flags().StringVarP(&comment, "comment", "c", "", "Leave a comment before the issue is "+state)
|
||||
cmd.ValidArgsFunction = a.completeIssueArgs(completeState, true)
|
||||
|
||||
Reference in new issue
Block a user