Enhancement: add version-specific docs URLs to help output (#21795)

---------

Co-authored-by: Michael Eischer <michael.eischer@fau.de>
This commit is contained in:
Brook SeyoumandMichael Eischer authored and GitHub committed 2026-11-22 16:43:44 +00:00
1 parent 8af83234f2
commit b7e20f3aa2
3 files changed
+32 -3

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
Enhancement: Add version-specific docs URLs to help output
Updated the help message to use version-specific documentation URLs or else just use latest.
https://github.com/restic/restic/pull/21795
+4
View File
@@ -48,6 +48,10 @@ func parseIDsFromReader(t testing.TB, rd io.Reader) restic.IDs {
} }
} }
if err := sc.Err(); err != nil {
t.Fatalf("failed to scan list output (parsed %d IDs before error): %v", len(IDs), err)
}
return IDs return IDs
} }
+23 -3
View File
@@ -8,8 +8,10 @@ import (
"fmt" "fmt"
"log" "log"
"os" "os"
"regexp"
"runtime" "runtime"
godebug "runtime/debug" godebug "runtime/debug"
"strings"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.uber.org/automaxprocs/maxprocs" "go.uber.org/automaxprocs/maxprocs"
@@ -37,12 +39,12 @@ func newRootCommand(globalOptions *global.Options) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "restic", Use: "restic",
Short: "Backup and restore files", Short: "Backup and restore files",
Long: ` Long: fmt.Sprintf(`
restic is a backup program which allows saving multiple revisions of files and restic is a backup program which allows saving multiple revisions of files and
directories in an encrypted repository stored on different backends. directories in an encrypted repository stored on different backends.
The full documentation can be found at https://restic.readthedocs.io/ . The full documentation can be found at %s.
`, `, docsURL(global.Version)),
SilenceErrors: true, SilenceErrors: true,
SilenceUsage: true, SilenceUsage: true,
DisableAutoGenTag: true, DisableAutoGenTag: true,
@@ -132,6 +134,24 @@ func tweakGoGC() {
} }
} }
func docsURL(version string) string {
baseURL := "https://restic.readthedocs.io/en/"
if version == "" || version == "unknown" {
return baseURL + "latest"
}
if strings.Contains(version, "dev") || strings.Contains(version, "compiled") {
return baseURL + "latest"
}
if matches := regexp.MustCompile(`^(\d+\.\d+\.\d+)`).FindStringSubmatch(version); len(matches) == 2 {
return fmt.Sprintf(baseURL+"v%s", matches[1])
}
return baseURL + "latest"
}
func printExitError(globalOptions global.Options, code int, message string) { func printExitError(globalOptions global.Options, code int, message string) {
if globalOptions.JSON { if globalOptions.JSON {
type jsonExitError struct { type jsonExitError struct {