Skip to content

Commit eb304fa

Browse files
committed
line up 'locks' output columns
1 parent 3c8e643 commit eb304fa

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

commands/command_locks.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ package commands
33
import (
44
"encoding/json"
55
"os"
6+
"sort"
7+
"strings"
68

9+
"github.com/git-lfs/git-lfs/locking"
10+
"github.com/git-lfs/git-lfs/tools"
711
"github.com/spf13/cobra"
812
)
913

@@ -30,8 +34,20 @@ func locksCommand(cmd *cobra.Command, args []string) {
3034
return
3135
}
3236

37+
var maxlen int
38+
lockPaths := make([]string, 0, len(locks))
39+
locksByPath := make(map[string]locking.Lock)
3340
for _, lock := range locks {
34-
Print("%s\t%s", lock.Path, lock.Owner)
41+
lockPaths = append(lockPaths, lock.Path)
42+
locksByPath[lock.Path] = lock
43+
maxlen = tools.MaxInt(maxlen, len(lock.Path))
44+
}
45+
46+
sort.Strings(lockPaths)
47+
for _, lockPath := range lockPaths {
48+
lock := locksByPath[lockPath]
49+
padding := tools.MaxInt(maxlen-len(lock.Path), 0)
50+
Print("%s%s\t%s", lock.Path, strings.Repeat(" ", padding), lock.Owner)
3551
}
3652

3753
if err != nil {

0 commit comments

Comments
 (0)