MCPcopy Create free account
hub / github.com/GetStream/stream-cli / queryCmd

Function queryCmd

pkg/cmd/chat/user/user.go:330–384  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

328}
329
330func queryCmd() *cobra.Command {
331 cmd := &cobra.Command{
332 Use: "query-users --filter [raw-json] --limit [int] --output-format [json|tree]",
333 Short: "Query users",
334 Long: heredoc.Doc(`
335 This command allows you to search for users. The 'filter' flag is a raw JSON string,
336 and you can check the valid combinations in the official documentation.
337
338 https://getstream.io/chat/docs/node/query_users/?language=javascript
339 `),
340 Example: heredoc.Doc(`
341 # Query for 'user-1'. The results are shown as json.
342 $ stream-cli chat query-users --filter '{"id": {"$eq": "user-1"}}'
343
344 # Query for 'user-1' and 'user-2'. The results are shown as a browsable tree.
345 $ stream-cli chat query-users --filter '{"id": {"$in": ["user-1", "user-2"]}}' --output-format tree
346 `),
347 RunE: func(cmd *cobra.Command, args []string) error {
348 c, err := config.GetConfig(cmd).GetClient(cmd)
349 if err != nil {
350 return err
351 }
352
353 limit, _ := cmd.Flags().GetInt("limit")
354 filter, _ := cmd.Flags().GetString("filter")
355
356 var m map[string]interface{}
357 err = json.Unmarshal([]byte(filter), &m)
358 if err != nil {
359 return err
360 }
361
362 q := &stream.QueryUsersOptions{
363 QueryOption: stream.QueryOption{
364 Filter: m,
365 Limit: limit,
366 },
367 }
368 resp, err := c.QueryUsers(cmd.Context(), q)
369 if err != nil {
370 return err
371 }
372
373 return utils.PrintObject(cmd, resp)
374 },
375 }
376
377 fl := cmd.Flags()
378 fl.StringP("filter", "f", "{}", "[required] Filter for users")
379 fl.IntP("limit", "l", 10, "[optional] The number of users returned")
380 fl.StringP("output-format", "o", "json", "[optional] Output format. Can be json or tree")
381 _ = cmd.MarkFlagRequired("filter")
382
383 return cmd
384}
385
386func revokeCmd() *cobra.Command {
387 cmd := &cobra.Command{

Callers 1

NewCmdsFunction · 0.85

Calls 3

GetConfigFunction · 0.92
PrintObjectFunction · 0.92
GetClientMethod · 0.80

Tested by

no test coverage detected