-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Conversation
efa51e7
to
9973620
Compare
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. |
Codecov Report
@@ 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
|
proto/cosmos/bank/v1beta1/cli.yaml
Outdated
tx: | ||
service: cosmos.bank.v1beta1.Msg | ||
method_options: | ||
Send: | ||
field_options: | ||
from_address: | ||
position: 0 | ||
to_address: | ||
position: 1 | ||
amount: | ||
position: 2 |
There was a problem hiding this comment.
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
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 |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
?)
proto/cosmos/bank/v1beta1/cli.yaml
Outdated
method_options: | ||
Send: | ||
use: send [from_key_or_address] [to_address] [amount...] | ||
field_options: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
@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? |
@@ -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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
@@ -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 |
There was a problem hiding this comment.
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.
# flag_options is a map of proto field names to customization options | ||
denom: | ||
shorthand: d | ||
usage: the denom to query |
There was a problem hiding this comment.
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?
* 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
* 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
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...
!
to the type prefix if API or client breaking changeCHANGELOG.md
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...
!
in the type prefix if API or client breaking change