Files
wild-cloud/wild-cli/cmd/wild/config/set.go

54 lines
1.2 KiB
Go

package config
import (
"fmt"
"github.com/spf13/cobra"
"github.com/wild-cloud/wild-cli/internal/config"
"github.com/wild-cloud/wild-cli/internal/environment"
"github.com/wild-cloud/wild-cli/internal/output"
)
func newSetCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "set <path> <value>",
Short: "Set a configuration value",
Long: `Set a configuration value in config.yaml using a dot-notation path.
The value will be parsed as YAML, so you can set strings, numbers, booleans, or complex objects.
Examples:
wild config set cluster.name my-cluster
wild config set cluster.replicas 3
wild config set cluster.enabled true
wild config set apps.myapp.image nginx:latest`,
Args: cobra.ExactArgs(2),
RunE: runSet,
}
return cmd
}
func runSet(cmd *cobra.Command, args []string) error {
path := args[0]
value := args[1]
// Initialize environment
env := environment.New()
if err := env.RequiresProject(); err != nil {
return err
}
// Create config manager
mgr := config.NewManager(env.ConfigPath(), env.SecretsPath())
// Set the value
if err := mgr.Set(path, value); err != nil {
return fmt.Errorf("setting config value: %w", err)
}
output.Success(fmt.Sprintf("Set %s = %s", path, value))
return nil
}