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

Cannot retrieve unmodified argument to nave use from environment #123

Closed
rulatir opened this issue Jan 22, 2023 · 8 comments
Closed

Cannot retrieve unmodified argument to nave use from environment #123

rulatir opened this issue Jan 22, 2023 · 8 comments

Comments

@rulatir
Copy link
Contributor

rulatir commented Jan 22, 2023

$ echo $NAVE_NODE_MODERN
v19.2
$ nave use $NAVE_NODE_MODERN bash -c 'echo $NAVEVERSION'
19.2.0
$ nave use $NAVE_NODE_MODERN bash -c 'echo $NAVENAME'
19.2.0
$ nave use $NAVE_NODE_MODERN bash -c 'echo $NAVE'
19.2.0

It seems that scripts ran by nave, likely including .naverc, have no way of accessing the original unmodified version choice argument passed to nave use. This is probably a bug; specifically, my intuition is that the $NAVENAME environment variable should contain this unmodified argument.

@isaacs
Copy link
Owner

isaacs commented Jan 22, 2023

Hmm it'd have to be something other than $NAVENAME, since that's load bearing to determine whether you're in a symlinked named env or direct in the version folder. But it should be straightforward to add a new env, and I can see the value in it. Maybe $NAVEARG?

@rulatir
Copy link
Contributor Author

rulatir commented Jan 23, 2023

So if I add a named environment and say nave use my-named-env bash -c 'echo $NAVENAME', it will say 'my-named-env'?

@isaacs
Copy link
Owner

isaacs commented Jan 25, 2023

Yup!

$ nave use my-named-env 16 bash -c 'echo $NAVENAME'
Creating new env named 'my-named-env' using node 16.19.0
my-named-env

@isaacs
Copy link
Owner

isaacs commented Jan 25, 2023

Once it's created, you don't have to specify a version (or you don't have to initially, but it'll prompt you if it doesn't exist already). So, if it doesn't exist, it's not 100% headless (though you can echo $version | ... and that'll answer the prompt.)

Also, nave use <name> is a little bit clever, idk if it's clear from the example above. If the first argument is a valid node semver argument (like 18.0.1 or 16.3) then it'll create/update the named env to use that. Otherwise, it treats all remaining arguments as a command to run.

$ nave use my-named-env bash -c 'echo $NAVENAME'
my-named-env

$ nave use named-env-that-does-not-exist-yet bash -c 'echo $NAVENAME'
What version of node?
lts, lts/<name>, latest, x.y, or x.y.z > 16
Creating new env named 'named-env-that-does-not-exist-yet' using node 16.19.0
named-env-that-does-not-exist-yet

@isaacs isaacs closed this as completed in 27fd39f Jan 25, 2023
@isaacs
Copy link
Owner

isaacs commented Jan 25, 2023

Shipped 3.5.0, which now sets $NAVEVERSIONARG to the raw version argument provided.

In the case of nave use named-env without supplying a version, it is set to the resulting full version, because at least that way it's reliably set to something that we know would resolve to the version in use.

One weird side effect of this is that if you don't supply a version, and the named env doesn't yet exist, then it'll prompt the user for an argument but will not set $NAVEVERSIONARG to that argument. It'd be a bit of refactoring to capture that input in a way that the caller of add_named_env can get at it, and I figured it's enough of an edge case to not be worth it, but if you'd like to have that consistency, feel free to open a new issue on it.

@isaacs
Copy link
Owner

isaacs commented Jan 25, 2023

eg:

$ nave use new-named-env bash -c 'echo nva=$NAVEVERSIONARG'
What version of node? 16
Creating new env named 'new-named-env' using node 16.19.0
nva=16.19.0   # <-- would expect "16" here, not "16.19.0"

@rulatir
Copy link
Contributor Author

rulatir commented Jan 25, 2023

In the case of nave use named-env without supplying a version, it is set to the resulting full version

If it is reliably set the original version argument given to nave use in every context in which the resolution is unambiguous, then that's fine. I can make sure that the resolution is unambiguous. Thanks!

@isaacs
Copy link
Owner

isaacs commented Jan 26, 2023

The issue is that the argument isn't stored anywhere after the first setup command. So all we know at the point of nave use named is whatever version it resolved to.

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