-
Notifications
You must be signed in to change notification settings - Fork 699
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
Expand paths with tilde #512
Conversation
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.
Need a test, and do we need a dependency, is the logic that complex?
No, the logic isn't complex. However, the dep seems to handle a lot of edge cases. If we only want to solve the simple case, then we could probably just do this.
Maybe at some point we'll get an issue saying that there is a bug in the expansion logic. Or maybe not. Another option is that we could just copy the file over into the nats repo (with all the license stuff). |
IMO checking whether $HOME or $home are being defined in env when |
In my experience this handles the bulk of cases, hashi one is undeniably better but this is good enough for me.
|
I prefer to limit the dependencies unless we absolutely have to have them. |
All right. Implemented Wasn't sure if I should add tests for windows as well... I probably should, right? |
80090af
to
9d1c72d
Compare
Oookay, so turns out this homedir function is already in the stdlib. The other one in So, I deleted the original function we had. I also cross compiled from Linux to Windows to verify One weird thing is I'm not sure how Windows users expect to give us a path. I added some Windows tests too, hopefully @ColinSullivan1 can take a look at those to see if they make sense. |
nats_test.go
Outdated
|
||
// missing USERPROFILE env var | ||
{path: "~/fizz", wantErr: true}, | ||
} |
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.
Hey, @ColinSullivan1. Are these paths normally how Windows folks would give us a path?
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.
Not normally, unless running in some type of non-standard shell. paths would be \\foo\\bar
, with backslashes escaped for the test. However, programmatically, /
is accepted.
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.
Cool. Backtick strings allow you to write a literal without escaping.
`\foo\bar` == "\\foo\\bar"
So is this fine?
nats_test.go
Outdated
func TestExpandTildePath(t *testing.T) { | ||
t.Run("unix", func(t *testing.T) { | ||
if runtime.GOOS == "windows" { | ||
t.Skip() |
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 see if we can get one of these from @ColinSullivan1
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.
Will do...
nats.go
Outdated
return p, nil | ||
} | ||
|
||
home, err := os.UserHomeDir() |
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.
Golang doesn't check for %HOMEDRIVE%%HOMEPATH%
which is also used. It'd be more complicated but great for users if env var expansion in general was supported.
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.
Okay. I think we can do this with os.ExpandEnv
.
|
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.
The comment that I have is with the use of t.Errorf() instead of t.Fatalf(). We usually use the later and the reason is that there is no reason to continue the test when some error occurs.
3671bb5
to
20e4898
Compare
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.
You still have 2 places with Errorf() instead of Fatalf().
Currently, if you pass a path with a tilde to nats.UserCredentials it fails because it doesn't expand the tilde to mean the user's home directory. This change adds support to expand paths with a tilde, such as "~/.nkeys".
20e4898
to
02f4e95
Compare
Cool, good catch. Updated. |
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.
LGTM
Congrats! First PR merge! |
Currently, if you pass a path with a tilde to nats.UserCredentials it fails
because it doesn't expand the tilde to mean the user's home directory.
This change adds support to expand paths with a tilde, such as "~/.nkeys".
Resolves #509