# HG changeset patch # User Peter Sanchez # Date 1633740186 25200 # Fri Oct 08 17:43:06 2021 -0700 # Node ID 36b8e0dc3430b4455644f497589a61b836abc58f # Parent 074d83a71249f5b89b0d4e85cecf1b1373bbd62d Fixing stats formatting. Closes #9 diff --git a/cmd/stats.go b/cmd/stats.go --- a/cmd/stats.go +++ b/cmd/stats.go @@ -2,6 +2,8 @@ import ( "fmt" + "os" + "text/tabwriter" "github.com/spf13/cobra" "hg.code.netlandish.com/~petersanchez/tago/lib" @@ -47,11 +49,13 @@ return err } if len(tags) > 0 { - fmt.Println("Tag\t\tFile Count") - fmt.Println("---\t\t----------") + writer := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', tabwriter.AlignRight) + fmt.Fprintln(writer, "Tag\tFile Count") + fmt.Fprintln(writer, "---\t----------") for _, tag := range tags { - fmt.Printf("%s\t\t%d\n", tag.Name, tag.Count) + fmt.Fprintf(writer, "%s\t\t%d\n", tag.Name, tag.Count) } + writer.Flush() } else { fmt.Println("There are no tags in the database.") }