From abf0c86ab0c59e497b6f2452a68a5b46229f4c21 Mon Sep 17 00:00:00 2001 From: lew Date: Wed, 11 Feb 2026 23:51:29 +0000 Subject: [PATCH] feat(config): add config edit subcommand --- cmd/config_cmd.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/cmd/config_cmd.go b/cmd/config_cmd.go index cbee910..672784d 100644 --- a/cmd/config_cmd.go +++ b/cmd/config_cmd.go @@ -3,6 +3,7 @@ package cmd import ( "fmt" "os" + "os/exec" "path/filepath" "reflect" "strings" @@ -68,6 +69,37 @@ var configPathCmd = &cobra.Command{ }, } +var configEditCmd = &cobra.Command{ + Use: "edit", + Short: "Open config file in $EDITOR", + Args: cobra.NoArgs, + SilenceUsage: true, + RunE: func(cmd *cobra.Command, args []string) error { + editor := os.Getenv("EDITOR") + if editor == "" { + return withHint( + fmt.Errorf("EDITOR not set"), + "set $EDITOR to your preferred text editor", + ) + } + p, err := configPath() + if err != nil { + return fmt.Errorf("cannot determine config path: %w", err) + } + // Create default config if file doesn't exist + if _, err := os.Stat(p); os.IsNotExist(err) { + if err := writeConfigFile(defaultConfig()); err != nil { + return err + } + } + c := exec.Command(editor, p) + c.Stdin = os.Stdin + c.Stdout = os.Stdout + c.Stderr = os.Stderr + return c.Run() + }, +} + func writeConfigFile(cfg Config) error { p, err := configPath() if err != nil { @@ -157,6 +189,7 @@ var configSetCmd = &cobra.Command{ func init() { configInitCmd.Flags().Bool("new", false, "overwrite existing config file") + configCmd.AddCommand(configEditCmd) configCmd.AddCommand(configGetCmd) configCmd.AddCommand(configInitCmd) configCmd.AddCommand(configListCmd)