-
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
R4R reduce module interdependancy, /client refactor #4415
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4415 +/- ##
=========================================
- Coverage 56.23% 55.4% -0.84%
=========================================
Files 244 243 -1
Lines 15411 15599 +188
=========================================
- Hits 8666 8642 -24
- Misses 6113 6330 +217
+ Partials 632 627 -5 |
I like to idea of reorganizing |
May I ask a little PR description, just to understand the goals it achieves? [I've seen now that this is a duplicated message] |
I think I got a handle on this, and I like:
What I don't like/am not sure about:
|
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'm not entirely convinced about aliasing all client
sub packages public members. However, I don't think this should block on such small thing either way. Thus, ACK
@@ -62,13 +66,13 @@ the flag --nosort is set. | |||
cmd.Flags().Bool(flagNoSort, false, "Keys passed to --multisig are taken in the order they're supplied") | |||
cmd.Flags().String(FlagPublicKey, "", "Parse a public key in bech32 format and save it to disk") | |||
cmd.Flags().BoolP(flagInteractive, "i", false, "Interactively prompt user for BIP39 passphrase and mnemonic") | |||
cmd.Flags().Bool(client.FlagUseLedger, false, "Store a local reference to a private key on a Ledger device") | |||
cmd.Flags().Bool(flags.FlagUseLedger, false, "Store a local reference to a private key on a Ledger device") |
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.
So I love the idea of the flags
package, but what about making the flags in that package pflag.Flag
s. This would allow us to pass the cmd
to a function which adds all the necessary client.Flag*
s to the cmd.FlagSet
. See:
https://godoc.org/github.com/spf13/pflag#Flag
https://godoc.org/github.com/spf13/cobra#Command.Flags
https://godoc.org/github.com/spf13/pflag#FlagSet.AddFlag
https://godoc.org/github.com/spf13/pflag
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.
oh yeah we should probably rename the packages to not conflict with the flags namespace... maybe?
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.
Yes, that's exactly what we should be doing - I'd not block this PR though
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.
@jackzampolin I think I misunderstood you when I made my first comment. In regards to using pflags
we already do unless I'm missing something. There are only 2 places in the entire repo were we import regular flags (simapp/sim_test.go
and contrib/runsim/main.go
)
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.
jack [2:44 PM]
Oh I was saying that we could refactor all of the client.Flag*
defs (currently string
type) to be *pflag.Flag
type
which would be a separate PR
Then when registering them we could pass an []*pflag.Flag{}
to the cmd
And the client/flags
package could potentially have some standard groupings
Anyway, not a big deal
It would be a separate PR.
Any thoughts on that?
fp4k [2:50 PM]
oh I see, yeah well we wouldn’t want to remove the string (because we still need it to access the flag value using viper) but we could include an additional variable which is the actual pflag
definition. I think that makes sense as an additional PR as you’ve mentioned
jack [2:50 PM]
Well the string would be under pflag.Flag.Name
fp4k [2:50 PM]
oh very good 👏
from my experience of digesting the code base, I think it's often more succinct to import one package with alias, instead of several of the root subpackages. This especially comes into play as multiple subpackages from different high level packages have duplicate package names (for example Lastly I will mention, that although I think it's usually preferable to import the high level packages, there are some occasions where importing the subpackage is required do import cycles (which is often why the subpackages are introduced to begin with!). And also there are times, when an import is only referring to a single subpackage from an import package, In this situation, depending on the absence of conflicting import names, it may desirable to import the subpackage instead of the high level package. So for all the above reasons, I think it's valuable to allow for the import of aliases, but not enforce that this is a required style, as sometimes (as explained in the second paragraph) it's actually more desirable or required to import the subpackage. As such I have not changed many of the files in the sdk which import sub-packages during this client refactor, although maybe some of them should be changed to only import the high level client package. capisce? |
@rigelrozanski |
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.
Good reorganization of the client/flags
and client/input
code as well as related refactors. LGTM 👍
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.
LGTM
@@ -13,7 +13,7 @@ import ( | |||
) | |||
|
|||
// Register REST endpoints | |||
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) { | |||
func RegisterRPCRoutes(cliCtx context.CLIContext, r *mux.Router) { |
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.
We shouldn't have done this tbh. The package is self describing. Similar to just like you don't do NewFoo
in package foo
.
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 a downside of aliasing sub packages functions at top level: you need to come up with unique names at every turn. I merged it anyway because it was consistent with @rigelrozanski's view on this.
this is all just non-critical-breaking cleanup
Targeted PR against correct branch (see CONTRIBUTING.md)
Linked to github-issue with discussion and accepted design OR link to spec that describes this work.
Wrote tests
Updated relevant documentation (
docs/
)Added a relevant changelog entry:
clog add [section] [stanza] [message]
rereviewed
Files changed
in the github PR explorerFor Admin Use: