-
Notifications
You must be signed in to change notification settings - Fork 332
/
tag_list.go
68 lines (59 loc) · 1.82 KB
/
tag_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
59
60
61
62
63
64
65
66
67
68
package cmd
import (
"net/http"
"github.com/spf13/cobra"
"github.com/treeverse/lakefs/pkg/api/apigen"
"github.com/treeverse/lakefs/pkg/api/apiutil"
)
var tagListCmd = &cobra.Command{
Use: "list <repository URI>",
Short: "List tags in a repository",
Example: "lakectl tag list " + myRepoExample,
Args: cobra.ExactArgs(1),
ValidArgsFunction: ValidArgsRepository,
Run: func(cmd *cobra.Command, args []string) {
amount := Must(cmd.Flags().GetInt("amount"))
after := Must(cmd.Flags().GetString("after"))
u := MustParseRepoURI("repository URI", args[0])
ctx := cmd.Context()
client := getClient()
resp, err := client.ListTagsWithResponse(ctx, u.Repository, &apigen.ListTagsParams{
After: apiutil.Ptr(apigen.PaginationAfter(after)),
Amount: apiutil.Ptr(apigen.PaginationAmount(amount)),
})
DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK)
if resp.JSON200 == nil {
Die("Bad response from server", 1)
}
refs := resp.JSON200.Results
rows := make([][]interface{}, len(refs))
for i, row := range refs {
rows[i] = []interface{}{row.Id, row.CommitId}
}
tmplArgs := struct {
TagTable *Table
Pagination *Pagination
}{
TagTable: &Table{
Headers: []interface{}{"Tag", "Commit ID"},
Rows: rows,
},
}
pagination := resp.JSON200.Pagination
if pagination.HasMore {
tmplArgs.Pagination = &Pagination{
Amount: amount,
HasNext: true,
After: pagination.NextOffset,
}
}
PrintTable(rows, []interface{}{"Tag", "Commit ID"}, &pagination, amount)
},
}
//nolint:gochecknoinits
func init() {
flags := tagListCmd.Flags()
flags.Int("amount", defaultAmountArgumentValue, "number of results to return")
flags.String("after", "", "show results after this value (used for pagination)")
tagCmd.AddCommand(tagListCmd)
}