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

+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
}
+23 -3
View File
@@ -8,8 +8,10 @@ import (
"fmt"
"log"
"os"
"regexp"
"runtime"
godebug "runtime/debug"
"strings"
"github.com/spf13/cobra"
"go.uber.org/automaxprocs/maxprocs"
@@ -37,12 +39,12 @@ func newRootCommand(globalOptions *global.Options) *cobra.Command {
cmd := &cobra.Command{
Use: "restic",
Short: "Backup and restore files",
Long: `
Long: fmt.Sprintf(`
restic is a backup program which allows saving multiple revisions of files and
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,
SilenceUsage: 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) {
if globalOptions.JSON {
type jsonExitError struct {