/
local_list.go
58 lines (51 loc) · 1.14 KB
/
local_list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package cmd
import (
"path/filepath"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/spf13/cobra"
"github.com/treeverse/lakefs/pkg/local"
)
const (
indicesListTemplate = `{{.IndicesListTable | table -}}`
)
var localListCmd = &cobra.Command{
Use: "list [directory]",
Short: "find and list directories that are synced with lakeFS.",
Args: localDefaultArgsRange,
Run: func(cmd *cobra.Command, args []string) {
_, localPath := getSyncArgs(args, false, true)
dirs, err := local.FindIndices(localPath)
if err != nil {
DieErr(err)
}
var rows [][]interface{}
for _, d := range dirs {
idx, err := local.ReadIndex(filepath.Join(localPath, d))
if err != nil {
DieErr(err)
}
remote, err := idx.GetCurrentURI()
if err != nil {
DieErr(err)
}
rows = append(rows, table.Row{d, remote, idx.AtHead})
}
data := struct {
IndicesListTable *Table
}{
IndicesListTable: &Table{
Headers: []interface{}{
"Directory",
"Remote URI",
"Synced commit",
},
Rows: rows,
},
}
Write(indicesListTemplate, data)
},
}
//nolint:gochecknoinits
func init() {
localCmd.AddCommand(localListCmd)
}