mirror of
https://github.com/coollabsio/coolify-cli.git
synced 2026-06-19 07:35:04 +00:00
60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package env
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/coollabsio/coolify-cli/internal/cli"
|
|
"github.com/coollabsio/coolify-cli/internal/service"
|
|
)
|
|
|
|
func NewDeleteEnvCommand() *cobra.Command {
|
|
deleteEnvCmd := &cobra.Command{
|
|
Use: "delete <app_uuid> <env_uuid>",
|
|
Short: "Delete an environment variable",
|
|
Long: `Delete an environment variable from an application. First UUID is the application, second is the specific environment variable to delete.`,
|
|
Args: cli.ExactArgs(2, "<uuid1> <uuid2>"),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
ctx := cmd.Context()
|
|
appUUID := args[0]
|
|
envUUID := args[1]
|
|
|
|
client, err := cli.GetAPIClient(cmd)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to get API client: %w", err)
|
|
}
|
|
|
|
force, _ := cmd.Flags().GetBool("force")
|
|
|
|
// Prompt for confirmation unless --force is used
|
|
if !force {
|
|
var response string
|
|
fmt.Printf("Are you sure you want to delete this environment variable? (yes/no): ")
|
|
_, err := fmt.Scanln(&response)
|
|
|
|
if err != nil {
|
|
return fmt.Errorf("failed to read confirmation: %w", err)
|
|
}
|
|
|
|
if response != "yes" && response != "y" {
|
|
fmt.Println("Delete cancelled.")
|
|
return nil
|
|
}
|
|
}
|
|
|
|
appSvc := service.NewApplicationService(client)
|
|
err = appSvc.DeleteEnv(ctx, appUUID, envUUID)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to delete environment variable: %w", err)
|
|
}
|
|
|
|
fmt.Println("Environment variable deleted successfully.")
|
|
return nil
|
|
},
|
|
}
|
|
|
|
deleteEnvCmd.Flags().Bool("force", false, "Skip confirmation prompt")
|
|
return deleteEnvCmd
|
|
}
|