From a16112f43ca40f4a8f8c81ff7ee8ff4c89589698 Mon Sep 17 00:00:00 2001 From: Peter Dannemann <28637185+petedannemann@users.noreply.github.com> Date: Mon, 18 Sep 2023 13:24:58 -0400 Subject: [PATCH] fix issues from get subcmd refactor (#151) * Revert "pr feedback" This reverts commit 07667ddf64bfbe9383cb2ae9f2f6b548f169f157. * fix debug flag for get subcommand --- cmd/topicctl/subcmd/get.go | 92 +++++++++++++++++++++++++++----------- 1 file changed, 65 insertions(+), 27 deletions(-) diff --git a/cmd/topicctl/subcmd/get.go b/cmd/topicctl/subcmd/get.go index dd1a4c28..642a9031 100644 --- a/cmd/topicctl/subcmd/get.go +++ b/cmd/topicctl/subcmd/get.go @@ -60,25 +60,10 @@ func init() { } func getPreRun(cmd *cobra.Command, args []string) error { - return getConfig.shared.validate() -} - -func getCliRunnerAndCtx() ( - context.Context, - *cli.CLIRunner, - error, -) { - ctx := context.Background() - sess := session.Must(session.NewSession()) - - adminClient, err := getConfig.shared.getAdminClient(ctx, sess, true) - if err != nil { - return nil, nil, err + if err := RootCmd.PersistentPreRunE(cmd, args); err != nil { + return err } - defer adminClient.Close() - - cliRunner := cli.NewCLIRunner(adminClient, log.Infof, !noSpinner) - return ctx, cliRunner, nil + return getConfig.shared.validate() } func balanceCmd() *cobra.Command { @@ -93,10 +78,16 @@ func balanceCmd() *cobra.Command { ), Args: cobra.MaximumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - ctx, cliRunner, err := getCliRunnerAndCtx() + ctx := context.Background() + sess := session.Must(session.NewSession()) + + adminClient, err := getConfig.shared.getAdminClient(ctx, sess, true) if err != nil { return err } + defer adminClient.Close() + + cliRunner := cli.NewCLIRunner(adminClient, log.Infof, !noSpinner) var topicName string if len(args) == 1 { @@ -114,10 +105,16 @@ func brokersCmd() *cobra.Command { Short: "Displays descriptions of each broker in the cluster.", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - ctx, cliRunner, err := getCliRunnerAndCtx() + ctx := context.Background() + sess := session.Must(session.NewSession()) + + adminClient, err := getConfig.shared.getAdminClient(ctx, sess, true) if err != nil { return err } + defer adminClient.Close() + + cliRunner := cli.NewCLIRunner(adminClient, log.Infof, !noSpinner) return cliRunner.GetBrokers(ctx, getConfig.full) }, } @@ -129,11 +126,16 @@ func configCmd() *cobra.Command { Short: "Displays configuration for the provider broker or topic.", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - ctx, cliRunner, err := getCliRunnerAndCtx() + ctx := context.Background() + sess := session.Must(session.NewSession()) + + adminClient, err := getConfig.shared.getAdminClient(ctx, sess, true) if err != nil { return err } + defer adminClient.Close() + cliRunner := cli.NewCLIRunner(adminClient, log.Infof, !noSpinner) return cliRunner.GetConfig(ctx, args[0]) }, } @@ -145,10 +147,16 @@ func groupsCmd() *cobra.Command { Short: "Displays consumer group informatin for the cluster.", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - ctx, cliRunner, err := getCliRunnerAndCtx() + ctx := context.Background() + sess := session.Must(session.NewSession()) + + adminClient, err := getConfig.shared.getAdminClient(ctx, sess, true) if err != nil { return err } + defer adminClient.Close() + + cliRunner := cli.NewCLIRunner(adminClient, log.Infof, !noSpinner) return cliRunner.GetGroups(ctx) }, } @@ -160,10 +168,16 @@ func lagsCmd() *cobra.Command { Short: "Displays consumer group lag for the specified topic and consumer group.", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - ctx, cliRunner, err := getCliRunnerAndCtx() + ctx := context.Background() + sess := session.Must(session.NewSession()) + + adminClient, err := getConfig.shared.getAdminClient(ctx, sess, true) if err != nil { return err } + defer adminClient.Close() + + cliRunner := cli.NewCLIRunner(adminClient, log.Infof, !noSpinner) return cliRunner.GetMemberLags( ctx, args[0], @@ -181,10 +195,16 @@ func membersCmd() *cobra.Command { Short: "Details of each member in the specified consumer group.", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - ctx, cliRunner, err := getCliRunnerAndCtx() + ctx := context.Background() + sess := session.Must(session.NewSession()) + + adminClient, err := getConfig.shared.getAdminClient(ctx, sess, true) if err != nil { return err } + defer adminClient.Close() + + cliRunner := cli.NewCLIRunner(adminClient, log.Infof, !noSpinner) return cliRunner.GetGroupMembers(ctx, args[0], getConfig.full) }, } @@ -196,10 +216,16 @@ func partitionsCmd() *cobra.Command { Short: "Displays partition information for the specified topic.", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - ctx, cliRunner, err := getCliRunnerAndCtx() + ctx := context.Background() + sess := session.Must(session.NewSession()) + + adminClient, err := getConfig.shared.getAdminClient(ctx, sess, true) if err != nil { return err } + defer adminClient.Close() + + cliRunner := cli.NewCLIRunner(adminClient, log.Infof, !noSpinner) return cliRunner.GetPartitions(ctx, args[0]) }, } @@ -211,10 +237,16 @@ func offsetsCmd() *cobra.Command { Short: "Displays offset information for the specified topic along with start and end times.", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - ctx, cliRunner, err := getCliRunnerAndCtx() + ctx := context.Background() + sess := session.Must(session.NewSession()) + + adminClient, err := getConfig.shared.getAdminClient(ctx, sess, true) if err != nil { return err } + defer adminClient.Close() + + cliRunner := cli.NewCLIRunner(adminClient, log.Infof, !noSpinner) return cliRunner.GetOffsets(ctx, args[0]) }, } @@ -226,10 +258,16 @@ func topicsCmd() *cobra.Command { Short: "Displays information for all topics in the cluster.", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - ctx, cliRunner, err := getCliRunnerAndCtx() + ctx := context.Background() + sess := session.Must(session.NewSession()) + + adminClient, err := getConfig.shared.getAdminClient(ctx, sess, true) if err != nil { return err } + defer adminClient.Close() + + cliRunner := cli.NewCLIRunner(adminClient, log.Infof, !noSpinner) return cliRunner.GetTopics(ctx, getConfig.full) }, }