2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-12 08:16:37 +00:00

Make columns for host and tags size width dynamicly on their content.

This commit is contained in:
Pauline Middelink 2017-03-05 05:32:01 +01:00
parent edd5c8b44d
commit 45e9f35654

View File

@ -99,9 +99,22 @@ func runSnapshots(opts SnapshotOptions, gopts GlobalOptions, args []string) erro
// printSnapshotsReadable prints a text table of the snapshots in list to stdout. // printSnapshotsReadable prints a text table of the snapshots in list to stdout.
func printSnapshotsReadable(stdout io.Writer, list []*restic.Snapshot) { func printSnapshotsReadable(stdout io.Writer, list []*restic.Snapshot) {
// Determine the max widths for host and tag.
maxHost, maxTag := 10, 6
for _, sn := range list {
if len(sn.Hostname) > maxHost {
maxHost = len(sn.Hostname)
}
for _, tag := range sn.Tags {
if len(tag) > maxTag {
maxTag = len(tag)
}
}
}
tab := NewTable() tab := NewTable()
tab.Header = fmt.Sprintf("%-8s %-19s %-10s %-10s %-3s %s", "ID", "Date", "Host", "Tags", "", "Directory") tab.Header = fmt.Sprintf("%-8s %-19s %-*s %-*s %-3s %s", "ID", "Date", -maxHost, "Host", -maxTag, "Tags", "", "Directory")
tab.RowFormat = "%-8s %-19s %-10s %-10s %-3s %s" tab.RowFormat = fmt.Sprintf("%%-8s %%-19s %%%ds %%%ds %%-3s %%s", -maxHost, -maxTag)
for _, sn := range list { for _, sn := range list {
if len(sn.Paths) == 0 { if len(sn.Paths) == 0 {