From 2c783566f3e01346fc64201c4834af17dba9fad1 Mon Sep 17 00:00:00 2001 From: Ken Hibino Date: Sat, 9 Apr 2022 06:49:22 -0700 Subject: [PATCH] (cli): Add group ls command --- tools/asynq/cmd/group.go | 48 ++++++++++++++++++++++++++++++++++++++++ tools/go.mod | 3 +-- 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 tools/asynq/cmd/group.go diff --git a/tools/asynq/cmd/group.go b/tools/asynq/cmd/group.go new file mode 100644 index 0000000..761433e --- /dev/null +++ b/tools/asynq/cmd/group.go @@ -0,0 +1,48 @@ +// Copyright 2022 Kentaro Hibino. All rights reserved. +// Use of this source code is governed by a MIT license +// that can be found in the LICENSE file. + +package cmd + +import ( + "fmt" + "os" + + "github.com/spf13/cobra" +) + +func init() { + rootCmd.AddCommand(groupCmd) + groupCmd.AddCommand(groupListCmd) + groupListCmd.Flags().StringP("queue", "q", "", "queue to inspect") + groupListCmd.MarkFlagRequired("queue") +} + +var groupCmd = &cobra.Command{ + Use: "group", + Short: "Manage groups", +} + +var groupListCmd = &cobra.Command{ + Use: "ls", + Short: "List groups", + Args: cobra.NoArgs, + Run: groupLists, +} + +func groupLists(cmd *cobra.Command, args []string) { + qname, err := cmd.Flags().GetString("queue") + if err != nil { + fmt.Println(err) + os.Exit(1) + } + inspector := createInspector() + groups, err := inspector.Groups(qname) + if len(groups) == 0 { + fmt.Printf("No groups found in queue %q\n", qname) + return + } + for _, g := range groups { + fmt.Println(g.Group) + } +} diff --git a/tools/go.mod b/tools/go.mod index 35463c3..1d803cf 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -5,7 +5,7 @@ go 1.13 require ( github.com/fatih/color v1.9.0 github.com/go-redis/redis/v8 v8.11.4 - github.com/hibiken/asynq v0.21.0 /* TODO: Update this after release */ + github.com/hibiken/asynq v0.21.0 github.com/hibiken/asynq/x v0.0.0-20220131170841-349f4c50fb1d github.com/mitchellh/go-homedir v1.1.0 github.com/prometheus/client_golang v1.11.0 @@ -14,5 +14,4 @@ require ( github.com/spf13/viper v1.7.0 ) -/* TODO: Remove this before release */ replace github.com/hibiken/asynq => ../