Skip to content

Commit

Permalink
feat: ✨ implement search command and move index as subcommand, ad…
Browse files Browse the repository at this point in the history
…d `key` command

- Add `search key` command to get MeiliSearch read-only key.
  • Loading branch information
Dan6erbond committed May 10, 2023
1 parent 55bd55f commit 583ce54
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions server/pkg/meilisearch/commands.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,47 @@
package meilisearch

import (
"log"

"github.com/meilisearch/meilisearch-go"
"github.com/pocketbase/pocketbase"
"github.com/spf13/cobra"
)

func RegisterCommands(app *pocketbase.PocketBase, client *meilisearch.Client) {
searchCmd := &cobra.Command{
Use: "search",
Run: func(command *cobra.Command, args []string) {
print("Runs commands to interact with MeiliSearch")
},
}

searchCmd.AddCommand(&cobra.Command{
Use: "key",
Run: func(command *cobra.Command, args []string) {
key, err := GetReadOnlyKey(client)

if err != nil {
log.Println("Error retrieving key:", err)
}

if key != "" {
log.Println("MeiliSearch read-only key:", key)
} else {
log.Println("No read-only key was found")
}
},
})

indexCmd := &cobra.Command{
Use: "index",
Run: func(command *cobra.Command, args []string) {
print("Runs commands to interact with the Meilisearch index")
print("Runs commands to interact with MeiliSearch")
},
}

searchCmd.AddCommand(indexCmd)

indexCmd.AddCommand(&cobra.Command{
Use: "clear",
Run: func(command *cobra.Command, args []string) {
Expand Down Expand Up @@ -47,5 +75,5 @@ func RegisterCommands(app *pocketbase.PocketBase, client *meilisearch.Client) {
},
})

app.RootCmd.AddCommand(indexCmd)
app.RootCmd.AddCommand(searchCmd)
}

0 comments on commit 583ce54

Please sign in to comment.