package cmd import ( "envy/cmd/utils" "os" "os/exec" "path" "runtime" "github.com/spf13/cobra" ) // editCmd represents the edit command var editCmd = &cobra.Command{ Use: "edit", Short: "Open .env file in the default editor", Run: func(cmd *cobra.Command, args []string) { editor := os.Getenv("EDITOR") if editor == "" { switch runtime.GOOS { case "windows": editor = "notepad" default: editor = "nano" } } cwd, err := os.Getwd() utils.StopIfErr(err) edit := exec.Command(editor, path.Join(cwd, ".env")) edit.Stdin = os.Stdin edit.Stdout = os.Stdout edit.Stderr = os.Stderr err = edit.Run() utils.StopIfErr(err) }, } func init() { rootCmd.AddCommand(editCmd) }