mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01: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
+7
-11
@@ -161,7 +161,7 @@ $ tea auth login --host gitea.com --ssh-key ~/.ssh/id_ed25519`,
|
||||
case selected == 1 && !oauth && cmd.Flags().Changed("scopes"):
|
||||
return clierr.Wrap(clierr.Usage, errors.New("--scopes requires --oauth"))
|
||||
}
|
||||
snapshot, err := a.deps.Settings.Load()
|
||||
snapshot, err := a.settings()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -321,7 +321,7 @@ $ tea auth login --host gitea.com --ssh-key ~/.ssh/id_ed25519`,
|
||||
// confirmReplace asks before a login replaces the stored credential of an account that tea already
|
||||
// has, and reports whether it does.
|
||||
func (a *application) confirmReplace(cmd *cobra.Command, instance, user string) (bool, error) {
|
||||
snapshot, err := a.deps.Settings.Load()
|
||||
snapshot, err := a.settings()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -437,7 +437,7 @@ credential is missing or rejected.`,
|
||||
$ tea auth status --verify
|
||||
$ tea auth status --host gitea.com --json`,
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
s, err := a.deps.Settings.Load()
|
||||
s, err := a.settings()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -708,12 +708,8 @@ asks which one on a terminal. The instance is the one of the current repository,
|
||||
|
||||
// chooseAccount asks which of the accounts of instance to use, or explains how to name one.
|
||||
func (a *application) chooseAccount(cmd *cobra.Command, instance string, names []string, active string) (string, error) {
|
||||
s, err := a.deps.Settings.Load()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
chooser, ok := a.deps.Prompter.(terminal.Chooser)
|
||||
if !ok || !a.policy(s).CanPrompt(a.deps.Streams) {
|
||||
chooser, ok := a.chooser()
|
||||
if !ok {
|
||||
return "", clierr.Wrap(clierr.Usage, fmt.Errorf("name the account: tea auth switch <user> (accounts on %s: %s)", instance, strings.Join(names, ", ")))
|
||||
}
|
||||
choices := make([]terminal.Choice, len(names))
|
||||
@@ -774,7 +770,7 @@ instance.`,
|
||||
a.warn(cmd, "Could not ask git's credential helpers to forget %s on %s", t.User, t.Host)
|
||||
}
|
||||
}
|
||||
if s, err := a.deps.Settings.Load(); err == nil {
|
||||
if s, err := a.settings(); err == nil {
|
||||
if active := s.Hosts.Hosts[t.Host].User; active != "" && active != t.host.User {
|
||||
a.done(cmd, "Switched active account for %s to %s", t.Host, active)
|
||||
}
|
||||
@@ -833,7 +829,7 @@ $ tea auth token --host gitea.com --user alice`,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s, err := a.deps.Settings.Load()
|
||||
s, err := a.settings()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user