Some checks failed
CI / Run tests and lints (push) Failing after 29s
CI / Build CLI docs (push) Has been skipped
CI / Run Playwright end-to-end tests (mysql) (push) Failing after 3s
CI / Run Playwright end-to-end tests (postgres) (push) Failing after 2s
CI / Run Playwright end-to-end tests (sqlite) (push) Failing after 3s
CodeQL / Analyze (go) (push) Failing after 4s
CodeQL / Analyze (javascript) (push) Failing after 3s
Docker Image Scanners / scanners (push) Failing after 4s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Run end-to-end tests (postgres) (push) Failing after 19s
CI / Run end-to-end tests (sqlite) (push) Failing after 2s
CI / Run Playwright end-to-end tests (cockroach) (push) Failing after 2s
CI / Draft newsletter (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
85 lines
1.6 KiB
Go
85 lines
1.6 KiB
Go
// 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)
|