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

feat: add auto-cli customization options #11763

Merged
merged 19 commits into from
Sep 12, 2022
Merged

Conversation

aaronc
Copy link
Member

@aaronc aaronc commented Apr 25, 2022

Description

Ref #11775


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@github-actions
Copy link
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Jun 10, 2022
@github-actions github-actions bot closed this Jun 17, 2022
@aaronc aaronc reopened this Sep 8, 2022
@aaronc aaronc mentioned this pull request Sep 8, 2022
33 tasks
@codecov
Copy link

codecov bot commented Sep 8, 2022

Codecov Report

Merging #11763 (b2e212a) into main (97a77a4) will decrease coverage by 0.02%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #11763      +/-   ##
==========================================
- Coverage   53.92%   53.89%   -0.03%     
==========================================
  Files         653      648       -5     
  Lines       55497    55342     -155     
==========================================
- Hits        29926    29827      -99     
+ Misses      23176    23130      -46     
+ Partials     2395     2385      -10     
Impacted Files Coverage Δ
x/group/keeper/keeper.go 56.25% <0.00%> (-0.40%) ⬇️
tx/textual/valuerenderer/valuerenderer.go
tx/textual/valuerenderer/bytes.go
tx/textual/valuerenderer/int.go
tx/textual/valuerenderer/timestamp.go
tx/textual/valuerenderer/dec.go
x/staking/simulation/operations.go 75.91% <0.00%> (+1.37%) ⬆️
crypto/keys/internal/ecdsa/privkey.go 83.01% <0.00%> (+1.88%) ⬆️
x/distribution/simulation/operations.go 90.32% <0.00%> (+9.67%) ⬆️

Comment on lines 1 to 11
tx:
service: cosmos.bank.v1beta1.Msg
method_options:
Send:
field_options:
from_address:
position: 0
to_address:
position: 1
amount:
position: 2
Copy link
Contributor

@ValarDragon ValarDragon Sep 8, 2022

Choose a reason for hiding this comment

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

Really nice! Perhaps a different syntax is what I'd first pass think, but I'm happy either way

Suggested change
tx:
service: cosmos.bank.v1beta1.Msg
method_options:
Send:
field_options:
from_address:
position: 0
to_address:
position: 1
amount:
position: 2
send:
proto_msg: cosmos.bank.v1beta1.MsgSend
short_example: send {from} {to} {amount}
long_example: send osmo1myAddr... osmo1toAddr... 1osmo
args:
from:
proto_field: "from_address"
to:
proto_field: 1 # highlights that we can mix field number or strings here
amount:
multi_arg_parse: # highlights that can span across multiple args
# we can skip proto_field if name is same as name of proto field

Copy link
Contributor

@ValarDragon ValarDragon Sep 8, 2022

Choose a reason for hiding this comment

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

Looking at this, theres not really any difference in CLI specification, beyond how the top level looks, and generalizing the position arg to instead proto_field.

Copy link
Member Author

@aaronc aaronc Sep 8, 2022

Choose a reason for hiding this comment

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

I see what you're getting at, but the paradigm this works on is based on doing something by default with each method and field and then allowing customization on top of that. So the code starts with the ServiceDescriptor, iterates over each method and checks if it got customized. Maybe that's counter-intuitive, but much easier to manage implementation-wise. Okay if we leave that part as is?

I can definitely add something for varargs (assuming that's what you mean by multi_arg_parse?)

method_options:
Send:
use: send [from_key_or_address] [to_address] [amount...]
field_options:
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this called field_options? Should be args or argument. Also, how do we handle flags?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is all based on protobuf services, methods, fields, etc. By default all fields become flags. This let's us customize that. I'll try to be more descriptive in the doc strings

@aaronc aaronc changed the title feat(cli/v2): add command & flag proto options feat: add auto-cli customization options Sep 8, 2022
@aaronc
Copy link
Member Author

aaronc commented Sep 8, 2022

@ValarDragon @alexanderbez I change the design based on your feedback and attempted to make this more CLI-centric rather than protobuf-centric. Is this approach more intutive?

@github-actions github-actions bot removed the stale label Sep 9, 2022
@github-actions github-actions bot added the C:CLI label Sep 9, 2022
@@ -11,7 +11,7 @@ cd proto
proto_dirs=$(find ./cosmos -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq)
for dir in $proto_dirs; do
for file in $(find "${dir}" -maxdepth 1 -name '*.proto'); do
if grep "option go_package" $file &> /dev/null ; then
if grep "option go_package.*(?!cosmos-sdk/api)" $file &> /dev/null ; then
Copy link
Member Author

Choose a reason for hiding this comment

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

this is to skip gogo generation for files which are natively generated with pulsar

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I would add a comment above the statement describing what is going on.

@aaronc aaronc marked this pull request as ready for review September 9, 2022 01:16
@aaronc aaronc requested review from a team as code owners September 9, 2022 01:16
@@ -11,7 +11,7 @@ cd proto
proto_dirs=$(find ./cosmos -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq)
for dir in $proto_dirs; do
for file in $(find "${dir}" -maxdepth 1 -name '*.proto'); do
if grep "option go_package" $file &> /dev/null ; then
if grep "option go_package.*(?!cosmos-sdk/api)" $file &> /dev/null ; then
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I would add a comment above the statement describing what is going on.

client/v2/cli/testdata/bank_example.yaml Show resolved Hide resolved
# flag_options is a map of proto field names to customization options
denom:
shorthand: d
usage: the denom to query
Copy link
Member Author

Choose a reason for hiding this comment

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

☝️ @alexanderbez here is a contrived example of flag_options. what do you think?

@aaronc aaronc enabled auto-merge (squash) September 12, 2022 15:47
@aaronc aaronc merged commit b41fd3f into main Sep 12, 2022
@aaronc aaronc deleted the aaronc/cli-v2-proto-options branch September 12, 2022 15:51
julienrbrt pushed a commit that referenced this pull request Sep 13, 2022
* feat(cli/v2): add command & flag proto options

* WIP

* docs

* update

* change name to use

* update use

* rename to autocli

* updates

* switch to (hopefully) more intuitive design

* docs

* updates

* updates

* add flag_options example
@aaronc aaronc mentioned this pull request Sep 13, 2022
19 tasks
Wryhder pushed a commit to Wryhder/cosmos-sdk that referenced this pull request Oct 26, 2022
* feat(cli/v2): add command & flag proto options

* WIP

* docs

* update

* change name to use

* update use

* rename to autocli

* updates

* switch to (hopefully) more intuitive design

* docs

* updates

* updates

* add flag_options example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants