repo mirror list: fail fast on bad --sort column · Entire

repo mirror list: fail fast on bad --sort column

9c6ee6f→main·

gtrrz-victor·1w ago·2 files·+17 added/-6 removed

Validate --sort in PreRunE so an unknown column errors before the network fetch RunE would otherwise do first, picking the valid column set by --show-available. Also correct the --repo help/doc to say it filters the repo name only (owner/provider/cluster stay server-side).

Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com

Sessions

01KX0B74J5W2TCT833ZXMSPZ0FView transcript

[?
Fix Repo Mirror List Filtering and SortingClaude Code·Opus 4.8[1m]·2 steps](/content/gh/entireio/cli/session/9388357d-3413-4e5c-9851-50fb037bbbbe#timeline-01KX0B74J5W2TCT833ZXMSPZ0F/index.html)

Changes

2

21 unmodified lines

22
23
24
25
26
27
28
25
26
27
28
29
30
31
437 unmodified lines

469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
67 unmodified lines

553
554
555
545
556
557
558
559

21 unmodified lines

// owner/repo name, the clone URL you'd copy, and whether the upstream is
// private. Owner, provider, and cluster aren't columns of their own — they're
// inferable from the owner/repo pair and the clone URL
// (entire://<cluster>/gh/<owner>/<repo>), where `--repo` and a bare cluster/
// provider substring still match — and the wire model's internal ids are
// dropped. The clone URL is synthesised from the mirror's coords (the form
// `git clone` accepts), since the list API doesn't return it.
// (entire://<cluster>/gh/<owner>/<repo>). `--repo` filters on the repo name
// only; owner/provider/cluster stay server-side filters, and the wire model's
// internal ids are dropped. The clone URL is synthesised from the mirror's
// coords (the form `git clone` accepts), since the list API doesn't return it.
var mirrorColumns = []string{"REPO", "CLONE URL", "PRIVATE"}

// mirrorPrivate renders the PRIVATE column ("yes"/"no"), shared by the table
437 unmodified lines

Use:   "list",
        Short: "List mirrors you can see (or, with --show-available, repos you could mirror)",
        Args:  cobra.NoArgs,
        // Validate --sort before RunE so a bad column fails fast, without the
        // network round-trip RunE would otherwise do first. The valid column
        // set depends on --show-available (different table shape).
        PreRunE: func(_ *cobra.Command, _ []string) error {
            cols := mirrorColumns
            if showAvailable {
                cols = availableMirrorColumns
            }
            _, _, err := parseSortColumn(sortSpec, cols)
            return err
        },
        RunE: func(cmd *cobra.Command, _ []string) error {
            if showAvailable {
                return runCoreList(cmd, "No repos available to mirror.", availableMirrorColumns, availableMirrorRow, func(ctx context.Context, c *coreapi.Client) ([]coreapi.AvailableMirror, error) {
67 unmodified lines

cmd.Flags().StringVar(&cluster, "cluster", "", "Filter by cluster public host")
        cmd.Flags().StringVar(&provider, "provider", "", "Filter by upstream provider (e.g. github)")
        cmd.Flags().StringVar(&owner, "owner", "", "Filter by upstream owner login")
        cmd.Flags().StringVar(&repo, "repo", "", "Filter by repo name")
        cmd.Flags().StringVar(&repo, "repo", "", "Filter by repo-name substring (case-insensitive)")
        cmd.Flags().StringVar(&sortSpec, "sort", "", "Sort by column (header name; prefix '-' for descending). Default: repo name ascending")
        cmd.Flags().BoolVar(&showAvailable, "show-available", false, "Instead of existing mirrors, list GitHub repos you could onboard as mirrors (ignores --cluster/--provider)")
        return cmd

Mcmd/entire/cli/repo_mirror.go+16/-5

379 unmodified lines

380
381
382
383
383
384
385
386

379 unmodified lines

// execMirrorList runs `list` under a parent that carries the control-plane
// persistent flags (--json lives there, not on the list command itself), so
// tests can exercise --json and the client-side --filter/--sort together.
// tests can exercise --json and the client-side --repo/--sort together.
func execMirrorList(t *testing.T, args ...string) (stdout, stderr string, err error) {

t.Helper()
    parent := &cobra.Command{Use: "mirror"}