Skip to content

Commit

Permalink
make some region_command support jq (#1420)
Browse files Browse the repository at this point in the history
* make some region_command support jq
Signed-off-by: fredchenbj <[email protected]>
  • Loading branch information
fredbjer authored and nolouch committed Jan 29, 2019
1 parent 8d6c936 commit 21a3537
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions tools/pd-ctl/pdctl/command/region_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,42 +59,47 @@ func NewRegionCommand() *cobra.Command {
r.AddCommand(NewRegionsWithStartKeyCommand())

topRead := &cobra.Command{
Use: "topread <limit>",
Use: `topread <limit> [--jq="<query string>"]`,
Short: "show regions with top read flow",
Run: showRegionTopReadCommandFunc,
}
topRead.Flags().String("jq", "", "jq query")
r.AddCommand(topRead)

topWrite := &cobra.Command{
Use: "topwrite <limit>",
Use: `topwrite <limit> [--jq="<query string>"]`,
Short: "show regions with top write flow",
Run: showRegionTopWriteCommandFunc,
}
topWrite.Flags().String("jq", "", "jq query")
r.AddCommand(topWrite)

topConfVer := &cobra.Command{
Use: "topconfver <limit>",
Use: `topconfver <limit> [--jq="<query string>"]`,
Short: "show regions with top conf version",
Run: showRegionTopConfVerCommandFunc,
}
topConfVer.Flags().String("jq", "", "jq query")
r.AddCommand(topConfVer)

topVersion := &cobra.Command{
Use: "topversion <limit>",
Use: `topversion <limit> [--jq="<query string>"]`,
Short: "show regions with top version",
Run: showRegionTopVersionCommandFunc,
}
topVersion.Flags().String("jq", "", "jq query")
r.AddCommand(topVersion)

topSize := &cobra.Command{
Use: "topsize <limit>",
Use: `topsize <limit> [--jq="<query string>"]`,
Short: "show regions with top size",
Run: showRegionTopSizeCommandFunc,
}
topSize.Flags().String("jq", "", "jq query")
r.AddCommand(topSize)

scanRegion := &cobra.Command{
Use: `scan [-jq="<query string>"]`,
Use: `scan [--jq="<query string>"]`,
Short: "scan all regions",
Run: scanRegionCommandFunc,
}
Expand Down Expand Up @@ -188,6 +193,10 @@ func showRegionTopWriteCommandFunc(cmd *cobra.Command, args []string) {
cmd.Printf("Failed to get regions: %s\n", err)
return
}
if flag := cmd.Flag("jq"); flag != nil && flag.Value.String() != "" {
printWithJQFilter(r, flag.Value.String())
return
}
cmd.Println(r)
}

Expand All @@ -205,6 +214,10 @@ func showRegionTopReadCommandFunc(cmd *cobra.Command, args []string) {
cmd.Printf("Failed to get regions: %s\n", err)
return
}
if flag := cmd.Flag("jq"); flag != nil && flag.Value.String() != "" {
printWithJQFilter(r, flag.Value.String())
return
}
cmd.Println(r)
}

Expand All @@ -222,6 +235,10 @@ func showRegionTopConfVerCommandFunc(cmd *cobra.Command, args []string) {
cmd.Printf("Failed to get regions: %s\n", err)
return
}
if flag := cmd.Flag("jq"); flag != nil && flag.Value.String() != "" {
printWithJQFilter(r, flag.Value.String())
return
}
cmd.Println(r)
}

Expand All @@ -239,6 +256,10 @@ func showRegionTopVersionCommandFunc(cmd *cobra.Command, args []string) {
cmd.Printf("Failed to get regions: %s\n", err)
return
}
if flag := cmd.Flag("jq"); flag != nil && flag.Value.String() != "" {
printWithJQFilter(r, flag.Value.String())
return
}
cmd.Println(r)
}

Expand All @@ -256,6 +277,10 @@ func showRegionTopSizeCommandFunc(cmd *cobra.Command, args []string) {
cmd.Printf("Failed to get regions: %s\n", err)
return
}
if flag := cmd.Flag("jq"); flag != nil && flag.Value.String() != "" {
printWithJQFilter(r, flag.Value.String())
return
}
cmd.Println(r)
}

Expand Down

0 comments on commit 21a3537

Please sign in to comment.