mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
refactor(prompts): fold Asker into Prompter and share delete confirmations
FormPrompter is the only production prompter and implements the rich prompt API, so Ask, AskText and ConfirmDefault become the Prompter interface and the plain Input/Confirm fallbacks go away. Confirmations that default to no derive their non-terminal wording from the prompt, and single deletes share deleteConfirmed for the prompt, the request and the done line. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
31 files changed
+131
-253
No files matched your search
@@ -196,12 +196,8 @@ $ tea label create bug -c ee0701 --force`, Args: usageArgs(cobra.MaximumNArgs(1)
|
||||
|
||||
// askLabelDetails asks for the optional color and description of a label whose name was prompted.
|
||||
func (a *application) askLabelDetails(cmd *cobra.Command, opts *services.LabelOptions) error {
|
||||
asker, ok := a.deps.Prompter.(terminal.Asker)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
if opts.Color == nil {
|
||||
color, err := asker.Ask(cmd.Context(), "Color (hex, e.g. d73a4a; empty = random):", func(s string) error {
|
||||
color, err := a.deps.Prompter.Ask(cmd.Context(), "Color (hex, e.g. d73a4a; empty = random):", func(s string) error {
|
||||
if s != "" && !labelColor.MatchString(strings.TrimPrefix(s, "#")) {
|
||||
return errors.New("use six hexadecimal digits")
|
||||
}
|
||||
@@ -215,7 +211,7 @@ func (a *application) askLabelDetails(cmd *cobra.Command, opts *services.LabelOp
|
||||
}
|
||||
}
|
||||
if opts.Description == nil {
|
||||
description, err := asker.Ask(cmd.Context(), "Description (optional):", nil)
|
||||
description, err := a.deps.Prompter.Ask(cmd.Context(), "Description (optional):", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -288,7 +284,7 @@ $ tea label delete wontfix duplicate --yes`, Annotations: map[string]string{"tea
|
||||
if len(found) > 1 {
|
||||
subject = fmt.Sprintf("%d labels (%s)", len(found), strings.Join(names, ", "))
|
||||
}
|
||||
if err := a.confirmAction(cmd, terminal.Confirmation{Prompt: "Delete " + subject + " from " + s.Scope() + "?", NonTTY: "delete " + subject + " from " + s.Scope()}); err != nil {
|
||||
if err := a.confirmAction(cmd, terminal.Confirmation{Prompt: "Delete " + subject + " from " + s.Scope() + "?"}); err != nil {
|
||||
return err
|
||||
}
|
||||
return batchDone(a, cmd, found, func(item services.Label) string { return "label " + strconv.Quote(item.Name) }, func(item services.Label) (services.Label, error) {
|
||||
|
||||
Reference in new issue
Block a user