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..79fe5bb 100644 --- a/llms.txt +++ b/llms.txt @@ -582,8 +582,8 @@ 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: --build-time type: boolean @@ -603,7 +603,7 @@ Parameters: required: false - name: --key type: string - description: New environment variable key + description: New environment variable key (rename) required: false - name: --preview type: boolean @@ -615,8 +615,8 @@ Parameters: required: false - name: --value type: string - description: New environment variable value - required: false + description: New environment variable value (required) + required: true Command: coolify app get Description: Retrieve detailed information about a specific application. @@ -1146,8 +1146,8 @@ 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: --comment type: string @@ -1167,12 +1167,12 @@ Parameters: required: false - name: --key type: string - description: New environment variable key + description: New environment variable key (rename) required: false - name: --value type: string - description: New environment variable value - required: false + description: New environment variable value (required) + required: true Command: coolify database get Description: Get detailed information about a specific database by UUID. @@ -1614,8 +1614,8 @@ 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: --build-time type: boolean @@ -1635,7 +1635,7 @@ Parameters: required: false - name: --key type: string - description: New environment variable key + description: New environment variable key (rename) required: false - name: --runtime type: boolean @@ -1643,8 +1643,8 @@ Parameters: required: false - name: --value type: string - description: New environment variable value - required: false + description: New environment variable value (required) + required: true Command: coolify service get Description: Get detailed information about a specific service.