-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
cli: improve structure and reduce magic #721
Comments
Here's an example of the kind of madness we currently employ to help illustrate the problem with the current design: https://github.com/cosmos/cosmos-sdk/blob/master/x/bank/rest/sendtx.go#L77 This is in a REST handler:
I think this helps justify that the |
Are plaintext passwords passed through REST, or do we want the ability to do that? I don't see anything other than reading the password from stdin. |
Currently they are passed through REST yes |
Please see some relevant discussion here: #595 |
Are modules usually expected to expose the same functionality in CLI and REST? Might be worth separating further - each module could include three packages: |
No, I think we should still make sure modules keep their "command" functions (e.g. Also not sure about the Naming category in the original issue - do we want to change names globally? Only within some subset of the code? |
This is a more concrete replacement of #560
The CLI/REST is a bit of a mess right now because of the abusive use of viper and stdin. There is common functionality to both the CLI and REST that is the actual stuff we want to do. This should be in its own package and well contained and easily testable without any dependence on viper or stdin. This is the goal of the
client/builder
, which we should callclient/core
. The surroundingclient
package can have convenience functions for mapping from viper/stdin to the things we need incore
.Here are some more concrete points for what we should do.
Naming
CmdAccount
,CmdAccountDefault
AccountDecoderFn
client/builder
->client/core
Note in general functions that return functions should end in
Fn
.Structure
Each concern (x/auth, x/bank, client/keys, etc.) should have
cli
andrest
pkgs whose primary objectives are to parse all the arguments from either viper/cobra or http and forward them to theclient/builder
.Currently the builder calls
client.GetNode
and makes various calls toviper
. We should eliminate those fully - thebuilder
should have ZERO calls to global functions/variables.To avoid dumping args into the builder functions, they can be methods on one or some structs. These structs should have all the things we would otherwise get from viper, stdin, etc., like node address, chain-id, password, etc.
We should have helper functions in
client
that read from viper/stdin/etc. into thebuilder
structsThe text was updated successfully, but these errors were encountered: