-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Refactor command functions #859
Conversation
e1f6e02
to
a82c616
Compare
cfg := api.NewClusterConfig() | ||
ng := cfg.NewNodeGroup() | ||
rc.ClusterConfig = cfg |
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.
Since there is no other command in this context can we rename rc
to cmd
or command
which is easier to understand what is is?
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.
It's ResourceCmd
, hence rc
. Using resourceCmd
would be too verbose IMO. Calling it resource
is also kind of misleading, it's not really a resource. Maybe we could rename the struct? But I've already tried a bunch of names, and this is the only one that sticks... Anyhow, to me this PR is only start of the process, I'd rather go on to next thing and revisit this later.
We will soon need to get more refactoring done and decouple things into a library that doesn't have any assumptions about being a used in CLI, so we will have revisit this. I suspect we might turn ResourceCmd
into an interface that will have CLI-oriented implementation, and a more general one also. But it's a little too early to decide on that.
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 not just command
or cmd
? it is a resourceCmd but there could be a similar actionCmd
or similar and they would all be commands. What do you think?
@@ -14,45 +11,40 @@ import ( | |||
"github.com/weaveworks/eksctl/pkg/eks" | |||
) | |||
|
|||
func createIAMIdentityMappingCmd(g *cmdutils.Grouping) *cobra.Command { | |||
p := &api.ProviderConfig{} | |||
func createIAMIdentityMappingCmd(rc *cmdutils.ResourceCmd) { |
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.
If all these create*Cmd()
functions manipulate the first parameter, ResourceCmd
, I think it would be more idiomatic if it was the receiver of these methods. Since I don't normally expect a parameter of a function to be mutated by it. What do you think?
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.
it would be more idiomatic if it was the receiver of these methods
yes, but that means all those have to be in the same package...
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.
Since I don't normally expect a parameter of a function to be mutated by it.
It's unfortunate, but we already have too many places where *api.ClusterConfig
is passed in and mutated, which is kind of by design. We can discuss how that can be fix, but I'm not entirely sure if it the most important thing at the moment. (Only if there was a way in Go to prevent mutation!)
|
||
group.InFlagSet("General", func(fs *pflag.FlagSet) { | ||
rc.AddCommand(func() error { | ||
return doCreateIAMIdentityMapping(rc, id) |
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 sure about this cyclic dependency here: rc -> doCreateIAMIdentityMapping -> rc. I need to think about this
@@ -82,11 +68,11 @@ func doDescribeStacksCmd(p *api.ProviderConfig, cfg *api.ClusterConfig, nameArg | |||
} | |||
|
|||
for _, s := range stacks { | |||
if !describeStacksAll && *s.StackStatus == cloudformation.StackStatusDeleteComplete { |
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 think the old names here were more clear, I would leave them as they were.
Nice refactor! And I think it's great that we also rename other things like |
- create short-hand methods for defining standard commands - move most of common parameters to a struct - get rid of global state - improve overall consistency of command functions
a82c616
to
dbedfd1
Compare
I've renamed a few more things, name got rid of |
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.
If you say we will get rid of the rc
in the next PRs we can merge this
@martina-if yeah, next PR towards #813. |
Description
Checklist
make build
)make test
)make integration-test
)