cli/cmd/core/config/cmd_set.go
Snider 21dc508e96
Some checks are pending
Security Scan / security (push) Waiting to run
refactor(cli): replace cobra with core/go primitives
- Remove github.com/spf13/cobra dependency entirely
- Command = core.Command (was cobra.Command)
- CommandRegistration func(c *core.Core) (was func(root *cobra.Command))
- Path-based routing: c.Command("config/list", ...) replaces root.AddCommand()
- Flags parsed automatically via core.Options (no StringVarP ceremony)
- Replace stdlib imports with core/go: errors, path/filepath fully removed
- fmt/strings reduced to only what core/go can't replace yet (Fprint, Builder)
- Shell completion deferred to core/go v0.9.0
- Net -344 lines (576 insertions, 920 deletions)
- Build, vet, and tests pass clean

Co-Authored-By: Virgil <virgil@lethean.io>
2026-04-08 11:11:25 +01:00

38 lines
1.1 KiB
Go

package config
import (
"dappco.re/go/core"
"dappco.re/go/core/cli/pkg/cli"
)
// configSetAction handles 'config set --key=<key> --value=<value>'.
// Also accepts positional form via _arg for backwards compatibility when
// only one arg is passed (interpreted as key, value read from --value).
func configSetAction(opts core.Options) core.Result {
key := opts.String("key")
value := opts.String("value")
// Fallback: first positional arg as key if --key not provided.
if key == "" {
key = opts.String("_arg")
}
if key == "" {
return core.Result{Value: cli.Err("requires --key and --value arguments (e.g. config set --key=dev.editor --value=vim)"), OK: false}
}
if value == "" {
return core.Result{Value: cli.Err("requires --value argument (e.g. config set --key=%s --value=<value>)", key), OK: false}
}
configuration, err := loadConfig()
if err != nil {
return core.Result{Value: err, OK: false}
}
if err := configuration.Set(key, value); err != nil {
return core.Result{Value: cli.Wrap(err, "failed to set config value"), OK: false}
}
cli.Success(key + " = " + value)
return core.Result{OK: true}
}