WIP.
This commit is contained in:
parent
098201418b
commit
58a01bff56
5 changed files with 99 additions and 26 deletions
|
|
@ -43,3 +43,28 @@ func (c *chats) AddChat(ctx context.Context, cmd *cli.Command) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *chats) ListChats(ctx context.Context, cmd *cli.Command) error {
|
||||
logger := logging.Get("commands")
|
||||
logger.SetFormat("chat add: {{message}}")
|
||||
|
||||
mdb := models.OpenDatabase(ctx, c.settings)
|
||||
if err := mdb.Open(); err != nil {
|
||||
logger.Error("connection error:", errors.Unfurl(err))
|
||||
return err
|
||||
}
|
||||
|
||||
mdl := models.NewChatModel(ctx, mdb.DB())
|
||||
chats, err := mdl.ListChats()
|
||||
if err != nil {
|
||||
if errors.Is(err, models.ErrNoRows) {
|
||||
logger.Error("no chats configured")
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
for i, chat := range chats {
|
||||
fmt.Printf("%d: %s <%d>\n", i, chat.Name, chat.ID)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ func NewCommandHost(ctx context.Context, root vfs.VFS) (*commands, error) {
|
|||
}
|
||||
|
||||
cmd := &commands{
|
||||
ctx: ctx,
|
||||
root: root,
|
||||
settings: conf,
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue