-
Notifications
You must be signed in to change notification settings - Fork 21
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 the command utils package #33
base: main
Are you sure you want to change the base?
Conversation
- decrease amount of duplicate code - add some comments - update readme
cli/command/argParsingHelpers.go
Outdated
|
||
import "github.com/urfave/cli/v2" | ||
|
||
func prependArgParsingToAction(c *cli.Command, argName string, argGetter func(ctx *cli.Context) (string, error)) cli.ActionFunc { |
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 the point but this function makes it harder to read and understand the code. So I suggest you drop it.
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.
Fair. I thought there should be a helper for that but I agree that it ended up being very verbose and somewhat complicated. Removed it in 5d616c3
cli/command/universeN.go
Outdated
|
||
// Attaches universe argument parsing to a command. | ||
// `pos` is position of the universe argument, expected to be 0 or 1. | ||
func UniverseAtPos(c *cli.Command, pos int) { |
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.
Do you need to export it?
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, thanks. I forgot the meaning of the capital letters. Fixed in 9801c78
cli/command/universeN.go
Outdated
} | ||
} | ||
|
||
c.Action = prependArgParsingToAction(c, "universe", func(ctx *cli.Context) (string, error) { |
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.
see comment about prependArgParsingToAction
- rename to universeAtPos
Reading through the
cli
folder contents I thought that the command utils were a little messy and had lot of duplicate code. I am not very experienced in Go so I am not familiar with the conventions, however, I think I made some improvements.I thought about adding a commit with more comments for some of the individual commands but those actually have a decent amount of documentation or the function names are self explanatory.
This isn't exactly what I have been asked for but I think it demonstrates my understanding of what I studied and it might even be useful/worth merging.