Repository: supabase/cli
Pull request #563 (2022-10-27 06:04:06)

fix: group cli commands help text
## What kind of change does this PR introduce?

docs update

## What is the current behavior?

too many commands in root, making help text look messy

## What is the new behavior?

group commands by their use case

## Additional context

```
$ supabase help
Supabase CLI

Usage:
  supabase [command]

Local Development:
  db                Manage local Postgres databases
  gen               Run code generation tools
  init              Initialize a local project
  link              Link to a Supabase project
  login             Authenticate using an access token
  migration         Manage database migration scripts
  start             Start containers for Supabase local development
  status            Show status of local Supabase containers
  stop              Stop all local Supabase containers
  test              Run tests on local Supabase containers

Management APIs:
  domains           Manage custom domain names for Supabase projects
  functions         Manage Supabase Edge functions
  orgs              Manage Supabase organizations
  projects          Manage Supabase projects
  secrets           Manage Supabase secrets

Additional Commands:
  completion        Generate the autocompletion script for the specified shell
  help              Help about any command

Flags:
      --debug            output debug logs to stderr
      --experimental     enable experimental features
  -h, --help             help for supabase
      --workdir string   path to a Supabase project directory

Use "supabase [command] --help" for more information about a command.
```


coveralls: ## Pull Request Test Coverage Report for [Build 3334906347](https://coveralls.io/builds/53650061)

* **4** of **4**   **(100.0%)**  changed or added relevant lines in **1** file are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage increased (+**0.04%**) to **48.804%**

---



