mirror of
https://github.com/restic/restic.git
synced 2026-11-23 13:52:39 +00:00
Enhancement: add version-specific docs URLs to help output (#21795)
--------- Co-authored-by: Michael Eischer <michael.eischer@fau.de>
This commit is contained in:
1 parent
8af83234f2
commit
b7e20f3aa2
3 files changed
+32
-3
No files matched your search
@@ -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
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user