From 146ce7a7b0b3152ed97e91b51ba59298bb75ccbe Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Mon, 23 Mar 2026 11:16:47 +0100 Subject: [PATCH 1/2] feat(env): allow updating vars by UUID or key identifier Add support for identifying environment variables by UUID or key name in update commands, eliminating the requirement to use --key for lookups. Commands now accept as a positional argument to identify the variable, with --key becoming optional for renaming only. Applied to app, database, and service env update commands and updated documentation. --- README.md | 8 ++--- cmd/application/env/create.go | 2 +- cmd/application/env/update.go | 27 ++++++++++------ cmd/database/env/create.go | 4 +-- cmd/database/env/update.go | 27 ++++++++++------ cmd/service/env/create.go | 4 +-- cmd/service/env/update.go | 28 ++++++++++------ llms.txt | 60 +++++++++++++++++------------------ 8 files changed, 93 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index 9c159ef..f36a5cd 100644 --- a/README.md +++ b/README.md @@ -149,9 +149,9 @@ Commands can use `server` or `servers` interchangeably. - `--build-time` - Available at build time - `--is-literal` - Treat value as literal (don't interpolate variables) - `--is-multiline` - Value is multiline -- `coolify app env update ` - Update an environment variable - - `--key ` - Variable key (required) +- `coolify app env update ` - Update an environment variable - `--value ` - Variable value (required) + - `--key ` - New variable key (optional, for renaming) - `--preview` - Available in preview deployments - `--build-time` - Available at build time - `--is-literal` - Treat value as literal (don't interpolate variables) @@ -239,9 +239,9 @@ Commands can use `server` or `servers` interchangeably. - `coolify service env get ` - Get a specific environment variable - `coolify service env create ` - Create a new environment variable - Same flags as application environment variables -- `coolify service env update ` - Update an environment variable - - `--key ` - Variable key (required) +- `coolify service env update ` - Update an environment variable - `--value ` - Variable value (required) + - `--key ` - New variable key (optional, for renaming) - `--build-time` - Available at build time - `--is-literal` - Treat value as literal (don't interpolate variables) - `--is-multiline` - Value is multiline diff --git a/cmd/application/env/create.go b/cmd/application/env/create.go index 72df55a..96d2333 100644 --- a/cmd/application/env/create.go +++ b/cmd/application/env/create.go @@ -71,7 +71,7 @@ func NewCreateEnvCommand() *cobra.Command { return fmt.Errorf("failed to create environment variable: %w", err) } - fmt.Printf("Environment variable '%s' created successfully.\n", env.Key) + fmt.Printf("Environment variable '%s' created successfully.\n", key) fmt.Printf("UUID: %s\n", env.UUID) return nil }, diff --git a/cmd/application/env/update.go b/cmd/application/env/update.go index 70d858f..ad7dd68 100644 --- a/cmd/application/env/update.go +++ b/cmd/application/env/update.go @@ -12,13 +12,14 @@ import ( func NewUpdateEnvCommand() *cobra.Command { cmd := &cobra.Command{ - Use: "update ", + Use: "update ", Short: "Update an environment variable", - Long: `Update an existing environment variable. UUID is the application.`, - Args: cli.ExactArgs(1, ""), + Long: `Update an existing environment variable. Identify it by UUID or key name.`, + Args: cli.ExactArgs(2, " "), RunE: func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() appUUID := args[0] + envIdentifier := args[1] client, err := cli.GetAPIClient(cmd) if err != nil { @@ -30,12 +31,24 @@ func NewUpdateEnvCommand() *cobra.Command { return err } + appSvc := service.NewApplicationService(client) + + // Look up the env var to resolve its key + existingEnv, err := appSvc.GetEnv(ctx, appUUID, envIdentifier) + if err != nil { + return fmt.Errorf("failed to find environment variable '%s': %w", envIdentifier, err) + } + req := &models.EnvironmentVariableUpdateRequest{} + // Use existing key unless --key flag explicitly provides a new one if cmd.Flags().Changed("key") { key, _ := cmd.Flags().GetString("key") req.Key = &key + } else { + req.Key = &existingEnv.Key } + if cmd.Flags().Changed("value") { value, _ := cmd.Flags().GetString("value") req.Value = &value @@ -65,14 +78,10 @@ func NewUpdateEnvCommand() *cobra.Command { req.Comment = &comment } - if req.Key == nil { - return fmt.Errorf("--key is required") - } if req.Value == nil { return fmt.Errorf("--value is required") } - appSvc := service.NewApplicationService(client) env, err := appSvc.UpdateEnv(ctx, appUUID, req) if err != nil { return fmt.Errorf("failed to update environment variable: %w", err) @@ -83,8 +92,8 @@ func NewUpdateEnvCommand() *cobra.Command { }, } - cmd.Flags().String("key", "", "New environment variable key") - cmd.Flags().String("value", "", "New environment variable value") + cmd.Flags().String("key", "", "New environment variable key (rename)") + cmd.Flags().String("value", "", "New environment variable value (required)") cmd.Flags().Bool("build-time", true, "Available at build time (default: true)") cmd.Flags().Bool("preview", false, "Available in preview deployments") cmd.Flags().Bool("is-literal", false, "Treat value as literal") diff --git a/cmd/database/env/create.go b/cmd/database/env/create.go index 576f10a..f1279a4 100644 --- a/cmd/database/env/create.go +++ b/cmd/database/env/create.go @@ -58,12 +58,12 @@ func NewCreateCommand() *cobra.Command { } dbSvc := service.NewDatabaseService(client) - env, err := dbSvc.CreateEnv(ctx, uuid, req) + _, err = dbSvc.CreateEnv(ctx, uuid, req) if err != nil { return fmt.Errorf("failed to create environment variable: %w", err) } - fmt.Printf("Environment variable '%s' created successfully.\n", env.Key) + fmt.Printf("Environment variable '%s' created successfully.\n", key) return nil }, } diff --git a/cmd/database/env/update.go b/cmd/database/env/update.go index b063c07..19cf725 100644 --- a/cmd/database/env/update.go +++ b/cmd/database/env/update.go @@ -12,13 +12,14 @@ import ( func NewUpdateCommand() *cobra.Command { cmd := &cobra.Command{ - Use: "update ", + Use: "update ", Short: "Update an environment variable", - Long: `Update an existing environment variable. UUID is the database.`, - Args: cli.ExactArgs(1, ""), + Long: `Update an existing environment variable. Identify it by UUID or key name.`, + Args: cli.ExactArgs(2, " "), RunE: func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() dbUUID := args[0] + envIdentifier := args[1] client, err := cli.GetAPIClient(cmd) if err != nil { @@ -30,12 +31,24 @@ func NewUpdateCommand() *cobra.Command { return err } + dbSvc := service.NewDatabaseService(client) + + // Look up the env var to resolve its key + existingEnv, err := dbSvc.GetEnv(ctx, dbUUID, envIdentifier) + if err != nil { + return fmt.Errorf("failed to find environment variable '%s': %w", envIdentifier, err) + } + req := &models.DatabaseEnvironmentVariableUpdateRequest{} + // Use existing key unless --key flag explicitly provides a new one if cmd.Flags().Changed("key") { key, _ := cmd.Flags().GetString("key") req.Key = &key + } else { + req.Key = &existingEnv.Key } + if cmd.Flags().Changed("value") { value, _ := cmd.Flags().GetString("value") req.Value = &value @@ -57,14 +70,10 @@ func NewUpdateCommand() *cobra.Command { req.Comment = &comment } - if req.Key == nil { - return fmt.Errorf("--key is required") - } if req.Value == nil { return fmt.Errorf("--value is required") } - dbSvc := service.NewDatabaseService(client) env, err := dbSvc.UpdateEnv(ctx, dbUUID, req) if err != nil { return fmt.Errorf("failed to update environment variable: %w", err) @@ -75,8 +84,8 @@ func NewUpdateCommand() *cobra.Command { }, } - cmd.Flags().String("key", "", "New environment variable key") - cmd.Flags().String("value", "", "New environment variable value") + cmd.Flags().String("key", "", "New environment variable key (rename)") + cmd.Flags().String("value", "", "New environment variable value (required)") cmd.Flags().Bool("is-literal", false, "Treat value as literal") cmd.Flags().Bool("is-multiline", false, "Value is multiline") cmd.Flags().Bool("is-shown-once", false, "Only show value once") diff --git a/cmd/service/env/create.go b/cmd/service/env/create.go index 782d64a..ddb918b 100644 --- a/cmd/service/env/create.go +++ b/cmd/service/env/create.go @@ -63,12 +63,12 @@ func NewCreateCommand() *cobra.Command { } serviceSvc := service.NewService(client) - env, err := serviceSvc.CreateEnv(ctx, uuid, req) + _, err = serviceSvc.CreateEnv(ctx, uuid, req) if err != nil { return fmt.Errorf("failed to create environment variable: %w", err) } - fmt.Printf("Environment variable '%s' created successfully.\n", env.Key) + fmt.Printf("Environment variable '%s' created successfully.\n", key) return nil }, } diff --git a/cmd/service/env/update.go b/cmd/service/env/update.go index 35d7bf3..bd61017 100644 --- a/cmd/service/env/update.go +++ b/cmd/service/env/update.go @@ -12,13 +12,14 @@ import ( func NewUpdateCommand() *cobra.Command { cmd := &cobra.Command{ - Use: "update ", + Use: "update ", Short: "Update an environment variable", - Long: `Update an existing environment variable. UUID is the service.`, - Args: cli.ExactArgs(1, ""), + Long: `Update an existing environment variable. Identify it by UUID or key name.`, + Args: cli.ExactArgs(2, " "), RunE: func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() serviceUUID := args[0] + envIdentifier := args[1] client, err := cli.GetAPIClient(cmd) if err != nil { @@ -30,13 +31,24 @@ func NewUpdateCommand() *cobra.Command { return err } + serviceSvc := service.NewService(client) + + // Look up the env var to resolve its key + existingEnv, err := serviceSvc.GetEnv(ctx, serviceUUID, envIdentifier) + if err != nil { + return fmt.Errorf("failed to find environment variable '%s': %w", envIdentifier, err) + } + req := &models.ServiceEnvironmentVariableUpdateRequest{} - // Only set fields that were provided + // Use existing key unless --key flag explicitly provides a new one if cmd.Flags().Changed("key") { key, _ := cmd.Flags().GetString("key") req.Key = &key + } else { + req.Key = &existingEnv.Key } + if cmd.Flags().Changed("value") { value, _ := cmd.Flags().GetString("value") req.Value = &value @@ -62,14 +74,10 @@ func NewUpdateCommand() *cobra.Command { req.Comment = &comment } - if req.Key == nil { - return fmt.Errorf("--key is required") - } if req.Value == nil { return fmt.Errorf("--value is required") } - serviceSvc := service.NewService(client) env, err := serviceSvc.UpdateEnv(ctx, serviceUUID, req) if err != nil { return fmt.Errorf("failed to update environment variable: %w", err) @@ -80,8 +88,8 @@ func NewUpdateCommand() *cobra.Command { }, } - cmd.Flags().String("key", "", "New environment variable key") - cmd.Flags().String("value", "", "New environment variable value") + cmd.Flags().String("key", "", "New environment variable key (rename)") + cmd.Flags().String("value", "", "New environment variable value (required)") cmd.Flags().Bool("build-time", true, "Available at build time (default: true)") cmd.Flags().Bool("is-literal", false, "Treat value as literal (don't interpolate variables)") cmd.Flags().Bool("is-multiline", false, "Value is multiline") diff --git a/llms.txt b/llms.txt index 38972ad..5b3ba8c 100644 --- a/llms.txt +++ b/llms.txt @@ -582,9 +582,17 @@ Parameters: description: Make all variables available at runtime (default: true) required: false -Command: coolify app env update -Description: Update an existing environment variable. UUID is the application. +Command: coolify app env update +Description: Update an existing environment variable. Identify it by UUID or key name. Parameters: + - name: --value + type: string + description: New environment variable value (required) + required: true + - name: --key + type: string + description: New environment variable key (optional, for renaming) + required: false - name: --build-time type: boolean description: Available at build time (default: true) @@ -601,10 +609,6 @@ Parameters: type: boolean description: Value is multiline required: false - - name: --key - type: string - description: New environment variable key - required: false - name: --preview type: boolean description: Available in preview deployments @@ -613,10 +617,6 @@ Parameters: type: boolean description: Available at runtime (default: true) required: false - - name: --value - type: string - description: New environment variable value - required: false Command: coolify app get Description: Retrieve detailed information about a specific application. @@ -1146,9 +1146,17 @@ Parameters: description: Treat all values as literal (don't interpolate variables) required: false -Command: coolify database env update -Description: Update an existing environment variable. UUID is the database. +Command: coolify database env update +Description: Update an existing environment variable. Identify it by UUID or key name. Parameters: + - name: --value + type: string + description: New environment variable value (required) + required: true + - name: --key + type: string + description: New environment variable key (optional, for renaming) + required: false - name: --comment type: string description: Comment for the environment variable @@ -1165,14 +1173,6 @@ Parameters: type: boolean description: Only show value once required: false - - name: --key - type: string - description: New environment variable key - required: false - - name: --value - type: string - description: New environment variable value - required: false Command: coolify database get Description: Get detailed information about a specific database by UUID. @@ -1614,9 +1614,17 @@ Parameters: description: Make all variables available at runtime (default: true) required: false -Command: coolify service env update -Description: Update an existing environment variable. UUID is the service. +Command: coolify service env update +Description: Update an existing environment variable. Identify it by UUID or key name. Parameters: + - name: --value + type: string + description: New environment variable value (required) + required: true + - name: --key + type: string + description: New environment variable key (optional, for renaming) + required: false - name: --build-time type: boolean description: Available at build time (default: true) @@ -1633,18 +1641,10 @@ Parameters: type: boolean description: Value is multiline required: false - - name: --key - type: string - description: New environment variable key - required: false - name: --runtime type: boolean description: Available at runtime (default: true) required: false - - name: --value - type: string - description: New environment variable value - required: false Command: coolify service get Description: Get detailed information about a specific service. From ccf578e537b9a0bdb3dd07fddbc29c07922ed541 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Mon, 23 Mar 2026 14:41:03 +0100 Subject: [PATCH 2/2] docs(env): reorder parameters in env update commands Reorganize parameter ordering for consistency across app, database, and service env update commands. Move string parameters (--key, --value) after boolean parameters. Simplify --key parameter description. --- llms.txt | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/llms.txt b/llms.txt index 5b3ba8c..79fe5bb 100644 --- a/llms.txt +++ b/llms.txt @@ -585,14 +585,6 @@ Parameters: Command: coolify app env update Description: Update an existing environment variable. Identify it by UUID or key name. Parameters: - - name: --value - type: string - description: New environment variable value (required) - required: true - - name: --key - type: string - description: New environment variable key (optional, for renaming) - required: false - name: --build-time type: boolean description: Available at build time (default: true) @@ -609,6 +601,10 @@ Parameters: type: boolean description: Value is multiline required: false + - name: --key + type: string + description: New environment variable key (rename) + required: false - name: --preview type: boolean description: Available in preview deployments @@ -617,6 +613,10 @@ Parameters: type: boolean description: Available at runtime (default: true) required: false + - name: --value + type: string + description: New environment variable value (required) + required: true Command: coolify app get Description: Retrieve detailed information about a specific application. @@ -1149,14 +1149,6 @@ Parameters: Command: coolify database env update Description: Update an existing environment variable. Identify it by UUID or key name. Parameters: - - name: --value - type: string - description: New environment variable value (required) - required: true - - name: --key - type: string - description: New environment variable key (optional, for renaming) - required: false - name: --comment type: string description: Comment for the environment variable @@ -1173,6 +1165,14 @@ Parameters: type: boolean description: Only show value once required: false + - name: --key + type: string + description: New environment variable key (rename) + required: false + - name: --value + type: string + description: New environment variable value (required) + required: true Command: coolify database get Description: Get detailed information about a specific database by UUID. @@ -1617,14 +1617,6 @@ Parameters: Command: coolify service env update Description: Update an existing environment variable. Identify it by UUID or key name. Parameters: - - name: --value - type: string - description: New environment variable value (required) - required: true - - name: --key - type: string - description: New environment variable key (optional, for renaming) - required: false - name: --build-time type: boolean description: Available at build time (default: true) @@ -1641,10 +1633,18 @@ Parameters: type: boolean description: Value is multiline required: false + - name: --key + type: string + description: New environment variable key (rename) + required: false - name: --runtime type: boolean description: Available at runtime (default: true) required: false + - name: --value + type: string + description: New environment variable value (required) + required: true Command: coolify service get Description: Get detailed information about a specific service.