From eb304fa10b5a939fdaf6b260d7a10374f3ee9830 Mon Sep 17 00:00:00 2001 From: risk danger olson Date: Thu, 23 Feb 2017 13:55:04 -0700 Subject: [PATCH] line up 'locks' output columns --- commands/command_locks.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/commands/command_locks.go b/commands/command_locks.go index c316bb05..dc198ecc 100644 --- a/commands/command_locks.go +++ b/commands/command_locks.go @@ -3,7 +3,11 @@ package commands import ( "encoding/json" "os" + "sort" + "strings" + "github.com/git-lfs/git-lfs/locking" + "github.com/git-lfs/git-lfs/tools" "github.com/spf13/cobra" ) @@ -30,8 +34,20 @@ func locksCommand(cmd *cobra.Command, args []string) { return } + var maxlen int + lockPaths := make([]string, 0, len(locks)) + locksByPath := make(map[string]locking.Lock) for _, lock := range locks { - Print("%s\t%s", lock.Path, lock.Owner) + lockPaths = append(lockPaths, lock.Path) + locksByPath[lock.Path] = lock + maxlen = tools.MaxInt(maxlen, len(lock.Path)) + } + + sort.Strings(lockPaths) + for _, lockPath := range lockPaths { + lock := locksByPath[lockPath] + padding := tools.MaxInt(maxlen-len(lock.Path), 0) + Print("%s%s\t%s", lock.Path, strings.Repeat(" ", padding), lock.Owner) } if err != nil {