Add cursor pagination flags to proboctl list commands
Replace the limit-driven auto-walking Paginate helper with explicit cursor-pagination flags (--first/--after, --last/--before) that mirror the GraphQL connection arguments. List commands now return a single keyset page with its page info, and emit cursors so callers can page forward and backward. --before no longer requires --last: both --first and --last default to 50 when omitted. Also split the tracker-pattern stats into enriched with and without a description so the enrichment backlog is visible at a glance. Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
@@ -40,7 +40,6 @@ func newCmdList(f *cmdutil.Factory) *cobra.Command {
|
||||
flagWithoutDescription bool
|
||||
flagSort string
|
||||
flagOrder string
|
||||
flagLimit int
|
||||
)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@@ -62,7 +61,8 @@ func newCmdList(f *cmdutil.Factory) *cobra.Command {
|
||||
cmd.Flags().BoolVar(&flagWithoutDescription, "without-description", false, "Only patterns with a blank description")
|
||||
cmd.Flags().StringVar(&flagSort, "sort", "confidence", "Sort field: pattern, confidence, created, updated, enriched")
|
||||
cmd.Flags().StringVar(&flagOrder, "order", "", "Sort order: asc, desc (default depends on field)")
|
||||
cmd.Flags().IntVarP(&flagLimit, "limit", "L", 50, "Maximum rows to return (0 for all)")
|
||||
|
||||
pageFlags := cmdutil.AddPageFlags(cmd)
|
||||
|
||||
cmd.RunE = func(cmd *cobra.Command, args []string) error {
|
||||
if err := clicmdutil.ValidateOutputFlag(output); err != nil {
|
||||
@@ -78,6 +78,11 @@ func newCmdList(f *cmdutil.Factory) *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
cursor, err := cmdutil.NewCursorFromFlags(pageFlags, orderBy)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var withCommonThirdParty *bool
|
||||
if cmd.Flags().Changed("with-common-third-party") {
|
||||
withCommonThirdParty = &flagWithCommonThirdParty
|
||||
@@ -100,7 +105,10 @@ func newCmdList(f *cmdutil.Factory) *cobra.Command {
|
||||
|
||||
ctx := cmd.Context()
|
||||
|
||||
var patterns coredata.CommonTrackerPatterns
|
||||
var (
|
||||
patterns coredata.CommonTrackerPatterns
|
||||
pageInfo cmdutil.PageInfo
|
||||
)
|
||||
|
||||
if err := pgClient.WithConn(
|
||||
ctx,
|
||||
@@ -153,10 +161,9 @@ func newCmdList(f *cmdutil.Factory) *cobra.Command {
|
||||
filter.WithIDs(linkedIDs)
|
||||
}
|
||||
|
||||
rows, err := cmdutil.Paginate(
|
||||
p, err := cmdutil.FetchPage(
|
||||
ctx,
|
||||
orderBy,
|
||||
flagLimit,
|
||||
cursor,
|
||||
func(ctx context.Context, cursor *page.Cursor[coredata.CommonTrackerPatternOrderField]) ([]*coredata.CommonTrackerPattern, error) {
|
||||
var ps coredata.CommonTrackerPatterns
|
||||
if err := ps.Load(ctx, conn, cursor, filter); err != nil {
|
||||
@@ -170,7 +177,8 @@ func newCmdList(f *cmdutil.Factory) *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
patterns = rows
|
||||
patterns = p.Data
|
||||
pageInfo = cmdutil.NewPageInfo(p)
|
||||
|
||||
return nil
|
||||
},
|
||||
@@ -179,16 +187,16 @@ func newCmdList(f *cmdutil.Factory) *cobra.Command {
|
||||
}
|
||||
|
||||
if *output == clicmdutil.OutputJSON {
|
||||
return clicmdutil.PrintJSON(f.IOStreams.Out, patterns)
|
||||
return clicmdutil.PrintJSON(f.IOStreams.Out, cmdutil.PageOutput{Items: patterns, PageInfo: pageInfo})
|
||||
}
|
||||
|
||||
return renderPatternTable(cmd, f, patterns)
|
||||
return renderPatternTable(cmd, f, patterns, pageInfo)
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func renderPatternTable(cmd *cobra.Command, f *cmdutil.Factory, patterns coredata.CommonTrackerPatterns) error {
|
||||
func renderPatternTable(cmd *cobra.Command, f *cmdutil.Factory, patterns coredata.CommonTrackerPatterns, pageInfo cmdutil.PageInfo) error {
|
||||
out := f.IOStreams.Out
|
||||
|
||||
if len(patterns) == 0 {
|
||||
@@ -243,6 +251,7 @@ func renderPatternTable(cmd *cobra.Command, f *cmdutil.Factory, patterns coredat
|
||||
}
|
||||
|
||||
_, _ = fmt.Fprintln(out, table.Render())
|
||||
cmdutil.PrintPageInfo(out, pageInfo)
|
||||
_, _ = fmt.Fprintf(f.IOStreams.ErrOut, "Showing %d common tracker patterns.\n", len(patterns))
|
||||
|
||||
return nil
|
||||
|
||||
@@ -55,7 +55,8 @@ func newCmdStats(f *cmdutil.Factory) *cobra.Command {
|
||||
}{
|
||||
{"total", coredata.NewCommonTrackerPatternFilter()},
|
||||
{"queued", coredata.NewCommonTrackerPatternFilter().WithState(new(coredata.CommonTrackerPatternEnrichmentStateQueued))},
|
||||
{"enriched", coredata.NewCommonTrackerPatternFilter().WithState(new(coredata.CommonTrackerPatternEnrichmentStateEnriched))},
|
||||
{"enriched", coredata.NewCommonTrackerPatternFilter().WithState(new(coredata.CommonTrackerPatternEnrichmentStateEnriched)).WithDescribed(new(true))},
|
||||
{"enriched (no description)", coredata.NewCommonTrackerPatternFilter().WithState(new(coredata.CommonTrackerPatternEnrichmentStateEnriched)).WithDescribed(new(false))},
|
||||
{"unenriched", coredata.NewCommonTrackerPatternFilter().WithState(new(coredata.CommonTrackerPatternEnrichmentStateUnenriched))},
|
||||
{"linked", coredata.NewCommonTrackerPatternFilter().WithLinked(new(true))},
|
||||
{"unlinked", coredata.NewCommonTrackerPatternFilter().WithLinked(new(false))},
|
||||
@@ -83,7 +84,7 @@ func newCmdStats(f *cmdutil.Factory) *cobra.Command {
|
||||
}
|
||||
|
||||
table := clicmdutil.NewTable("METRIC", "COUNT")
|
||||
for _, key := range []string{"total", "queued", "enriched", "unenriched", "linked", "unlinked"} {
|
||||
for _, key := range []string{"total", "queued", "enriched", "enriched (no description)", "unenriched", "linked", "unlinked"} {
|
||||
table.Row(key, fmt.Sprintf("%d", stats[key]))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user