-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add delete topic command #100
Closed
Closed
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package subcmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/segmentio/topicctl/pkg/cli" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var deleteCmd = &cobra.Command{ | ||
Use: "delete [resource type]", | ||
Short: "delete instances of a particular type", | ||
Long: strings.Join( | ||
[]string{ | ||
"Deletes instances of a particular type.", | ||
"Supported types currently include: topic.", | ||
"", | ||
"See the tool README for a detailed description of each one.", | ||
}, | ||
"\n", | ||
), | ||
Args: cobra.MinimumNArgs(1), | ||
RunE: deleteRun, | ||
PreRunE: deletePreRun, | ||
} | ||
|
||
type deleteCmdConfig struct { | ||
shared sharedOptions | ||
} | ||
|
||
var deleteConfig deleteCmdConfig | ||
|
||
func init() { | ||
addSharedFlags(deleteCmd, &deleteConfig.shared) | ||
RootCmd.AddCommand(deleteCmd) | ||
} | ||
|
||
func deletePreRun(cmd *cobra.Command, args []string) error { | ||
return deleteConfig.shared.validate() | ||
} | ||
|
||
func deleteRun(cmd *cobra.Command, args []string) error { | ||
ctx := context.Background() | ||
sess := session.Must(session.NewSession()) | ||
|
||
adminClient, err := deleteConfig.shared.getAdminClient(ctx, sess, false) | ||
if err != nil { | ||
return err | ||
} | ||
defer adminClient.Close() | ||
|
||
cliRunner := cli.NewCLIRunner(adminClient, log.Infof, !noSpinner) | ||
|
||
resource := args[0] | ||
|
||
switch resource { | ||
case "topic": | ||
var topicName string | ||
|
||
if len(args) == 2 { | ||
topicName = args[1] | ||
} else if len(args) > 2 { | ||
return fmt.Errorf("Can only provide one positional argument with args") | ||
} | ||
|
||
return cliRunner.DeleteTopic(ctx, topicName) | ||
default: | ||
return fmt.Errorf("Unrecognized resource type: %s", resource) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -484,6 +484,28 @@ func (c *CLIRunner) GetTopics(ctx context.Context, full bool) error { | |
return nil | ||
} | ||
|
||
// DeleteTopic deletes a single topic. | ||
func (c *CLIRunner) DeleteTopic(ctx context.Context, topic string) error { | ||
confirm, err := apply.Confirm(fmt.Sprintf("Delete topic \"%s\"", topic), false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This asks for confirmation without verifying it's an existing topic which can be confusing. In the interest of taking every step to confirm safe operation, can you add a check here that a topic of the given name exists prior to asking user confirmation? |
||
if err != nil { | ||
return err | ||
} | ||
|
||
if !confirm { | ||
return nil | ||
} | ||
|
||
c.startSpinner() | ||
err = c.adminClient.DeleteTopic(ctx, topic) | ||
c.stopSpinner() | ||
if err != nil { | ||
return err | ||
} | ||
c.printer("Success") | ||
|
||
return nil | ||
} | ||
|
||
// ResetOffsets resets the offsets for a single consumer group / topic combination. | ||
func (c *CLIRunner) ResetOffsets( | ||
ctx context.Context, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any other obvious resource types a delete function would be applicable to - did you have something in mind?