summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-07-01 11:13:41 +0300
committerPaul Buetow <paul@buetow.org>2024-07-01 11:13:41 +0300
commit0fa5420bfaed55ecbb43e98a18138aed7f658660 (patch)
tree1f9e6c650455226da3f436c4f7e967f657384a25 /internal
parentecc323b3b45e666a3376d7983424837d58336198 (diff)
display error message in TUI
Diffstat (limited to 'internal')
-rw-r--r--internal/client/tui/submit.go25
-rw-r--r--internal/client/tui/tui.go11
-rw-r--r--internal/easyhttp/easyhttp.go5
3 files changed, 22 insertions, 19 deletions
diff --git a/internal/client/tui/submit.go b/internal/client/tui/submit.go
index 15b7826..5507000 100644
--- a/internal/client/tui/submit.go
+++ b/internal/client/tui/submit.go
@@ -3,30 +3,25 @@ package tui
import (
"fmt"
+ "codeberg.org/snonux/gos/internal/config/client"
config "codeberg.org/snonux/gos/internal/config/client"
tea "github.com/charmbracelet/bubbletea"
)
func submitAction(conf config.ClientConfig) tea.Cmd {
- // The composed file is now the file to be submitted.
- //submitFile := fmt.Sprintf("%s/%s", conf.DataDir, conf.ComposeFile)
+ composeFile := fmt.Sprintf("%s/%s", conf.DataDir, conf.ComposeFile)
- /*
- c := &http.Client{
- Timeout: 10 * time.Second,
- }
- res, err := c.Get(url)
- if err != nil {
- return sub{err}
- }
- defer res.Body.Close()
- */
+ return submitMessage(conf, composeFile, func() error {
+ // This is the callback to call
+ return nil
+ })
+}
+func submitMessage(conf client.ClientConfig, filePath string, callback func() error) tea.Cmd {
return func() tea.Msg {
- err := fmt.Errorf("this is a test errorrrrrr!")
return finishedMsg{
- err: err,
+ callback: callback,
+ err: fmt.Errorf("This is a sample error"),
}
}
-
}
diff --git a/internal/client/tui/tui.go b/internal/client/tui/tui.go
index 38085f7..41a0a39 100644
--- a/internal/client/tui/tui.go
+++ b/internal/client/tui/tui.go
@@ -77,13 +77,12 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Quit
}
case finishedMsg:
- if msg.err != nil {
- m.err = msg.err
- return m, tea.Quit
+ m.err = msg.err
+ if m.err != nil {
+ return m, nil
}
if err := msg.callback(); err != nil {
m.err = err
- return m, tea.Quit
}
}
@@ -102,6 +101,10 @@ func (m model) View() string {
s += fmt.Sprintf("%s %s\n", cursor, choice)
}
+ if m.err != nil {
+ s += fmt.Sprintf("\nERROR: %s\n", m.err)
+ }
+
s += "\nPress q to quiet.\n"
return style.Render(s)
}
diff --git a/internal/easyhttp/easyhttp.go b/internal/easyhttp/easyhttp.go
index 7cd24ff..ca10a8e 100644
--- a/internal/easyhttp/easyhttp.go
+++ b/internal/easyhttp/easyhttp.go
@@ -43,3 +43,8 @@ func GetData[T any](uri, apiKey string, data *T) error {
return json.Unmarshal(bytes, data)
}
+
+// Submiut structure as JSON to API
+func SubmitData[T any](servers []string, uri, apiKey string, data *T) error {
+ return nil
+}