mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
refactor(services): leave CLI flag and command names to the app layer
Services report ErrRunScanExhausted, ErrMaxPages and plain conflicts, and the commands add the --branch/--max-pages/--force hints. Unknown label names use the shared NotFoundError, and the repository-scoped review and team search refusal moves into tea search's own usage check. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
10 files changed
+37
-18
No files matched your search
+10
-1
@@ -182,7 +182,7 @@ $ tea label create bug -c ee0701 --force`, Args: usageArgs(cobra.MaximumNArgs(1)
|
||||
}
|
||||
item, updated, err := s.CreateUnique(cmd.Context(), existing, opts, force)
|
||||
if err != nil {
|
||||
return err
|
||||
return forceHint(err)
|
||||
}
|
||||
return a.reportLabel(cmd, s, item, updated)
|
||||
}}
|
||||
@@ -220,6 +220,14 @@ func (a *application) askLabelDetails(cmd *cobra.Command, opts *services.LabelOp
|
||||
return nil
|
||||
}
|
||||
|
||||
// forceHint points at --force when a label exists already.
|
||||
func forceHint(err error) error {
|
||||
if conflict, ok := errors.AsType[*services.ConflictError](err); ok && conflict.Reason == services.ReasonExists {
|
||||
conflict.Hint = "pass --force to update it"
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// 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 {
|
||||
verb := "Created"
|
||||
@@ -336,6 +344,7 @@ func (a *application) createLabels(cmd *cobra.Command, s services.Labels, rows [
|
||||
outcome := map[string]string{}
|
||||
results, failures := applyBatch(cmd, rows, func(row services.LabelOptions) string { return "label " + strconv.Quote(*row.Name) }, func(row services.LabelOptions) (services.Label, error) {
|
||||
item, updated, err := s.CreateUnique(cmd.Context(), existing, row, force)
|
||||
err = forceHint(err)
|
||||
switch {
|
||||
case err != nil:
|
||||
return item, err
|
||||
|
||||
Reference in new issue
Block a user