mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 23:06:32 +00:00
Fix json tags for grouped snapshot output
This commit will add json tags to the structs for json output, so all json variables of the snapshot command output are lowercase and snake-case. Furthermore it adds some internal code changes based on the feedback in the pull request #2087.
This commit is contained in:
parent
cadcab5a19
commit
c9fd9b5275
@ -51,9 +51,9 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type groupKey struct {
|
type groupKey struct {
|
||||||
Hostname string
|
Hostname string `json:"hostname"`
|
||||||
Paths []string
|
Paths []string `json:"paths"`
|
||||||
Tags []string
|
Tags []string `json:"tags"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func runSnapshots(opts SnapshotOptions, gopts GlobalOptions, args []string) error {
|
func runSnapshots(opts SnapshotOptions, gopts GlobalOptions, args []string) error {
|
||||||
@ -295,7 +295,9 @@ func PrintSnapshots(stdout io.Writer, list restic.Snapshots, reasons []restic.Ke
|
|||||||
// following snapshots belong to.
|
// following snapshots belong to.
|
||||||
// Prints nothing, if we did not group at all.
|
// Prints nothing, if we did not group at all.
|
||||||
func PrintSnapshotGroupHeader(stdout io.Writer, groupKeyJSON string, GroupByTag bool, GroupByHost bool, GroupByPath bool) error {
|
func PrintSnapshotGroupHeader(stdout io.Writer, groupKeyJSON string, GroupByTag bool, GroupByHost bool, GroupByPath bool) error {
|
||||||
if GroupByTag || GroupByHost || GroupByPath {
|
if !GroupByTag && !GroupByHost && !GroupByPath {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
var key groupKey
|
var key groupKey
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
@ -320,7 +322,6 @@ func PrintSnapshotGroupHeader(stdout io.Writer, groupKeyJSON string, GroupByTag
|
|||||||
fmt.Fprintf(stdout, " for (%s)", strings.Join(infoStrings, ", "))
|
fmt.Fprintf(stdout, " for (%s)", strings.Join(infoStrings, ", "))
|
||||||
}
|
}
|
||||||
fmt.Fprintf(stdout, ":\n")
|
fmt.Fprintf(stdout, ":\n")
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -335,8 +336,8 @@ type Snapshot struct {
|
|||||||
|
|
||||||
// SnapshotGroup helps to print SnaphotGroups as JSON with their GroupReasons included.
|
// SnapshotGroup helps to print SnaphotGroups as JSON with their GroupReasons included.
|
||||||
type SnapshotGroup struct {
|
type SnapshotGroup struct {
|
||||||
GroupKey groupKey
|
GroupKey groupKey `json:"group_key"`
|
||||||
Snapshots []Snapshot
|
Snapshots []Snapshot `json:"snapshots"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// printSnapshotsJSON writes the JSON representation of list to stdout.
|
// printSnapshotsJSON writes the JSON representation of list to stdout.
|
||||||
@ -372,7 +373,8 @@ func printSnapshotGroupJSON(stdout io.Writer, snGroups map[string]restic.Snapsho
|
|||||||
}
|
}
|
||||||
|
|
||||||
return json.NewEncoder(stdout).Encode(snapshotGroups)
|
return json.NewEncoder(stdout).Encode(snapshotGroups)
|
||||||
} else {
|
}
|
||||||
|
|
||||||
// Old behavior
|
// Old behavior
|
||||||
var snapshots []Snapshot
|
var snapshots []Snapshot
|
||||||
|
|
||||||
@ -388,5 +390,4 @@ func printSnapshotGroupJSON(stdout io.Writer, snGroups map[string]restic.Snapsho
|
|||||||
}
|
}
|
||||||
|
|
||||||
return json.NewEncoder(stdout).Encode(snapshots)
|
return json.NewEncoder(stdout).Encode(snapshots)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user