Skip to content
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

pdctl: support filter json output by calling external jq #1126

Merged
merged 6 commits into from
Jul 11, 2018

Conversation

disksing
Copy link
Contributor

@disksing disksing commented Jun 28, 2018

What have you changed? (required)

  • support jq query to format the output of region and store command
  • import package shellwords to split command line strings
  • Note: it requires jq be installed in the system. We may want to include a jq binary in our release package.

What are the type of the changes (required)?

  • New feature (non-breaking change which adds functionality)

How has this PR been tested (required)?

  • start a local cluster to test jq queries.

Does this PR affect documentation (docs/docs-cn) update? (optional)

Yes. See pingcap/docs-cn#790

Copy link
Contributor

@nolouch nolouch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@Connor1996 Connor1996 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a reference of related documentation PR.

@@ -42,7 +43,7 @@ type regionInfo struct {
// NewRegionCommand return a region subcommand of rootCmd
func NewRegionCommand() *cobra.Command {
r := &cobra.Command{
Use: "region <region_id>",
Use: `region <region_id> [-jq="<query string>"]`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only support some commands?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Only support APIs that query region/store list. The results returned by other APIs are simple and easy to see with the naked eye.

@@ -82,6 +84,11 @@ func showRegionCommandFunc(cmd *cobra.Command, args []string) {
fmt.Printf("Failed to get region: %s\n", err)
return
}
if flag := cmd.Flag("jq"); flag != nil && flag.Value.String() != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we provide a Print interface for jq or standard output?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible but I don't think it's necessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seem better to extract to a function like isJQUsed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to over-abstract, --jq is not a general parameter. these two commands just happen to both support it.

Copy link
Contributor

@siddontang siddontang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@disksing disksing merged commit 722081d into tikv:master Jul 11, 2018
@disksing disksing deleted the jq branch July 11, 2018 02:43
nolouch pushed a commit to nolouch/pd that referenced this pull request Aug 15, 2018
* pdctl: support filter json output by calling external jq

* update vendor

* support jq for store command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants