mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11: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
@@ -119,11 +119,7 @@ func (a *application) promptComment(cmd *cobra.Command, initial string) (string,
|
||||
draft, err := a.editDraft(cmd, initial)
|
||||
return draft.Body, draft, err
|
||||
}
|
||||
if asker, ok := a.deps.Prompter.(terminal.Asker); ok {
|
||||
body, err := asker.AskText(cmd.Context(), commentTitle, initial)
|
||||
return body, terminal.Draft{}, err
|
||||
}
|
||||
body, err := a.deps.Prompter.Input(cmd.Context(), commentTitle)
|
||||
body, err := a.deps.Prompter.AskText(cmd.Context(), commentTitle, initial)
|
||||
return body, terminal.Draft{}, err
|
||||
}
|
||||
|
||||
@@ -189,14 +185,9 @@ func (a *application) editComment(cmd *cobra.Command, t target, comment services
|
||||
// deleteComment deletes comment after a confirmation that defaults to no.
|
||||
func (a *application) deleteComment(cmd *cobra.Command, t target, comment services.Comment) error {
|
||||
name := commentName(t, comment)
|
||||
if err := a.confirmAction(cmd, terminal.Confirmation{Prompt: "Delete " + name + "?", NonTTY: "delete " + name}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := (services.Comments{Client: t.client, Repository: t.Repo}).Delete(cmd.Context(), comment.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
a.done(cmd, "Deleted %s", name)
|
||||
return nil
|
||||
return a.deleteConfirmed(cmd, name, func() error {
|
||||
return (services.Comments{Client: t.client, Repository: t.Repo}).Delete(cmd.Context(), comment.ID)
|
||||
})
|
||||
}
|
||||
|
||||
// commentView shows one comment; now dates it on a terminal.
|
||||
|
||||
Reference in new issue
Block a user