Skip to content

Commit 86b1e60

Browse files
authored
Merge pull request #1241 from planetscale/nick/list-tablets
Add list-tablets command to pscale branch vtctld
2 parents 18f16ca + ecea8a2 commit 86b1e60

5 files changed

Lines changed: 57 additions & 3 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ require (
2525
github.com/mattn/go-shellwords v1.0.12
2626
github.com/mitchellh/go-homedir v1.1.0
2727
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
28-
github.com/planetscale/planetscale-go v0.159.0
28+
github.com/planetscale/planetscale-go v0.160.0
2929
github.com/planetscale/psdb v0.0.0-20250717190954-65c6661ab6e4
3030
github.com/planetscale/psdbproxy v0.0.0-20250728082226-3f4ea3a74ec7
3131
github.com/spf13/cobra v1.10.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjL
176176
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
177177
github.com/planetscale/noglog v0.2.1-0.20210421230640-bea75fcd2e8e h1:MZ8D+Z3m2vvqGZLvoQfpaGg/j1fNDr4j03s3PRz4rVY=
178178
github.com/planetscale/noglog v0.2.1-0.20210421230640-bea75fcd2e8e/go.mod h1:hwAsSPQdvPa3WcfKfzTXxtEq/HlqwLjQasfO6QbGo4Q=
179-
github.com/planetscale/planetscale-go v0.159.0 h1:qqyZjG/z5k/w5gihfSwxssVu+mIsRTKqXFIeVJa/7hI=
180-
github.com/planetscale/planetscale-go v0.159.0/go.mod h1:paQCI5SgquuoewvMQM7R+r1XJO868bdP6/ihGidYRM0=
179+
github.com/planetscale/planetscale-go v0.160.0 h1:nWgTrMJPk+FzV71OV+wKU17F6DCnSX0lHxHSUH6Yhn0=
180+
github.com/planetscale/planetscale-go v0.160.0/go.mod h1:paQCI5SgquuoewvMQM7R+r1XJO868bdP6/ihGidYRM0=
181181
github.com/planetscale/psdb v0.0.0-20250717190954-65c6661ab6e4 h1:Xv5pj20Rhfty1Tv0OVcidg4ez4PvGrpKvb6rvUwQgDs=
182182
github.com/planetscale/psdb v0.0.0-20250717190954-65c6661ab6e4/go.mod h1:M52h5IWxAcbdQ1hSZrLAGQC4ZXslxEsK/Wh9nu3wdWs=
183183
github.com/planetscale/psdbproxy v0.0.0-20250728082226-3f4ea3a74ec7 h1:aRd6vdE1fyuSI4RVj7oCr8lFmgqXvpnPUmN85VbZCp8=
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package vtctld
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/planetscale/cli/internal/cmdutil"
7+
ps "github.com/planetscale/planetscale-go/planetscale"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
func ListTabletsCmd(ch *cmdutil.Helper) *cobra.Command {
12+
cmd := &cobra.Command{
13+
Use: "list-tablets <database> <branch>",
14+
Short: "List tablets for a branch, grouped by keyspace and shard",
15+
Args: cmdutil.RequiredArgs("database", "branch"),
16+
RunE: func(cmd *cobra.Command, args []string) error {
17+
ctx := cmd.Context()
18+
database, branch := args[0], args[1]
19+
20+
client, err := ch.Client()
21+
if err != nil {
22+
return err
23+
}
24+
25+
end := ch.Printer.PrintProgress(
26+
fmt.Sprintf("Listing tablets on %s\u2026",
27+
progressTarget(ch.Config.Organization, database, branch)))
28+
defer end()
29+
30+
groups, err := client.Vtctld.ListTablets(ctx, &ps.ListBranchTabletsRequest{
31+
Organization: ch.Config.Organization,
32+
Database: database,
33+
Branch: branch,
34+
})
35+
if err != nil {
36+
return cmdutil.HandleError(err)
37+
}
38+
39+
end()
40+
return ch.Printer.PrintJSON(groups)
41+
},
42+
}
43+
44+
return cmd
45+
}

internal/cmd/branch/vtctld/vtctld.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func VtctldCmd(ch *cmdutil.Helper) *cobra.Command {
2020
cmd.AddCommand(PlannedReparentShardCmd(ch))
2121
cmd.AddCommand(ListWorkflowsCmd(ch))
2222
cmd.AddCommand(ListKeyspacesCmd(ch))
23+
cmd.AddCommand(ListTabletsCmd(ch))
2324
cmd.AddCommand(StartWorkflowCmd(ch))
2425
cmd.AddCommand(StopWorkflowCmd(ch))
2526

internal/mock/vtctld_general.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ type VtctldService struct {
1414
ListKeyspacesFn func(context.Context, *ps.VtctldListKeyspacesRequest) (json.RawMessage, error)
1515
ListKeyspacesFnInvoked bool
1616

17+
ListTabletsFn func(context.Context, *ps.ListBranchTabletsRequest) ([]*ps.TabletGroup, error)
18+
ListTabletsFnInvoked bool
19+
1720
StartWorkflowFn func(context.Context, *ps.VtctldStartWorkflowRequest) (json.RawMessage, error)
1821
StartWorkflowFnInvoked bool
1922

@@ -34,6 +37,11 @@ func (s *VtctldService) ListKeyspaces(ctx context.Context, req *ps.VtctldListKey
3437
return s.ListKeyspacesFn(ctx, req)
3538
}
3639

40+
func (s *VtctldService) ListTablets(ctx context.Context, req *ps.ListBranchTabletsRequest) ([]*ps.TabletGroup, error) {
41+
s.ListTabletsFnInvoked = true
42+
return s.ListTabletsFn(ctx, req)
43+
}
44+
3745
func (s *VtctldService) StartWorkflow(ctx context.Context, req *ps.VtctldStartWorkflowRequest) (json.RawMessage, error) {
3846
s.StartWorkflowFnInvoked = true
3947
return s.StartWorkflowFn(ctx, req)

0 commit comments

Comments
 (0)