From 54c2f622a4285542b4507ff357e433d44b4f27fe Mon Sep 17 00:00:00 2001 From: Florian Adamsky Date: Wed, 18 Jan 2017 20:46:00 +0100 Subject: [PATCH] Add box-drawing character to the snapshots command Remove underscore of variable name Format code with gofmt Change snapshot output according to the discussion --- src/cmds/restic/cmd_snapshots.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/cmds/restic/cmd_snapshots.go b/src/cmds/restic/cmd_snapshots.go index 6195ffb0a..74a7c1263 100644 --- a/src/cmds/restic/cmd_snapshots.go +++ b/src/cmds/restic/cmd_snapshots.go @@ -57,8 +57,8 @@ func runSnapshots(opts SnapshotOptions, gopts GlobalOptions, args []string) erro } tab := NewTable() - tab.Header = fmt.Sprintf("%-8s %-19s %-10s %-10s %s", "ID", "Date", "Host", "Tags", "Directory") - tab.RowFormat = "%-8s %-19s %-10s %-10s %s" + tab.Header = fmt.Sprintf("%-8s %-19s %-10s %-10s %-3s %s", "ID", "Date", "Host", "Tags", "", "Directory") + tab.RowFormat = "%-8s %-19s %-10s %-10s %-3s %s" done := make(chan struct{}) defer close(done) @@ -97,9 +97,15 @@ func runSnapshots(opts SnapshotOptions, gopts GlobalOptions, args []string) erro firstTag = sn.Tags[0] } - tab.Rows = append(tab.Rows, []interface{}{sn.ID().Str(), sn.Time.Format(TimeFormat), sn.Hostname, firstTag, sn.Paths[0]}) - rows := len(sn.Paths) + + treeElement := " " + if rows != 1 { + treeElement = "┌──" + } + + tab.Rows = append(tab.Rows, []interface{}{sn.ID().Str(), sn.Time.Format(TimeFormat), sn.Hostname, firstTag, treeElement, sn.Paths[0]}) + if len(sn.Tags) > rows { rows = len(sn.Tags) } @@ -115,7 +121,12 @@ func runSnapshots(opts SnapshotOptions, gopts GlobalOptions, args []string) erro tag = sn.Tags[i] } - tab.Rows = append(tab.Rows, []interface{}{"", "", "", tag, path}) + treeElement := "│" + if i == (rows - 1) { + treeElement = "└──" + } + + tab.Rows = append(tab.Rows, []interface{}{"", "", "", tag, treeElement, path}) } }