- commit
- c81d4e2
- parent
- d03b23e
- author
- Eric Bower
- date
- 2024-05-15 14:33:47 +0000 UTC
chore(pico): better logging statements
4 files changed,
+20,
-16
+2,
-1
1@@ -456,7 +456,7 @@ func (me *PsqlDB) FindPublicKeyForKey(key string) (*db.PublicKey, error) {
2 }
3
4 if len(keys) == 0 {
5- return nil, errors.New("no public keys found for key provided")
6+ return nil, fmt.Errorf("pubkey not found in our database: [%s]", key)
7 }
8
9 // When we run PublicKeyForKey and there are multiple public keys returned from the database
10@@ -590,6 +590,7 @@ func (me *PsqlDB) FindUserForKey(username string, key string) (*db.User, error)
11 me.Logger.Info("attempting to find user with only public key", "key", key)
12 pk, err := me.FindPublicKeyForKey(key)
13 if err == nil {
14+ me.Logger.Info("found pubkey, looking for user", "key", key, "userID", pk.UserID)
15 user, err := me.FindUser(pk.UserID)
16 if err != nil {
17 return nil, err
+3,
-2
1@@ -12,7 +12,6 @@ import (
2 "github.com/picosh/pico/tui/common"
3 "github.com/picosh/pico/tui/notifications"
4 "github.com/picosh/pico/tui/plus"
5- "github.com/picosh/send/send/utils"
6 )
7
8 func getUser(s ssh.Session, dbpool db.DB) (*db.User, error) {
9@@ -82,7 +81,9 @@ func WishMiddleware(handler *CliHandler) wish.Middleware {
10
11 user, err := getUser(sesh, dbpool)
12 if err != nil {
13- utils.ErrorHandler(sesh, err)
14+ wish.Errorf(sesh, "detected ssh command: %s\n", args)
15+ s := fmt.Errorf("error: you need to create an account before using the remote cli: %w", err)
16+ wish.Fatalln(sesh, s)
17 return
18 }
19
+1,
-1
1@@ -82,7 +82,7 @@ func StartSshServer() {
2 cfg,
3 handler,
4 cliHandler,
5- promwish.Middleware(fmt.Sprintf("%s:%s", host, promPort), "pgs-ssh"),
6+ promwish.Middleware(fmt.Sprintf("%s:%s", host, promPort), "pico-ssh"),
7 ),
8 )
9 if err != nil {
+14,
-12
1@@ -2,13 +2,13 @@ package tui
2
3 import (
4 "errors"
5- "fmt"
6 "io"
7
8 "github.com/charmbracelet/bubbles/spinner"
9 tea "github.com/charmbracelet/bubbletea"
10 "github.com/charmbracelet/lipgloss"
11 "github.com/charmbracelet/ssh"
12+ "github.com/charmbracelet/wish"
13 bm "github.com/charmbracelet/wish/bubbletea"
14 "github.com/muesli/reflow/indent"
15 "github.com/muesli/reflow/wordwrap"
16@@ -33,8 +33,8 @@ const (
17 statusNoAccount
18 statusBrowsingKeys
19 statusBrowsingTokens
20- statusBrowsingPlus
21 statusBrowsingNotifications
22+ statusBrowsingPlus
23 statusChat
24 statusQuitting
25 )
26@@ -56,8 +56,8 @@ type menuChoice int
27 const (
28 keysChoice menuChoice = iota
29 tokensChoice
30- plusChoice
31 notificationsChoice
32+ plusChoice
33 chatChoice
34 exitChoice
35 unsetChoice // set when no choice has been made
36@@ -67,8 +67,8 @@ const (
37 var menuChoices = map[menuChoice]string{
38 keysChoice: "Manage keys",
39 tokensChoice: "Manage tokens",
40- plusChoice: "Pico+",
41 notificationsChoice: "Notifications",
42+ plusChoice: "Pico+",
43 chatChoice: "Chat",
44 exitChoice: "Exit",
45 }
46@@ -83,25 +83,25 @@ func NewSpinner(styles common.Styles) spinner.Model {
47 type GotDBMsg db.DB
48
49 func CmsMiddleware(cfg *shared.ConfigSite) bm.Handler {
50- return func(s ssh.Session) (tea.Model, []tea.ProgramOption) {
51+ return func(sesh ssh.Session) (tea.Model, []tea.ProgramOption) {
52 logger := cfg.Logger
53
54- _, _, active := s.Pty()
55+ _, _, active := sesh.Pty()
56 if !active {
57 logger.Info("no active terminal, skipping")
58 return nil, nil
59 }
60
61- sshUser := s.User()
62+ sshUser := sesh.User()
63 dbpool := postgres.NewDB(cfg.DbURL, cfg.Logger)
64- renderer := lipgloss.NewRenderer(s)
65- renderer.SetOutput(common.OutputFromSession(s))
66+ renderer := lipgloss.NewRenderer(sesh)
67+ renderer.SetOutput(common.OutputFromSession(sesh))
68 styles := common.DefaultStyles(renderer)
69
70 m := model{
71- session: s,
72+ session: sesh,
73 cfg: cfg,
74- publicKey: s.PublicKey(),
75+ publicKey: sesh.PublicKey(),
76 dbpool: dbpool,
77 sshUser: sshUser,
78 status: statusInit,
79@@ -116,7 +116,7 @@ func CmsMiddleware(cfg *shared.ConfigSite) bm.Handler {
80
81 user, err := m.findUser()
82 if err != nil {
83- _, _ = fmt.Fprintln(s.Stderr(), err)
84+ wish.Errorln(sesh, err)
85 return nil, nil
86 }
87 m.user = user
88@@ -177,6 +177,7 @@ func (m model) findUser() (*db.User, error) {
89 if errors.Is(err, &db.ErrMultiplePublicKeys{}) {
90 return nil, err
91 }
92+ // no user and not error indicates we need to create an account
93 return nil, nil
94 }
95
96@@ -259,6 +260,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
97 m.createAccount = account.NewCreateModel(m.styles, m.dbpool, m.publicKey)
98 m.plus = plus.NewModel(m.styles, m.user, m.session)
99 m.notifications = notifications.NewModel(m.styles, m.dbpool, m.user, m.session)
100+ // no user found? go to create account screen
101 if m.user == nil {
102 m.status = statusNoAccount
103 } else {