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
@@ -216,7 +216,7 @@ $ tea config get default_host --show-source
|
||||
$ tea config get ssh_host --host https://gitea.com
|
||||
$ tea config get ssh_key --host https://gitea.com --user alice`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
snapshot, err := a.deps.Settings.Load()
|
||||
snapshot, err := a.settings()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -247,7 +247,7 @@ $ tea config get ssh_key --host https://gitea.com --user alice`,
|
||||
# Include the settings of an instance
|
||||
$ tea config list --host https://gitea.com`,
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
snapshot, err := a.deps.Settings.Load()
|
||||
snapshot, err := a.settings()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -348,7 +348,7 @@ func (a *application) reportSet(cmd *cobra.Command, key, value, scope string) {
|
||||
|
||||
// warnWithoutAccount points out a default_host that has no account to act as yet.
|
||||
func (a *application) warnWithoutAccount(cmd *cobra.Command) {
|
||||
snapshot, err := a.deps.Settings.Load()
|
||||
snapshot, err := a.settings()
|
||||
if host := snapshot.Preferences.DefaultHost; err == nil && len(snapshot.Hosts.Hosts[host].Users) == 0 {
|
||||
a.warn(cmd, "No account on %s yet; log in with: tea auth login --host %s", host, host)
|
||||
}
|
||||
@@ -564,7 +564,7 @@ $ tea alias set il "issue list --assignee @me" --clobber`,
|
||||
Use: "list", Short: "List shortcuts", Args: argsExact(0),
|
||||
Example: "$ tea alias list\n# Print the expansion of one alias\n$ tea alias list --jq .il",
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
s, err := a.deps.Settings.Load()
|
||||
s, err := a.settings()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user