Implement lmcli rm
This commit is contained in:
parent
cf0e98f656
commit
6af9377cf5
@ -122,6 +122,40 @@ var lsCmd = &cobra.Command{
|
||||
},
|
||||
}
|
||||
|
||||
var rmCmd = &cobra.Command{
|
||||
Use: "rm [conversation]",
|
||||
Short: "Remove a conversation",
|
||||
Long: `Removes a conversation by its short name.`,
|
||||
Args: func(cmd *cobra.Command, args []string) error {
|
||||
argCount := 1
|
||||
if err := cobra.MinimumNArgs(argCount)(cmd, args); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
shortName := args[0]
|
||||
conversation, err := store.ConversationByShortName(shortName)
|
||||
if err != nil {
|
||||
Fatal("Cloud not search for conversation: %v\n", err)
|
||||
}
|
||||
if conversation.ID == 0 || err != nil {
|
||||
Fatal("Conversation not found with short name: %s\n", shortName)
|
||||
}
|
||||
err = store.DeleteConversation(conversation)
|
||||
if err != nil {
|
||||
Fatal("Could not delete conversation: %v\n", err)
|
||||
}
|
||||
},
|
||||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
compMode := cobra.ShellCompDirectiveNoFileComp
|
||||
if len(args) != 0 {
|
||||
return nil, compMode
|
||||
}
|
||||
return store.ConversationShortNameCompletions(toComplete), compMode
|
||||
},
|
||||
}
|
||||
|
||||
var viewCmd = &cobra.Command{
|
||||
Use: "view [conversation]",
|
||||
Short: "View messages in a conversation",
|
||||
@ -289,6 +323,7 @@ func NewRootCmd() *cobra.Command {
|
||||
lsCmd,
|
||||
newCmd,
|
||||
promptCmd,
|
||||
rmCmd,
|
||||
viewCmd,
|
||||
)
|
||||
return rootCmd
|
||||
|
@ -86,6 +86,11 @@ func (s *Store) SaveConversation(conversation *Conversation) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *Store) DeleteConversation(conversation *Conversation) error {
|
||||
s.db.Where("conversation_id = ?", conversation.ID).Delete(&Message{})
|
||||
return s.db.Delete(&conversation).Error
|
||||
}
|
||||
|
||||
func (s *Store) SaveMessage(message *Message) error {
|
||||
return s.db.Create(message).Error
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user