forked from TrueCloudLab/restic
Merge pull request #4553 from CommanderRoot/add-version-json
Add --json option to version command
This commit is contained in:
commit
81ca9d28f2
3 changed files with 49 additions and 2 deletions
7
changelog/unreleased/issue-4547
Normal file
7
changelog/unreleased/issue-4547
Normal file
|
@ -0,0 +1,7 @@
|
|||
Enhancement: Add support for `--json` option to `version` command
|
||||
|
||||
Restic now supports outputting restic version and used go version, OS and
|
||||
architecture via JSON when using the version command.
|
||||
|
||||
https://github.com/restic/restic/issues/4547
|
||||
https://github.com/restic/restic/pull/4553
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"runtime"
|
||||
|
||||
|
@ -21,8 +22,31 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
|
|||
`,
|
||||
DisableAutoGenTag: true,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Printf("restic %s compiled with %v on %v/%v\n",
|
||||
version, runtime.Version(), runtime.GOOS, runtime.GOARCH)
|
||||
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)
|
||||
}
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -576,3 +576,19 @@ The snapshots command returns a single JSON object.
|
|||
+------------------------------+-----------------------------------------------------+
|
||||
| ``compression_space_saving`` | Overall space saving due to compression |
|
||||
+------------------------------+-----------------------------------------------------+
|
||||
|
||||
|
||||
version
|
||||
-------
|
||||
|
||||
The version command returns a single JSON object.
|
||||
|
||||
+----------------+--------------------+
|
||||
| ``version`` | restic version |
|
||||
+----------------+--------------------+
|
||||
| ``go_version`` | Go compile version |
|
||||
+----------------+--------------------+
|
||||
| ``go_os`` | Go OS |
|
||||
+----------------+--------------------+
|
||||
| ``go_arch`` | Go architecture |
|
||||
+----------------+--------------------+
|
||||
|
|
Loading…
Reference in a new issue