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