2023-11-08 18:31:34 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2024-10-19 12:58:00 +00:00
|
|
|
"context"
|
2023-11-08 18:31:34 +00:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"git.faercol.me/faercol/polyculeconnect/polyculeconnect/cmd/utils"
|
2024-10-19 12:58:00 +00:00
|
|
|
"git.faercol.me/faercol/polyculeconnect/polyculeconnect/internal/db"
|
|
|
|
"git.faercol.me/faercol/polyculeconnect/polyculeconnect/logger"
|
2023-11-08 18:31:34 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var appRemoveCmd = &cobra.Command{
|
|
|
|
Use: "remove <app_client_id>",
|
|
|
|
Short: "Remove an app",
|
2024-08-10 14:27:49 +00:00
|
|
|
Long: `Remove the app with the given ID from the database.`,
|
|
|
|
Args: cobra.ExactArgs(1),
|
2023-11-08 18:31:34 +00:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
removeApp(args[0])
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func removeApp(appID string) {
|
2024-10-19 12:58:00 +00:00
|
|
|
c := utils.InitConfig("")
|
|
|
|
logger.Init(c.LogLevel)
|
2023-11-08 18:31:34 +00:00
|
|
|
|
2024-10-19 12:58:00 +00:00
|
|
|
s, err := db.New(*c)
|
|
|
|
if err != nil {
|
|
|
|
utils.Failf("failed to init storage: %s", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := s.ClientStorage().DeleteClient(context.Background(), appID); err != nil {
|
|
|
|
utils.Failf("Failed to remove app: %s", err.Error())
|
2023-11-08 18:31:34 +00:00
|
|
|
}
|
|
|
|
fmt.Println("App deleted")
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
appCmd.AddCommand(appRemoveCmd)
|
|
|
|
}
|