Skip to content

Conversation

@mislav
Copy link
Contributor

@mislav mislav commented Nov 14, 2022

Examples:

gh api -f labels[]=bug -f labels[]=p1
#=> { "labels": ["bug", "p1"] }

gh api -f branch[name]=patch-1 -F branch[protected]=true
#=> { "branch": { "name": "patch-1", "protected": true }

Fixes #1484

Examples:

	-f labels[]=bug -f labels[]=p1
        #=> { "labels": ["bug", "p1"] }

	-f branch[name]=patch-1 -F branch[protected]=true
        #=> { "branch": { "name": "patch-1", "protected": true }
@mislav mislav requested a review from a team as a code owner November 14, 2022 17:30
@mislav mislav requested review from vilmibm and removed request for a team November 14, 2022 17:30
Copy link
Contributor

@samcoe samcoe left a comment

Choose a reason for hiding this comment

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

This looks good to me. I would like to see this new feature syntax documented in the api command help section or perhaps in a new top level help topic.

Two discussion questions:

  1. Was there thoughts on adding deep nesting support, e.g -f branch[foo[bar]]=patch-1?
  2. What do you think about changing the array syntax to be []key rather than key[]? Perhaps I have been looking at too much Go code, but the brackets in front seem more natural to me.

@mislav
Copy link
Contributor Author

mislav commented Dec 22, 2022

@samcoe Thanks for the review!

  1. Was there thoughts on adding deep nesting support, e.g -f branch[foo[bar]]=patch-1?

Great idea! Just added with the syntax branch[foo][bar]=patch1.

  1. What do you think about changing the array syntax to be []key rather than key[]? Perhaps I have been looking at too much Go code, but the brackets in front seem more natural to me.

The newest code supports interspersed nested object/array syntax, e.g.:

-f labels[][name]=bug
-f labels[][color]=red
-f labels[][name]=feature
-f labels[][color]=green

This results in a labels array populated with objects that each have fields {name,color}. To support this case, I think that key[] syntax is more consistent than []key because it's similar to the syntax for nested objects (except that empty brackets signify that there is no key name).

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.

Allow JSON array parameters in gh api

3 participants