mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
refactor: load settings once per run and reuse shared helpers
The application caches the settings snapshot and reloads it only after an update through the store, so output and prompt helpers no longer read and parse config.yml and hosts.yml several times per command. canPrompt and chooser replace the inline prompt-policy checks. Checks are tallied by one services.Tally, terminal.Plural replaces the two app copies, refKind.article/noun replace the comment group's own words, list commands use servicePage, and web URLs are built by repositoryURL and webURL in browser.go. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
42 files changed
+157
-204
No files matched your search
+14
-2
@@ -12,13 +12,25 @@ import (
|
||||
// DefaultYes, destructive ones keep the default no, and irreversible ones set Typed. A declined
|
||||
// confirmation returns terminal.ErrCanceled.
|
||||
func (a *application) confirmAction(cmd *cobra.Command, c terminal.Confirmation) error {
|
||||
s, err := a.deps.Settings.Load()
|
||||
s, err := a.settings()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return terminal.ConfirmAction(cmd.Context(), c, a.options.yes, a.deps.Streams, a.policy(s), a.deps.Prompter)
|
||||
}
|
||||
|
||||
// canPrompt reports whether tea may ask questions on this terminal.
|
||||
func (a *application) canPrompt() bool {
|
||||
s, err := a.settings()
|
||||
return err == nil && a.policy(s).CanPrompt(a.deps.Streams)
|
||||
}
|
||||
|
||||
// chooser returns the prompter's selection prompt when prompts are allowed.
|
||||
func (a *application) chooser() (terminal.Chooser, bool) {
|
||||
chooser, ok := a.deps.Prompter.(terminal.Chooser)
|
||||
return chooser, ok && a.canPrompt()
|
||||
}
|
||||
|
||||
// deleteConfirmed asks to delete subject, such as `label "bug" from alice/x`, deletes it with del
|
||||
// and reports "Deleted <subject>".
|
||||
func (a *application) deleteConfirmed(cmd *cobra.Command, subject string, del func() error) error {
|
||||
@@ -36,7 +48,7 @@ func (a *application) deleteConfirmed(cmd *cobra.Command, subject string, del fu
|
||||
// until the answer is non-empty and validate, when set, accepts it. Without prompts it returns a
|
||||
// usage error naming --flag. It reports whether it prompted.
|
||||
func (a *application) requireInput(cmd *cobra.Command, value *string, flag, label string, validate func(string) error) (bool, error) {
|
||||
s, err := a.deps.Settings.Load()
|
||||
s, err := a.settings()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user