2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 10:58:55 +00:00

command version: add json output option

This commit is contained in:
Tobias Speicher 2023-10-31 19:30:00 +01:00
parent 42ab3ea2b9
commit d45cc52468
No known key found for this signature in database
GPG Key ID: 2CF824BD810C3BDB

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"encoding/json"
"fmt" "fmt"
"runtime" "runtime"
@ -21,8 +22,31 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("restic %s compiled with %v on %v/%v\n", if globalOptions.JSON {
version, runtime.Version(), runtime.GOOS, runtime.GOARCH) type jsonVersion struct {
Version string `json:"version"`
GoVersion string `json:"go_version"`
GoTarget string `json:"go_target"`
}
jsonS := jsonVersion{
Version: version,
GoVersion: runtime.Version(),
GoTarget: runtime.GOOS + "/" + runtime.GOARCH,
}
jsonB, err := json.Marshal(jsonS)
if err != nil {
Warnf("Marshall failed: %v\n", err)
return
}
fmt.Println(string(jsonB))
} else {
fmt.Printf("restic %s compiled with %v on %v/%v\n",
version, runtime.Version(), runtime.GOOS, runtime.GOARCH)
}
}, },
} }