Skip to content

Commit

Permalink
fix issues from get subcmd refactor (#151)
Browse files Browse the repository at this point in the history
* Revert "pr feedback"

This reverts commit 07667dd.

* fix debug flag for get subcommand
  • Loading branch information
petedannemann authored Sep 18, 2023
1 parent 7ac2269 commit a16112f
Showing 1 changed file with 65 additions and 27 deletions.
92 changes: 65 additions & 27 deletions cmd/topicctl/subcmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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)
},
}
Expand All @@ -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])
},
}
Expand All @@ -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)
},
}
Expand All @@ -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],
Expand All @@ -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)
},
}
Expand All @@ -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])
},
}
Expand All @@ -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])
},
}
Expand All @@ -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)
},
}
Expand Down

0 comments on commit a16112f

Please sign in to comment.