Skip to content

Commit 064cb71

Browse files
Merge pull request #1091 from planetscale/show-database-kind
Vitess vs Postgres command docs
2 parents 34eb0c2 + 48008a1 commit 064cb71

12 files changed

Lines changed: 137 additions & 49 deletions

File tree

internal/cmd/completion.go

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@ import (
77
"github.com/spf13/cobra"
88
)
99

10-
func init() {
11-
rootCmd.AddCommand(completionCmd)
12-
}
13-
14-
var completionCmd = &cobra.Command{
15-
Use: "completion [bash|zsh|fish|powershell]",
16-
Short: "Generate completion script for your shell",
17-
Long: `To load completions:
10+
func CompletionCmd() *cobra.Command {
11+
return &cobra.Command{
12+
Use: "completion [bash|zsh|fish|powershell]",
13+
Short: "Generate completion script for your shell",
14+
Long: `To load completions:
1815
1916
Bash:
2017
@@ -53,19 +50,20 @@ PowerShell:
5350
PS> pscale completion powershell > pscale.ps1
5451
# and source this file from your PowerShell profile.
5552
`,
56-
DisableFlagsInUseLine: true,
57-
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
58-
Args: cmdutil.RequiredArgs("shell"),
59-
Run: func(cmd *cobra.Command, args []string) {
60-
switch args[0] {
61-
case "bash":
62-
cmd.Root().GenBashCompletion(os.Stdout)
63-
case "zsh":
64-
cmd.Root().GenZshCompletion(os.Stdout)
65-
case "fish":
66-
cmd.Root().GenFishCompletion(os.Stdout, true)
67-
case "powershell":
68-
cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout)
69-
}
70-
},
53+
DisableFlagsInUseLine: true,
54+
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
55+
Args: cmdutil.RequiredArgs("shell"),
56+
Run: func(cmd *cobra.Command, args []string) {
57+
switch args[0] {
58+
case "bash":
59+
cmd.Root().GenBashCompletion(os.Stdout)
60+
case "zsh":
61+
cmd.Root().GenZshCompletion(os.Stdout)
62+
case "fish":
63+
cmd.Root().GenFishCompletion(os.Stdout, true)
64+
case "powershell":
65+
cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout)
66+
}
67+
},
68+
}
7169
}

internal/cmd/connect/connect.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func ConnectCmd(ch *cmdutil.Helper) *cobra.Command {
4444
// we only require database, because we deduct branch automatically
4545
Args: cmdutil.RequiredArgs("database"),
4646
Short: "Create a secure connection to a database and branch for a local client",
47+
Long: "Create a secure connection to a database and branch for a local client.\n\nThis command is only supported for Vitess databases.",
4748
Example: `The connect subcommand establishes a secure connection between your host and PlanetScale.
4849
4950
By default, if no branch names are given and there is only one branch, it

internal/cmd/database/dump.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ func DumpCmd(ch *cmdutil.Helper) *cobra.Command {
4444
f := &dumpFlags{}
4545
cmd := &cobra.Command{
4646
Use: "dump <database> <branch> [options]",
47-
Short: "Backup and dump your database",
47+
Short: "Backup and dump your database (Vitess databases only)",
48+
Long: "Backup and dump your database.\n\nThis command is only supported for Vitess databases. For Postgres databases, use standard PostgreSQL tools like pg_dump. See: https://planetscale.com/docs/postgres/imports/postgres-migrate-dumprestore",
4849
Args: cmdutil.RequiredArgs("database", "branch"),
4950
RunE: func(cmd *cobra.Command, args []string) error { return dump(ch, cmd, f, args) },
5051
}

internal/cmd/database/restore.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ func RestoreCmd(ch *cmdutil.Helper) *cobra.Command {
3939
f := &restoreFlags{}
4040
cmd := &cobra.Command{
4141
Use: "restore-dump <database> <branch> [options]",
42-
Short: "Restore your database from a local dump directory",
42+
Short: "Restore your database from a local dump directory (Vitess databases only)",
43+
Long: "Restore your database from a local dump directory.\n\nThis command is only supported for Vitess databases. For Postgres databases, use standard PostgreSQL tools like pg_restore. See: https://planetscale.com/docs/postgres/imports/postgres-migrate-dumprestore",
4344
Args: cmdutil.RequiredArgs("database", "branch"),
4445
RunE: func(cmd *cobra.Command, args []string) error { return restore(ch, cmd, f, args) },
4546
}

internal/cmd/dataimports/dataimports.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ func DataImportsCmd(ch *cmdutil.Helper) *cobra.Command {
1010
cmd := &cobra.Command{
1111
Use: "data-imports <command>",
1212
Short: "Create, list, and delete branch data imports",
13+
Long: "Create, list, and delete branch data imports.\n\nThis command is only supported for Vitess databases.",
1314
PersistentPreRunE: cmdutil.CheckAuthentication(ch.Config),
1415
}
1516

internal/cmd/deployrequest/dr.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ func DeployRequestCmd(ch *cmdutil.Helper) *cobra.Command {
1616
cmd := &cobra.Command{
1717
Use: "deploy-request <command>",
1818
Short: "Create, review, diff, revert, and manage deploy requests",
19+
Long: "Create, review, diff, revert, and manage deploy requests.\n\nThis command is only supported for Vitess databases.",
1920
Aliases: []string{"dr"},
2021
PersistentPreRunE: cmdutil.CheckAuthentication(ch.Config),
2122
}
@@ -79,9 +80,9 @@ func formatTimestamp(t *time.Time) string {
7980
if t == nil || t.IsZero() {
8081
return ""
8182
}
82-
83+
8384
duration := time.Since(*t)
84-
85+
8586
switch {
8687
case duration < time.Minute:
8788
return "less than a minute ago"

internal/cmd/keyspace/keyspace.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ func KeyspaceCmd(ch *cmdutil.Helper) *cobra.Command {
1313
cmd := &cobra.Command{
1414
Use: "keyspace <command>",
1515
Short: "List, show, and manage keyspaces",
16+
Long: "List, show, and manage keyspaces.\n\nThis command is only supported for Vitess databases.",
1617
PersistentPreRunE: cmdutil.CheckAuthentication(ch.Config),
1718
}
1819

internal/cmd/password/password.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func PasswordCmd(ch *cmdutil.Helper) *cobra.Command {
1717
cmd := &cobra.Command{
1818
Use: "password <command>",
1919
Short: "Create, list, and delete branch passwords",
20+
Long: "Create, list, and delete branch passwords.\n\nThis command is only supported for Vitess databases.",
2021
PersistentPreRunE: cmdutil.CheckAuthentication(ch.Config),
2122
}
2223

internal/cmd/role/role.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ func RoleCmd(ch *cmdutil.Helper) *cobra.Command {
99
cmd := &cobra.Command{
1010
Use: "role",
1111
Short: "Manage database roles for a Postgres database branch",
12+
Long: "Manage database roles for a Postgres database branch.\n\nThis command is only supported for Postgres databases.",
1213
PersistentPreRunE: cmdutil.CheckAuthentication(ch.Config),
1314
}
1415

internal/cmd/root.go

Lines changed: 102 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -205,35 +205,115 @@ func runCmd(ctx context.Context, ver, commit, buildDate string, format *printer.
205205
// We don't want to show the default value
206206
rootCmd.PersistentFlags().Lookup("api-token").DefValue = ""
207207

208+
// Add command groups for better organization
209+
rootCmd.AddGroup(&cobra.Group{ID: "database", Title: printer.Bold("Database management:")})
210+
rootCmd.AddGroup(&cobra.Group{ID: "vitess", Title: printer.Bold("Vitess-specific commands:")})
211+
rootCmd.AddGroup(&cobra.Group{ID: "postgres", Title: printer.Bold("Postgres-specific commands:")})
212+
rootCmd.AddGroup(&cobra.Group{ID: "platform", Title: printer.Bold("Platform & account management:")})
213+
208214
loginCmd := auth.LoginCmd(ch)
209215
loginCmd.Hidden = true
210216
logoutCmd := auth.LogoutCmd(ch)
211217
logoutCmd.Hidden = true
212218

213219
rootCmd.AddCommand(loginCmd)
214220
rootCmd.AddCommand(logoutCmd)
215-
rootCmd.AddCommand(api.ApiCmd(ch, userAgent, headers))
216-
rootCmd.AddCommand(auditlog.AuditLogCmd(ch))
217-
rootCmd.AddCommand(auth.AuthCmd(ch))
218-
rootCmd.AddCommand(backup.BackupCmd(ch))
219-
rootCmd.AddCommand(branch.BranchCmd(ch))
220-
rootCmd.AddCommand(connect.ConnectCmd(ch))
221-
rootCmd.AddCommand(database.DatabaseCmd(ch))
222-
rootCmd.AddCommand(dataimports.DataImportsCmd(ch))
223-
rootCmd.AddCommand(deployrequest.DeployRequestCmd(ch))
224-
rootCmd.AddCommand(keyspace.KeyspaceCmd(ch))
225-
rootCmd.AddCommand(mcp.McpCmd(ch))
226-
rootCmd.AddCommand(org.OrgCmd(ch))
227-
rootCmd.AddCommand(password.PasswordCmd(ch))
228-
rootCmd.AddCommand(ping.PingCmd(ch))
229-
rootCmd.AddCommand(region.RegionCmd(ch))
230-
rootCmd.AddCommand(shell.ShellCmd(ch, sigc, signals...))
231-
rootCmd.AddCommand(signup.SignupCmd(ch))
232-
rootCmd.AddCommand(size.SizeCmd(ch))
233-
rootCmd.AddCommand(token.TokenCmd(ch))
234-
rootCmd.AddCommand(version.VersionCmd(ch, ver, commit, buildDate))
235-
rootCmd.AddCommand(workflow.WorkflowCmd(ch))
236-
rootCmd.AddCommand(role.RoleCmd(ch))
221+
222+
// Platform & Account Management commands
223+
apiCmd := api.ApiCmd(ch, userAgent, headers)
224+
apiCmd.GroupID = "platform"
225+
rootCmd.AddCommand(apiCmd)
226+
227+
auditlogCmd := auditlog.AuditLogCmd(ch)
228+
auditlogCmd.GroupID = "platform"
229+
rootCmd.AddCommand(auditlogCmd)
230+
231+
authCmd := auth.AuthCmd(ch)
232+
authCmd.GroupID = "platform"
233+
rootCmd.AddCommand(authCmd)
234+
235+
completionCmd := CompletionCmd()
236+
completionCmd.GroupID = "platform"
237+
rootCmd.AddCommand(completionCmd)
238+
239+
mcpCmd := mcp.McpCmd(ch)
240+
mcpCmd.GroupID = "platform"
241+
rootCmd.AddCommand(mcpCmd)
242+
243+
orgCmd := org.OrgCmd(ch)
244+
orgCmd.GroupID = "platform"
245+
rootCmd.AddCommand(orgCmd)
246+
247+
pingCmd := ping.PingCmd(ch)
248+
pingCmd.GroupID = "platform"
249+
rootCmd.AddCommand(pingCmd)
250+
251+
regionCmd := region.RegionCmd(ch)
252+
regionCmd.GroupID = "platform"
253+
rootCmd.AddCommand(regionCmd)
254+
255+
signupCmd := signup.SignupCmd(ch)
256+
signupCmd.GroupID = "platform"
257+
rootCmd.AddCommand(signupCmd)
258+
259+
sizeCmd := size.SizeCmd(ch)
260+
sizeCmd.GroupID = "platform"
261+
rootCmd.AddCommand(sizeCmd)
262+
263+
tokenCmd := token.TokenCmd(ch)
264+
tokenCmd.GroupID = "platform"
265+
rootCmd.AddCommand(tokenCmd)
266+
267+
versionCmd := version.VersionCmd(ch, ver, commit, buildDate)
268+
versionCmd.GroupID = "platform"
269+
rootCmd.AddCommand(versionCmd)
270+
271+
// Database management commands (Both databases)
272+
backupCmd := backup.BackupCmd(ch)
273+
backupCmd.GroupID = "database"
274+
rootCmd.AddCommand(backupCmd)
275+
276+
branchCmd := branch.BranchCmd(ch)
277+
branchCmd.GroupID = "database"
278+
rootCmd.AddCommand(branchCmd)
279+
280+
databaseCmd := database.DatabaseCmd(ch)
281+
databaseCmd.GroupID = "database"
282+
rootCmd.AddCommand(databaseCmd)
283+
284+
// Vitess-specific commands
285+
connectCmd := connect.ConnectCmd(ch)
286+
connectCmd.GroupID = "vitess"
287+
rootCmd.AddCommand(connectCmd)
288+
289+
dataimportsCmd := dataimports.DataImportsCmd(ch)
290+
dataimportsCmd.GroupID = "vitess"
291+
rootCmd.AddCommand(dataimportsCmd)
292+
293+
deployRequestCmd := deployrequest.DeployRequestCmd(ch)
294+
deployRequestCmd.GroupID = "vitess"
295+
rootCmd.AddCommand(deployRequestCmd)
296+
297+
keyspaceCmd := keyspace.KeyspaceCmd(ch)
298+
keyspaceCmd.GroupID = "vitess"
299+
rootCmd.AddCommand(keyspaceCmd)
300+
301+
passwordCmd := password.PasswordCmd(ch)
302+
passwordCmd.GroupID = "vitess"
303+
rootCmd.AddCommand(passwordCmd)
304+
305+
shellCmd := shell.ShellCmd(ch, sigc, signals...)
306+
shellCmd.GroupID = "vitess"
307+
rootCmd.AddCommand(shellCmd)
308+
309+
workflowCmd := workflow.WorkflowCmd(ch)
310+
workflowCmd.GroupID = "vitess"
311+
rootCmd.AddCommand(workflowCmd)
312+
313+
// Postgres-specific commands
314+
roleCmd := role.RoleCmd(ch)
315+
roleCmd.GroupID = "postgres"
316+
rootCmd.AddCommand(roleCmd)
237317

238318
return rootCmd.ExecuteContext(ctx)
239319
}

0 commit comments

Comments
 (0)