Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- move detection to https://github.com/coollabsio/coolpack

- Env vars should use `--prod` to delete prod, instead of deleting prod by default and using `--preview` to delete preview
- Env vars should use `--prod` to delete prod, instead of deleting prod by default and using `--preview` to delete preview - DONE
- Fix spacing issues (use debug flag `CDP_DEBUG=1 cdp`) to see where it is coming from
- **BIG THING:** allow preview deployments with git setup
- For Docker this cannot work, but git deploys should set up Coolify to work with GitHub PRs on the deploy repo
Expand Down
32 changes: 30 additions & 2 deletions cmd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func init() {
envCmd.AddCommand(envPullCmd)
envCmd.AddCommand(envPushCmd)

// Add --preview flag for env commands to target preview deployments (from PRs)
envCmd.PersistentFlags().BoolVar(&previewFlag, "preview", false, "Target preview deployments (from Pull Requests)")
envCmd.PersistentFlags().BoolVar(&prodFlag, "prod", false, "Target production deployment (from Pull Requests)")
Comment thread
scooterthedev marked this conversation as resolved.
Outdated
}

func getAppUUID() (string, *api.Client, error) {
Expand Down Expand Up @@ -163,7 +163,11 @@ func runEnvAdd(cmd *cobra.Command, args []string) error {
return err
}

// Set is_preview based on flag
if prodFlag && previewFlag {
ui.Error("Cannot use both --prod and --preview")
return fmt.Errorf("conflicting flags")
}

Comment thread
scooterthedev marked this conversation as resolved.
isPreview := previewFlag

ui.Info(fmt.Sprintf("Adding %s...", key))
Expand All @@ -189,6 +193,20 @@ func runEnvRm(cmd *cobra.Command, args []string) error {
return err
}

if !prodFlag && !previewFlag {
ui.Error("Must use either --prod or --preview flag")
ui.Spacer()
ui.Print("Examples:")
ui.Print(" " + ui.CodeStyle.Render(fmt.Sprintf("%s env rm KEY --prod", execName())))
ui.Print(" " + ui.CodeStyle.Render(fmt.Sprintf("%s env rm KEY --preview", execName())))
return fmt.Errorf("deployment type not specified")
}

if prodFlag && previewFlag {
ui.Error("Cannot use both --prod and --preview")
return fmt.Errorf("conflicting flags")
}

// Confirm deletion
confirmed, err := ui.ConfirmAction("remove environment variable", key)
if err != nil {
Expand Down Expand Up @@ -246,6 +264,11 @@ func runEnvPull(cmd *cobra.Command, args []string) error {
return err
}

if prodFlag && previewFlag {
ui.Error("Cannot use both --prod and --preview")
return fmt.Errorf("conflicting flags")
}
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The runEnvPull function doesn't check if neither --prod nor --preview is specified, unlike runEnvRm. This creates inconsistent behavior - runEnvPull will default to production when no flag is specified, while runEnvRm requires an explicit flag. For consistency and to prevent accidental production operations, runEnvPull should also require an explicit flag specification.

Suggested change
}
}
if !prodFlag && !previewFlag {
ui.Error("Please specify either --prod or --preview")
return fmt.Errorf("no environment specified")
}

Copilot uses AI. Check for mistakes.

deploymentType := "production"
if previewFlag {
deploymentType = "preview"
Expand Down Expand Up @@ -316,6 +339,11 @@ func runEnvPush(cmd *cobra.Command, args []string) error {
return err
}

if prodFlag && previewFlag {
ui.Error("Cannot use both --prod and --preview")
return fmt.Errorf("conflicting flags")
}
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The runEnvPush function doesn't check if neither --prod nor --preview is specified, unlike runEnvRm. This creates inconsistent behavior - runEnvPush will default to production when no flag is specified, while runEnvRm requires an explicit flag. For consistency and to prevent accidental production operations, runEnvPush should also require an explicit flag specification.

Suggested change
}
}
if !prodFlag && !previewFlag {
ui.Error("You must specify either --prod or --preview")
return fmt.Errorf("missing required environment flag")
}

Copilot uses AI. Check for mistakes.

deploymentType := "production"
if previewFlag {
deploymentType = "preview"
Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var (

// Flags for env command
previewFlag bool
prodFlag bool

// Global verbose flag
verboseFlag bool
Expand Down