restic/cmd/restic/cmd_version.go

56 lines
1.1 KiB
Go
Raw Normal View History

2015-01-16 21:26:33 +01:00
package main
import (
"encoding/json"
2015-01-16 21:26:33 +01:00
"fmt"
"runtime"
2016-09-17 12:36:05 +02:00
"github.com/spf13/cobra"
)
2015-01-16 21:26:33 +01:00
2016-09-17 12:36:05 +02:00
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print version information",
2016-09-17 12:36:05 +02:00
Long: `
The "version" command prints detailed information about the build environment
and the version of this software.
EXIT STATUS
===========
Exit status is 0 if the command was successful, and non-zero if there was any error.
2016-09-17 12:36:05 +02:00
`,
DisableAutoGenTag: true,
2024-02-10 22:58:10 +01:00
Run: func(_ *cobra.Command, _ []string) {
if globalOptions.JSON {
type jsonVersion struct {
Version string `json:"version"`
GoVersion string `json:"go_version"`
GoOS string `json:"go_os"`
GoArch string `json:"go_arch"`
}
jsonS := jsonVersion{
Version: version,
GoVersion: runtime.Version(),
GoOS: runtime.GOOS,
GoArch: runtime.GOARCH,
}
err := json.NewEncoder(globalOptions.stdout).Encode(jsonS)
if err != nil {
Warnf("JSON encode failed: %v\n", err)
return
}
} else {
fmt.Printf("restic %s compiled with %v on %v/%v\n",
version, runtime.Version(), runtime.GOOS, runtime.GOARCH)
}
2016-09-17 12:36:05 +02:00
},
2015-01-16 21:26:33 +01:00
}
2016-09-17 12:36:05 +02:00
func init() {
cmdRoot.AddCommand(versionCmd)
2015-01-16 21:26:33 +01:00
}