-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathoutput.go
84 lines (67 loc) · 1.59 KB
/
output.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package cmdx
import "strconv"
type (
// OutputIder outputs an ID
OutputIder string
// OutputIderCollection outputs a list of IDs
OutputIderCollection struct {
Items []OutputIder
}
)
func (OutputIder) Header() []string {
return []string{"ID"}
}
func (i OutputIder) Columns() []string {
return []string{string(i)}
}
func (i OutputIder) Interface() interface{} {
return i
}
func (OutputIderCollection) Header() []string {
return []string{"ID"}
}
func (c OutputIderCollection) Table() [][]string {
rows := make([][]string, len(c.Items))
for i, ident := range c.Items {
rows[i] = []string{string(ident)}
}
return rows
}
func (c OutputIderCollection) Interface() interface{} {
return c.Items
}
func (c OutputIderCollection) Len() int {
return len(c.Items)
}
type PaginatedList struct {
Collection interface {
Table
IDs() []string
} `json:"-"`
Items []interface{} `json:"items"`
NextPageToken string `json:"next_page_token"`
IsLastPage bool `json:"is_last_page"`
}
func (r *PaginatedList) Header() []string {
return r.Collection.Header()
}
func (r *PaginatedList) Table() [][]string {
return append(
r.Collection.Table(),
[]string{},
[]string{"NEXT PAGE TOKEN", r.NextPageToken},
[]string{"IS LAST PAGE", strconv.FormatBool(r.IsLastPage)},
)
}
func (r *PaginatedList) Interface() interface{} {
return r
}
func (r *PaginatedList) Len() int {
return r.Collection.Len() + 3
}
func (r *PaginatedList) IDs() []string {
return r.Collection.IDs()
}
var _ Table = (*PaginatedList)(nil)