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

Add "goda why" or similar command #44

Closed
howardjohn opened this issue Feb 9, 2021 · 4 comments
Closed

Add "goda why" or similar command #44

howardjohn opened this issue Feb 9, 2021 · 4 comments

Comments

@howardjohn
Copy link

I have very often wanted to run a command to see why a dependency is required. This could be similar to go mod why, although that command is lacking a bit of functionality.

Essentially, given an import tree of

.
 ├  a
   ├ b
   ├ c
 ├ d
   ├  c 
 ├  c 

I would like a command like: goda why . c I would expect:

$ goda why . c
. -> a -> c
. -> d -> c
. -> c

From this, I can see all of the places I need to clean up usages of c if I want to drop the dependency.

I have done this exact thing before using a bunch of ad-hoc goda commands, resulting in out binary sizes being cut in half, so I think it would be pretty useful. It feels like all of the information is there, but not presentable in this way. Its also possible I just haven't found the right expressions to represent this.

Alternatives:

  • Modify graph/tree in some way to allow filtering out packages not in the path of c. For example, the above tree would be filtered to:
.
 ├  a
   ├ c
 ├ d
   ├  c 
 ├  c 

Here the tree is pretty much the same, but in our real repo the tree is 12k lines so its not usable for this use case. The same with the graph - its too big to read without filtering

@egonelbre
Copy link
Member

egonelbre commented Feb 10, 2021

You can use goda graph "reach(., c:root)" to get the necessary graph.

Also there's goda help expr that prints the help about the expressions.

@egonelbre
Copy link
Member

Also sometimes using goda graph "transitive(reach(., c:root))" can be a nicer graph to work with.

@howardjohn
Copy link
Author

Ah fantastic, I only tried goda tree and goda list with reach which is why I had problems since it doesn't have an expr. This works great!

Is there any reason tree doesn't support expr? If its just not enough time to implement it I may be interested in sending a PR if I find some time and you are interested - let me know. Otherwise, seems like this can be closed now. Thanks for the help + the great tool

@egonelbre
Copy link
Member

Honestly, I don't see a reason why it couldn't support it.

And, if you want to take a stab at it, then great.

Basically, you need to replace https://github.com/loov/goda/blob/master/tree/cmd.go#L48 with code https://github.com/loov/goda/blob/master/graph/cmd.go#L75 and then adjust the printing to work with the result.

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

No branches or pull requests

2 participants