mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
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>
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package app
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
"strings"
|
|
|
|
"gitea.dev/tea/internal/terminal"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// openBrowser opens resource in the configured browser, telling people on a terminal what opens.
|
|
func (a *application) openBrowser(command *cobra.Command, resource string) error {
|
|
preferences, err := a.preferences()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if a.deps.Streams.OutTTY {
|
|
fmt.Fprintf(command.ErrOrStderr(), "Opening %s in your browser.\n", displayURL(resource))
|
|
}
|
|
return a.deps.Browser.Open(command.Context(), resource, preferences.Browser)
|
|
}
|
|
|
|
// displayURL shows a URL to people without its scheme, like gh.
|
|
func displayURL(url string) string {
|
|
return terminal.SafeLine(strings.TrimPrefix(strings.TrimPrefix(url, "https://"), "http://"))
|
|
}
|
|
|
|
// webURL is the page of a path on the target's instance, such as an organization's profile.
|
|
func webURL(t target, path ...string) string {
|
|
escaped := make([]string, len(path))
|
|
for i, segment := range path {
|
|
escaped[i] = url.PathEscape(segment)
|
|
}
|
|
return strings.TrimSuffix(t.Host, "/") + "/" + strings.Join(escaped, "/")
|
|
}
|
|
|
|
// repositoryURL returns the web URL of the target's repository.
|
|
func repositoryURL(t target) string {
|
|
return strings.TrimSuffix(t.Host, "/") + "/" + t.Repo
|
|
}
|