switch WritePostCMD to higher order fn

This commit is contained in:
Travis Shears 2025-09-30 14:28:14 +02:00
parent 1160665595
commit 01ce668160
2 changed files with 16 additions and 8 deletions

View file

@ -8,13 +8,21 @@ import (
tea "github.com/charmbracelet/bubbletea"
)
func WritePostCMD() tea.Msg {
id, err := write()
if err != nil {
return ErrorMsg{err}
func WritePostCMD() tea.Cmd {
editor := os.Getenv("EDITOR")
if editor == "" {
editor = "vim"
}
return Notification(fmt.Sprintf("Created post with id: %s", id))
c := exec.Command(editor) //nolint:gosec
return tea.ExecProcess(c, func(err error) tea.Msg {
return Notification("Editor finished")
})
// id, err := write()
// if err != nil {
// return ErrorMsg{err}
// }
// return Notification(fmt.Sprintf("Created post with id: %s", id))
}
// For messages that contain errors it's often handy to also implement the

View file

@ -18,11 +18,11 @@ const (
)
func TODOCmd() tea.Msg {
return gemlog.Notification("This action has not been implemented yet.")
return gemlog.Notification("This action has not been implemented yet. Try another.")
}
var mainCommands = map[Action]tea.Cmd{
Write: gemlog.WritePostCMD,
Write: gemlog.WritePostCMD(),
Read: TODOCmd,
Edit: TODOCmd,
Delete: TODOCmd,