-
Notifications
You must be signed in to change notification settings - Fork 471
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
Adds lookPathIn
#3148
Adds lookPathIn
#3148
Conversation
lookPathIn
@twpayne Need to figure out how to make this work on windows too. |
@twpayne Please approve running now. |
BREAKING CHANGE: `isExecutable` has major change for windows. It now does something
@twpayne Okay I did what I could and I'm probably going to abandon efforts to get the windows test working. The unit tests show that it does work, there is just something odd about the txtar which is causing an issue. |
This is good work, and I love the idea of this function, and I’m more than happy to give a detailed review, but… Right now I don’t love this function, and many of the comments that I would make would be covered by the concerns from this. In particular, I don’t love the fact that it’s expecting an OS-specific PATH list. (As an aside, that's a
I think that we should either embrace a variadic form ( These would allow:
The hard part about the dynamic form would be the error handling if given a non-string or non-string-array. Other questions about the dynamic form:
With the way it’s implemented now, I think that it’s really confusing — and you’re going to end up calling My preference is for dynamic, either all strings or one array (which still requires What do you guys think? |
I think if you're not assuming a platform standard it should potentially be something else. The value add are the assumptions as you take those assumptions away the work involved to use it increases. While it's a good point it doesn't help with |
But this function isn’t using PowerShell, bash, fish, or cmd to find executables, it’s using a customized copy of a Go builtin to search a list of paths…that we have to split because we are requiring that it be joined in the first place. It’s better to think of this outside of the OS box and instead think of it in terms of what we want to do and how we want to use this. I, for one, do not want to use this by having to remember to join with
We can do both, but that slightly increases the func lookPathInTemplateFunc(needle string, haystack ...any) string {
if len(haystack) == 0 {
panic(fmt.Errorf("expected at least one haystack parameter"))
}
switch haystack[0].(type) {
case string:
return chezmoi.lookPathIn(needle, haystack)
case []string:
return chezmoi.lookPathIn(needle, haystack[0])
default:
panic(fmt.Errorf("invalid haystack type, must be string or []string"))
}
} At that point, there’s no need for joining, no need to expose what the list character is, and no need for |
I agree that it makes more sense for the haystack to be a list rather than a string. chezmoi already has a |
I keep forgetting the sprig reexport exists. I will create new commits in new PRs for the broken up functions. The name of the function would not be appropriate as it's really just a minimal modification of the |
Resolves: #3141
As per: #3141
Adds
lookPathIn
Not sure the testing procedure. Followed: https://www.chezmoi.io/developer/contributing-changes/
Microcommiters hate: https://www.conventionalcommits.org/en/v1.0.0/#summary -_-