diff --git a/changelog/unreleased/pull-21795 b/changelog/unreleased/pull-21795 new file mode 100644 index 000000000..242ba2ac7 --- /dev/null +++ b/changelog/unreleased/pull-21795 @@ -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 diff --git a/cmd/restic/cmd_list_integration_test.go b/cmd/restic/cmd_list_integration_test.go index e921ef0e4..718b0ef18 100644 --- a/cmd/restic/cmd_list_integration_test.go +++ b/cmd/restic/cmd_list_integration_test.go @@ -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 } diff --git a/cmd/restic/main.go b/cmd/restic/main.go index 789496bcc..5c6e46334 100644 --- a/cmd/restic/main.go +++ b/cmd/restic/main.go @@ -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 {