mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 14:56:29 +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 {
|
||||
Hostname string
|
||||
Paths []string
|
||||
Tags []string
|
||||
Hostname string `json:"hostname"`
|
||||
Paths []string `json:"paths"`
|
||||
Tags []string `json:"tags"`
|
||||
}
|
||||
|
||||
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.
|
||||
// Prints nothing, if we did not group at all.
|
||||
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 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, ":\n")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -335,8 +336,8 @@ type Snapshot struct {
|
||||
|
||||
// SnapshotGroup helps to print SnaphotGroups as JSON with their GroupReasons included.
|
||||
type SnapshotGroup struct {
|
||||
GroupKey groupKey
|
||||
Snapshots []Snapshot
|
||||
GroupKey groupKey `json:"group_key"`
|
||||
Snapshots []Snapshot `json:"snapshots"`
|
||||
}
|
||||
|
||||
// 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)
|
||||
} else {
|
||||
}
|
||||
|
||||
// Old behavior
|
||||
var snapshots []Snapshot
|
||||
|
||||
@ -388,5 +390,4 @@ func printSnapshotGroupJSON(stdout io.Writer, snGroups map[string]restic.Snapsho
|
||||
}
|
||||
|
||||
return json.NewEncoder(stdout).Encode(snapshots)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user