diff --git a/internal/cmd/db_destroy.go b/internal/cmd/db_destroy.go index 39d64a18..1545cef6 100644 --- a/internal/cmd/db_destroy.go +++ b/internal/cmd/db_destroy.go @@ -22,7 +22,7 @@ var destroyCmd = &cobra.Command{ Use: "destroy ", Short: "Destroy a database.", Args: cobra.MinimumNArgs(1), - ValidArgsFunction: dbNameArg, + ValidArgsFunction: dbNameListArg, RunE: func(cmd *cobra.Command, args []string) error { cmd.SilenceUsage = true diff --git a/internal/cmd/utils.go b/internal/cmd/utils.go index d8f38910..ce172c67 100644 --- a/internal/cmd/utils.go +++ b/internal/cmd/utils.go @@ -8,6 +8,7 @@ import ( "net/http" "net/url" "os" + "slices" "strings" "time" @@ -298,6 +299,20 @@ func dbNameArg(cmd *cobra.Command, args []string, toComplete string) ([]string, return []string{}, cobra.ShellCompDirectiveNoFileComp } +func dbNameListArg(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + client, err := authedTursoClient() + if err != nil { + return []string{}, cobra.ShellCompDirectiveNoFileComp + } + var dbNameList = make([]string, 0) + for _, dbName := range getDatabaseNames(client) { + if !slices.Contains(args, dbName) { + dbNameList = append(dbNameList, dbName) + } + } + return dbNameList, cobra.ShellCompDirectiveNoFileComp +} + func dbNameAndOrgArgs(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { client, err := authedTursoClient() if err != nil {