|  Totals | [![Coverage Status](https://coveralls.io/builds/53650061/badge)](https://coveralls.io/builds/53650061) |
| :-- | --: |
| Change from base [Build 3334281468](https://coveralls.io/builds/53647517): |  0.04% |
| Covered Lines: | 2652 |
| Relevant Lines: | 5434 |

---
##### 💛  - [Coveralls](https://coveralls.io)


Patch:
diff --git a/cmd/db.go b/cmd/db.go
index 2a4ca43c..5f72427e 100644
--- a/cmd/db.go
+++ b/cmd/db.go
@@ -23,8 +23,9 @@ import (
 
 var (
 	dbCmd = &cobra.Command{
-		Use:   "db",
-		Short: "Manage local Postgres databases",
+		GroupID: groupLocalDev,
+		Use:     "db",
+		Short:   "Manage local Postgres databases",
 	}
 
 	dbBranchCmd = &cobra.Command{
diff --git a/cmd/customHostname.go b/cmd/domains.go
similarity index 96%
rename from cmd/customHostname.go
rename to cmd/domains.go
index 48c20ed2..68fc842f 100644
--- a/cmd/customHostname.go
+++ b/cmd/domains.go
@@ -16,8 +16,9 @@ import (
 
 var (
 	customHostnamesCmd = &cobra.Command{
-		Use:   "custom-hostname",
-		Short: "Manage custom hostnames for Supabase projects",
+		GroupID: groupManagementAPI,
+		Use:     "domains",
+		Short:   "Manage custom domain names for Supabase projects",
 		PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
 			if !experimental {
 				return errors.New("must set the --experimental flag to run this command")
diff --git a/cmd/functions.go b/cmd/functions.go
index 0b6b003f..4c53e17e 100644
--- a/cmd/functions.go
+++ b/cmd/functions.go
@@ -20,8 +20,9 @@ import (
 
 var (
 	functionsCmd = &cobra.Command{
-		Use:   "functions",
-		Short: "Manage Supabase Edge functions",
+		GroupID: groupManagementAPI,
+		Use:     "functions",
+		Short:   "Manage Supabase Edge functions",
 	}
 
 	projectRef string
diff --git a/cmd/gen.go b/cmd/gen.go
index dfeda0ee..5630c862 100644
--- a/cmd/gen.go
+++ b/cmd/gen.go
@@ -12,8 +12,9 @@ import (
 
 var (
 	genCmd = &cobra.Command{
-		Use:   "gen",
-		Short: "Run code generation tools",
+		GroupID: groupLocalDev,
+		Use:     "gen",
+		Short:   "Run code generation tools",
 	}
 
 	genTypesCmd = &cobra.Command{
diff --git a/cmd/init.go b/cmd/init.go
index a9b85038..b2341326 100644
--- a/cmd/init.go
+++ b/cmd/init.go
@@ -10,8 +10,9 @@ import (
 )
 
 var initCmd = &cobra.Command{
-	Use:   "init",
-	Short: "Initialize a local project",
+	GroupID: groupLocalDev,
+	Use:     "init",
+	Short:   "Initialize a local project",
 	RunE: func(cmd *cobra.Command, args []string) error {
 		fsys := afero.NewOsFs()
 		if err := _init.Run(fsys); err != nil {
diff --git a/cmd/link.go b/cmd/link.go
index 915485b9..168c6a09 100644
--- a/cmd/link.go
+++ b/cmd/link.go
@@ -19,8 +19,9 @@ var (
 	username = "postgres"
 
 	linkCmd = &cobra.Command{
-		Use:   "link",
-		Short: "Link to a Supabase project",
+		GroupID: groupLocalDev,
+		Use:     "link",
+		Short:   "Link to a Supabase project",
 		RunE: func(cmd *cobra.Command, args []string) error {
 			projectRef, err := cmd.Flags().GetString("project-ref")
 			if err != nil {
diff --git a/cmd/login.go b/cmd/login.go
index 68e435c6..03bad385 100644
--- a/cmd/login.go
+++ b/cmd/login.go
@@ -12,8 +12,9 @@ import (
 
 var (
 	loginCmd = &cobra.Command{
-		Use:   "login",
-		Short: "Authenticate using an access token",
+		GroupID: groupLocalDev,
+		Use:     "login",
+		Short:   "Authenticate using an access token",
 		RunE: func(cmd *cobra.Command, args []string) error {
 			if err := login.Run(os.Stdin, afero.NewOsFs()); err != nil {
 				return err
diff --git a/cmd/migration.go b/cmd/migration.go
index 4d99e976..a74e33b2 100644
--- a/cmd/migration.go
+++ b/cmd/migration.go
@@ -12,8 +12,9 @@ import (
 
 var (
 	migrationCmd = &cobra.Command{
-		Use:   "migration",
-		Short: "Manage database migration scripts",
+		GroupID: groupLocalDev,
+		Use:     "migration",
+		Short:   "Manage database migration scripts",
 	}
 
 	migrationListCmd = &cobra.Command{
diff --git a/cmd/orgs.go b/cmd/orgs.go
index 7eda00f8..0502add4 100644
--- a/cmd/orgs.go
+++ b/cmd/orgs.go
@@ -8,8 +8,9 @@ import (
 
 var (
 	orgsCmd = &cobra.Command{
-		Use:   "orgs",
-		Short: "Manage Supabase organizations",
+		GroupID: groupManagementAPI,
+		Use:     "orgs",
+		Short:   "Manage Supabase organizations",
 	}
 
 	orgsListCmd = &cobra.Command{
diff --git a/cmd/projects.go b/cmd/projects.go
index f10d32cc..baeee21c 100644
--- a/cmd/projects.go
+++ b/cmd/projects.go
@@ -17,8 +17,9 @@ import (
 
 var (
 	projectsCmd = &cobra.Command{
-		Use:   "projects",
-		Short: "Manage Supabase projects",
+		GroupID: groupManagementAPI,
+		Use:     "projects",
+		Short:   "Manage Supabase projects",
 	}
 
 	interactive bool
diff --git a/cmd/root.go b/cmd/root.go
index cff01451..e32543ef 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -12,6 +12,11 @@ import (
 	"github.com/supabase/cli/internal/utils"
 )
 
+const (
+	groupLocalDev      = "local-dev"
+	groupManagementAPI = "management-api"
+)
+
 var (
 	// Passed from `-ldflags`: https://stackoverflow.com/q/11354518.
 	version      string
@@ -68,6 +73,8 @@ func init() {
 	flags.BoolVar(&experimental, "experimental", false, "enable experimental features")
 
 	rootCmd.SetVersionTemplate("{{.Version}}\n")
+	rootCmd.AddGroup(&cobra.Group{ID: groupLocalDev, Title: "Local Development:"})
+	rootCmd.AddGroup(&cobra.Group{ID: groupManagementAPI, Title: "Management APIs:"})
 }
 
 // instantiate new rootCmd is a bit tricky with cobra, but it can be done later with the following
diff --git a/cmd/secrets.go b/cmd/secrets.go
index abb6e824..dece7e30 100644
--- a/cmd/secrets.go
+++ b/cmd/secrets.go
@@ -13,8 +13,9 @@ import (
 
 var (
 	secretsCmd = &cobra.Command{
-		Use:   "secrets",
-		Short: "Manage Supabase secrets",
+		GroupID: groupManagementAPI,
+		Use:     "secrets",
+		Short:   "Manage Supabase secrets",
 	}
 
 	secretsListCmd = &cobra.Command{
diff --git a/cmd/start.go b/cmd/start.go
index 159bf295..07d0f67f 100644
--- a/cmd/start.go
+++ b/cmd/start.go
@@ -7,8 +7,9 @@ import (
 )
 
 var startCmd = &cobra.Command{
-	Use:   "start",
-	Short: "Start containers for Supabase local development",
+	GroupID: groupLocalDev,
+	Use:     "start",
+	Short:   "Start containers for Supabase local development",
 	RunE: func(cmd *cobra.Command, args []string) error {
 		return start.Run(cmd.Context(), afero.NewOsFs())
 	},
diff --git a/cmd/status.go b/cmd/status.go
index 90ec3b68..32cda0f7 100644
--- a/cmd/status.go
+++ b/cmd/status.go
@@ -10,8 +10,9 @@ import (
 )
 
 var statusCmd = &cobra.Command{
-	Use:   "status",
-	Short: "Show status of local Supabase containers",
+	GroupID: groupLocalDev,
+	Use:     "status",
+	Short:   "Show status of local Supabase containers",
 	RunE: func(cmd *cobra.Command, args []string) error {
 		ctx, _ := signal.NotifyContext(cmd.Context(), os.Interrupt)
 		return status.Run(ctx, afero.NewOsFs())
diff --git a/cmd/stop.go b/cmd/stop.go
index 11ec77a8..faf15afb 100644
--- a/cmd/stop.go
+++ b/cmd/stop.go
@@ -13,8 +13,9 @@ var (
 	backup bool
 
 	stopCmd = &cobra.Command{
-		Use:   "stop",
-		Short: "Stop all local Supabase containers",
+		GroupID: groupLocalDev,
+		Use:     "stop",
+		Short:   "Stop all local Supabase containers",
 		RunE: func(cmd *cobra.Command, args []string) error {
 			ctx, _ := signal.NotifyContext(cmd.Context(), os.Interrupt)
 			return stop.Run(ctx, backup, afero.NewOsFs())


Test patch:
diff --git a/cmd/test.go b/cmd/test.go
index 546acb65..5f315669 100644
--- a/cmd/test.go
+++ b/cmd/test.go
@@ -6,8 +6,9 @@ import (
 
 var (
 	testCmd = &cobra.Command{
-		Use:   "test",
-		Short: "Run tests for local project",
+		GroupID: groupLocalDev,
+		Use:     "test",
+		Short:   "Run tests on local Supabase containers",
 	}
 
 	testDbCmd = &cobra.Command{