From 123ea0f7bd79b9cd9ba7c408adf8c90edbac4d5f Mon Sep 17 00:00:00 2001 From: Turmaxx <88465473+Turmaxx@users.noreply.github.com> Date: Tue, 19 May 2026 17:01:27 +0300 Subject: [PATCH] updated cmd_docs.go again had to change a couple of things, like updating the docsURLForVersion command, and removing the nested function inside since regexMustCompile is a memory sensitive operation. - rewrote docsURLForVersion as well --- cmd/restic/cmd_docs.go | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/cmd/restic/cmd_docs.go b/cmd/restic/cmd_docs.go index 42ef41707..48130d5ed 100644 --- a/cmd/restic/cmd_docs.go +++ b/cmd/restic/cmd_docs.go @@ -8,6 +8,7 @@ import ( "os/exec" "regexp" "runtime" + "strings" "github.com/spf13/cobra" @@ -22,8 +23,9 @@ const ( type execFn func(name string, arg ...string) *exec.Cmd var ( - stdout io.Writer = os.Stdout - start execFn = exec.Command + stdout io.Writer = os.Stdout + start execFn = exec.Command + versionRegex *regexp.Regexp = regexp.MustCompile(`^(\d+\.\d+\.\d+)`) ) func newDocsCommand(globalOptions *global.Options) *cobra.Command { @@ -60,22 +62,23 @@ func newDocsCommand(globalOptions *global.Options) *cobra.Command { } func docsURLForVersion(version string) string { - extractVersion := func(version string) string { - // match a semantic version at the start of the string, e.g. "0.18.1" or - // "0.18.1-dev (compiled manually)" -> capture "0.18.1" - versionRegex := regexp.MustCompile(`^(\d+\.\d+\.\d+)`) - matches := versionRegex.FindStringSubmatch(version) - if len(matches) == 2 { - return matches[1] - } - return "" + // 1. Safe default fallback for empty/unknown versions + if version == "" || version == "unknown" { + return fmt.Sprintf("%s/stable", ResticURL) } - if tag := extractVersion(version); tag != "" { - return fmt.Sprintf("%s/v%s", ResticURL, tag) + // 2. Route development / local compilation environments directly to bleeding edge docs + if strings.Contains(version, "dev") || strings.Contains(version, "compiled") { + return fmt.Sprintf("%s/latest", ResticURL) } - return ResticURL + // 3. Match strict tag releases (e.g., exact matches like "0.18.1") + matches := versionRegex.FindStringSubmatch(version) + if len(matches) == 2 { + return fmt.Sprintf("%s/v%s", ResticURL, matches[1]) + } + + return fmt.Sprintf("%s/stable", ResticURL) } func openDocs(GOOS string, url string, docType string) {