-
Notifications
You must be signed in to change notification settings - Fork 369
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
Check whether PATH has been set up correctly #489
Check whether PATH has been set up correctly #489
Conversation
Codecov Report
@@ Coverage Diff @@
## master #489 +/- ##
========================================
+ Coverage 56.47% 57% +0.52%
========================================
Files 19 21 +2
Lines 926 956 +30
========================================
+ Hits 523 545 +22
- Misses 350 357 +7
- Partials 53 54 +1
Continue to review full report at Codecov.
|
internal/assertion/setup.go
Outdated
export PATH="${PATH}:${HOME}/.krew/bin"` | ||
) | ||
|
||
func CheckSetup(w io.Writer, paths environment.Paths) { |
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.
tbh the "assert" in the package name could make one think this works like "assert" keyword, but it doesn't. maybe pkg internal/platform
?
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 struggling with a good package name. installation
and environment
would make most sense to me, but those are taken already. platform
doesn't quite ring the right bells to me (although it's better than assertion
).
What do you think about internal/setup.WarnIfBinDirNotInPATH
?
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 went with setup
for now. Let me know your thoughts.
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.
Maybe shouldnt be in a separate pkg :)
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.
😃 That could simplify the naming. How about the environment
package?
Thanks for your comments! PTAL |
internal/setup/warning.go
Outdated
} | ||
|
||
krewPluginPath := paths.BinPath() | ||
return strings.Contains(os.Getenv("PATH"), krewPluginPath) |
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.
Let's use if there's an utility in kubectl plugin PATH scanning logic.
If not, please separate by os.PathListSeparator
, and do a ==
check; not Contains
.
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.
Doesn't really look like they have a dedicated util for that: https://github.com/kubernetes/kubernetes/blob/5cc945ad0d2fad2bdde7591490fcf0401fa335aa/staging/src/k8s.io/kubectl/pkg/cmd/plugin/plugin.go#L105
But checking for equality sounds right.
internal/setup/warning_test.go
Outdated
"sigs.k8s.io/krew/internal/testutil" | ||
) | ||
|
||
func TestCheckSetup_firstRun(t *testing.T) { |
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.
rm test func names :)
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 guess you meant the forgotten rename?
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 don't know what I was saying above.
I think I meant make sure Test names are the same as func name.
This PR is getting too large. Can we split that out to a different PR so that I don't lose context? IMO this functionality can be in |
d01868b
to
dba682a
Compare
Homebrew refuses to add a post-install message for setting up the PATH variable with krew's plugin store. Therefore we need to check this on our side to warn users about an incomplete setup. The goal is to - print specific instructions for each shell/OS. - not print the instructions when krew installs itself.
dba682a
to
d065358
Compare
Err.. I agree. This has gotten a little out of hand. It should be simpler now. PTAL |
paths := environment.NewPaths(tempDir.Path("does-not-exist")) | ||
res := IsBinDirInPATH(paths) | ||
if res == false { | ||
t.Errorf("Expected positive result on first run") |
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.
nit: start error messages lowercase
if err := os.Mkdir(tempDir.Path("exists"), os.ModePerm); err != nil { | ||
t.Fatal(err) | ||
} |
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.
can we just pass tempDir as path, instead of creating a dir called "exists"?
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.
Sure. I wanted to make it more explicit that the directory is there vs. the non-existent case. But I guess this will do as well.
/lgtm I think it's gotten to 200 lines mostly because we added shell-specific handling, which is a better UX anyway. |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ahmetb, corneliusweig The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/hold cancel |
Fixes #485
Related Homebrew/homebrew-core#49547
Homebrew refuses to add a post-install message for setting up
the PATH variable with krew's plugin store. Therefore we need
to check this on our side to warn users about an incomplete
setup. The goal is to