From 07dda9b1a19711ccf0f647ae38b0d6c6e01e2329 Mon Sep 17 00:00:00 2001 From: vvatanabe Date: Fri, 3 Nov 2023 07:37:56 +0900 Subject: [PATCH] feat: implements invalid as a subcommand --- internal/cmd/invalid.go | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 internal/cmd/invalid.go diff --git a/internal/cmd/invalid.go b/internal/cmd/invalid.go new file mode 100644 index 0000000..b33b344 --- /dev/null +++ b/internal/cmd/invalid.go @@ -0,0 +1,44 @@ +package cmd + +import ( + "context" + + "github.com/spf13/cobra" + "github.com/vvatanabe/dynamomq" +) + +var invalidCmd = &cobra.Command{ + Use: "invalid", + Short: "Remove a message from the standard queue to dead letter queue (DLQ) for manual fix", + Long: `Remove a message from the standard queue to dead letter queue (DLQ) for manual fix.`, + Run: func(cmd *cobra.Command, args []string) { + ctx := context.Background() + client, _, err := createDynamoMQClient[any](ctx, flgs) + if err != nil { + printError(err) + return + } + id := flgs.ID + _, err = client.MoveMessageToDLQ(ctx, &dynamomq.MoveMessageToDLQInput{ + ID: id, + }) + if err != nil { + printError(err) + return + } + printMessageWithData("", InvalidResult{ID: id}) + return + }, +} + +type InvalidResult struct { + ID string `json:"id"` +} + +func init() { + rootCmd.AddCommand(invalidCmd) + invalidCmd.Flags().StringVar(&flgs.TableName, flagMap.TableName.Name, flagMap.TableName.Value, flagMap.TableName.Usage) + invalidCmd.Flags().StringVar(&flgs.QueueingIndexName, flagMap.QueueingIndexName.Name, flagMap.QueueingIndexName.Value, flagMap.QueueingIndexName.Usage) + invalidCmd.Flags().StringVar(&flgs.EndpointURL, flagMap.EndpointURL.Name, flagMap.EndpointURL.Value, flagMap.EndpointURL.Usage) + invalidCmd.Flags().StringVar(&flgs.ID, flagMap.ID.Name, flagMap.ID.Value, flagMap.ID.Usage) +}