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

Refactor the command utils package #33

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

honzaflash
Copy link

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.

  • decrease amount of duplicate code
  • add some comments
  • update readme

- decrease amount of duplicate code
- add some comments
- update readme

import "github.com/urfave/cli/v2"

func prependArgParsingToAction(c *cli.Command, argName string, argGetter func(ctx *cli.Context) (string, error)) cli.ActionFunc {
Copy link
Contributor

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.

Copy link
Author

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


// 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) {
Copy link
Contributor

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?

Copy link
Author

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

}
}

c.Action = prependArgParsingToAction(c, "universe", func(ctx *cli.Context) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

see comment about prependArgParsingToAction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants