Skip to content

Commit

Permalink
store_command: propagate the error code to the root command (#8798)
Browse files Browse the repository at this point in the history
ref #8762

Signed-off-by: Boyang Lyu <[email protected]>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
JackL9u and ti-chi-bot[bot] authored Nov 12, 2024
1 parent 2637331 commit bb4c437
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions tools/pd-ctl/pdctl/command/store_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func NewDeleteStoreByAddrCommand() *cobra.Command {
d := &cobra.Command{
Use: "addr <address>",
Short: "delete store by its address",
Run: deleteStoreCommandByAddrFunc,
RunE: deleteStoreCommandByAddrFunc,
}
return d
}
Expand Down Expand Up @@ -378,19 +378,19 @@ func deleteStoreCommandFunc(cmd *cobra.Command, args []string) {
cmd.Println("Success!")
}

func deleteStoreCommandByAddrFunc(cmd *cobra.Command, args []string) {
func deleteStoreCommandByAddrFunc(cmd *cobra.Command, args []string) error {
id := getStoreID(cmd, args, false)
if id == -1 {
return
return fmt.Errorf("address not found: %s", args[0])
}
// delete store by its ID
prefix := fmt.Sprintf(storePrefix, id)
_, err := doRequest(cmd, prefix, http.MethodDelete, http.Header{})
if err != nil {
cmd.Printf("Failed to delete store %s: %s\n", args[0], err)
return
return fmt.Errorf("failed to delete store %s: %s", args[0], err)
}
cmd.Println("Success!")
return nil
}

func cancelDeleteStoreCommandFunc(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -436,6 +436,10 @@ func cancelDeleteStoreCommandFunc(cmd *cobra.Command, args []string) {

func cancelDeleteStoreCommandByAddrFunc(cmd *cobra.Command, args []string) {
id := getStoreID(cmd, args, true)
if id == -1 {
cmd.Printf("address not found: %s\n", args[0])
return
}
if id == 0 {
return
}
Expand Down Expand Up @@ -490,9 +494,6 @@ func getStoreID(cmd *cobra.Command, args []string, isCancel bool) (id int) {
}
}

if id == -1 {
cmd.Printf("address not found: %s\n", addr)
}
return
}

Expand Down

0 comments on commit bb4c437

Please sign in to comment.