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

Use reflection + Generics to delete most CLI boilerplate for queries #3611

Merged
merged 45 commits into from
Dec 5, 2022

Conversation

ValarDragon
Copy link
Member

@ValarDragon ValarDragon commented Dec 3, 2022

What is the purpose of the change

Cleans up some CLI boilerplate. Mostly was using it as an exercise to play around with ChatGPT

Brief Changelog

  • Less lines of code to create an index command
  • Make a generic to create our query commands
  • Make a generic to create our tx commands
  • Make a generics + reflection approach to automatically get code for "simple" queries
  • Index commands have more succinct outputs:
    Before:
    image
    After:
    image

Testing and Verifying

  • Manually verified index commands still work, just more succinctly.
  • Manually verified all query commands altered work as before. Two modules not changed (Superlfuid and one other), because they do a non-standard unwrapping of the proto response.
  • Other TWAP commands just had code moves.

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes? (yes / no)
  • Is a relevant changelog entry added to the Unreleased section in CHANGELOG.md? (yes / no)
  • How is the feature or change documented? (not applicable / specification (x/<module>/spec/) / Osmosis docs repo / not documented)

@github-actions github-actions bot added C:CLI C:x/incentives C:x/twap Changes to the twap module labels Dec 3, 2022
@ValarDragon ValarDragon added V:state/compatible/backport State machine compatible PR, should be backported A:backport/v13.x backport patches to v13.x branch labels Dec 3, 2022
@ValarDragon ValarDragon changed the title More CLI boilerplate cleanup Use reflection + Generics to delete most CLI boilerplate for queries Dec 3, 2022
@ValarDragon
Copy link
Member Author

ValarDragon commented Dec 5, 2022

Limitation for certain classes of further tx deletion:

  • We should be able to parse ValAddr just fine as it stands, but I don't have a convenient way to test out the superfluid txs commands on testnet, to ensure they work if I did that. So holding off for now
  • Need to just add sdk.Int parsing support, then we can knock out ~half of gamm txs
  • A lot of commands use flags when they really shouldn't. Need more generic custom "use flag" support. EDIT: Added this!
  • Gov commands (needs a third, related, cmd scaffolding). I'm thinking separate issue/PR.

@github-actions github-actions bot added the C:app-wiring Changes to the app folder label Dec 5, 2022
Copy link
Member

@p0mvn p0mvn left a comment

Choose a reason for hiding this comment

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

Looks great to me! Amazing work.

General suggestions/questions:

  • Although most CLI functions are self-explanatory, godocs would still be helpful in many cases. E.g: ParseField. Also, for consistency with the repo.
  • What is the testing strategy for this?

osmoutils/generic_helper.go Show resolved Hide resolved
osmoutils/osmocli/index_cmd.go Show resolved Hide resolved
fVal := v.Field(fieldIndex)
fType := t.Field(fieldIndex)

// fmt.Printf("Field %d: %s %s %s\n", fieldIndex, fType.Name, fType.Type, fType.Type.Kind())
Copy link
Member

Choose a reason for hiding this comment

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

Since this is turning into a discussion, I would like to chime in with some thoughts as well.

I agree that these are valuable for debugging purposes. However, I don't think that leaving commented-out prints should be the direction.

I agree with @nicolaslara that we should be using a toggle. I would even go beyond that to suggest using various log levels - debug, info etc. Each log should be analyzed in the review whether it adds value, including its log level. Otherwise, we will eventually have a system full of misc logs at the info level.

In my opinion, raw commented-out prints only add additional complexity to a system. So we should be using a logger with a configured tracing level.

If we don't take proper care to analyze the value of each in the review, the system will eventually become polluted with comments.

osmoutils/osmocli/parsers.go Outdated Show resolved Hide resolved
osmoutils/osmocli/parsers.go Outdated Show resolved Hide resolved
osmoutils/osmocli/parsers.go Outdated Show resolved Hide resolved

// TODO: Make this able to read from some local alias file for denoms.
func ParseCoins(arg string, fieldName string) (sdk.Coins, error) {
coins, err := sdk.ParseCoinsNormalized(arg)
Copy link
Member

Choose a reason for hiding this comment

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

There are some cases where sdk.ParseCoinsNormalized doesn't work. For example, here:

deposit, err := ParseCoinsNoSort(flags.InitialDeposit)

Is that case handled in this PR?

Copy link
Member

Choose a reason for hiding this comment

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

Took a quick peek. Looks like ParseCoinsNoSort is still used in the right place

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, explicitly didn't replace those for now. Need to add a way to set a custom per-field parser to get those replaced

@ValarDragon
Copy link
Member Author

Testing strategy:

  • Existing queries and CLI commands all still work at feature parity right now
    • All of the (admittedly bad) old tests still work
  • We can add some golang tests for the parse methods

@ValarDragon
Copy link
Member Author

Thanks for the reviews! Will get godocs added onto those primary parse methods

@@ -84,7 +84,7 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r

// GetTxCmd returns the capability module's root tx command.
func (a AppModuleBasic) GetTxCmd() *cobra.Command {
return cli.GetTxCmd()
return nil
Copy link
Member

Choose a reason for hiding this comment

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

What is the long term plan for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

wdym, it has no TX command?

Long term plan is that you don't have to implement this function for interface compat, if you don't use a tx cli

Copy link
Member

Choose a reason for hiding this comment

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

Ah, was trying to figure out why we were returning GetTxCmd before, makes sense

return cmd
}

// TODO: Change these flags to args. Required flags don't make that much sense.
Copy link
Member

Choose a reason for hiding this comment

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

YES lol

@ValarDragon ValarDragon merged commit ce98bbb into main Dec 5, 2022
@ValarDragon ValarDragon deleted the dev/more_cli_boilerplate_cleanup branch December 5, 2022 21:59
mergify bot pushed a commit that referenced this pull request Dec 5, 2022
…3611)

Makes new, far more succinct methods, to build tx and query CLI's

(cherry picked from commit ce98bbb)

# Conflicts:
#	x/valset-pref/client/cli/query.go
#	x/valset-pref/client/cli/tx.go
ValarDragon added a commit that referenced this pull request Dec 5, 2022
…(backport #3611) (#3633)

Makes new, far more succinct methods, to build tx and query CLI's

Co-authored-by: Dev Ojha <[email protected]>
Co-authored-by: Dev Ojha <[email protected]>
@ValarDragon ValarDragon mentioned this pull request Dec 6, 2022
7 tasks
@github-actions github-actions bot mentioned this pull request Mar 15, 2024
@github-actions github-actions bot mentioned this pull request Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:backport/v13.x backport patches to v13.x branch C:app-wiring Changes to the app folder C:CLI C:x/epochs C:x/gamm Changes, features and bugs related to the gamm module. C:x/incentives C:x/lockup C:x/mint C:x/pool-incentives C:x/superfluid C:x/tokenfactory C:x/twap Changes to the twap module C:x/txfees V:state/compatible/backport State machine compatible PR, should be backported
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

4 participants