Skip to content
This repository has been archived by the owner on Oct 22, 2023. It is now read-only.

Allow the default value of expression to refer to environment variables #1019

Closed
sschuberth opened this issue Sep 12, 2021 · 9 comments
Closed

Comments

@sschuberth
Copy link
Contributor

Describe the problem you'd like to solve

I'd like to specify a sub-directory of the host user's home directory as the local source directory for a volume. As a ~ prefix did not seem to work, I was trying to use an expression like local: ${HOME:-$USERPROFILE}/.gradle (so $HOME is tried first, assuming the host is a Linux system; otherwise assume the host is Windows, and use $USERPROFILE). But that does not seem to work either, the "nested" $USERPROFILE environment variable does not seem to get resolved.

Describe the solution you'd like

Environment variables that are part of the default value of an expression should be resolved.

Describe alternatives you've considered

Alternatively / additionally, a dedicated syntax to refer to the current user's home on the host system in a platform-agnostic way, like using ~, would be nice.

Additional context

Note that in Bash, echo ${HOME:-$USERPROFILE} actually works, so I was assuming it to work with Batect, too.

@sschuberth
Copy link
Contributor Author

Environment variables that are part of the default value of an expression should be resolved.

This seems to be the code that would need to get touched for this:

default != null -> default

@charleskorn
Copy link
Collaborator

Thanks for the suggestion @sschuberth. Have you seen #990? I'm planning on replacing the current expression syntax with something that would support this far more naturally.

@charleskorn
Copy link
Collaborator

a dedicated syntax to refer to the current user's home on the host system in a platform-agnostic way, like using ~, would be nice

This is supported in places that accept local file paths (eg. the local side of a volume mount). Are there other places that you'd like to use it?

@sschuberth
Copy link
Contributor Author

Have you seen #990?

Ah, no, I didn't connect "expression" with "environment variable" in that context. Thanks for pointing this out to me.

This is supported in places that accept local file paths (eg. the local side of a volume mount).

Hmm, when I tried it did not seem to work for me on Windows. Is ~-resolution maybe implemented only on platforms where the shell usually supports it (i.e. on non-Windows)?

Are there other places that you'd like to use it?

Nope, not yet 😉

@charleskorn
Copy link
Collaborator

Is ~-resolution maybe implemented only on platforms where the shell usually supports it (i.e. on non-Windows)?

It should be happening on all platforms - and if it's not, that's a bug :)

@sschuberth
Copy link
Contributor Author

Is there a way to see in the log what local paths Batect resolves to?

@charleskorn
Copy link
Collaborator

You should be able to see the resolved paths for volume mounts in the creation request sent to the Docker daemon, which is logged here.

@sschuberth
Copy link
Contributor Author

Ok, I'm getting

{"type":"batect.docker.DockerVolumeMountSource.LocalPath","formatted":"C:\\Users\\sebastian\\.gradle","path":"C:\\Users\\sebastian\\.gradle"}

which actually looks good, and using ~ in front of a local path on Windows seems to resolve to the user home correctly.

@sschuberth
Copy link
Contributor Author

Have you seen #990?

Ah, no, I didn't connect "expression" with "environment variable" in that context. Thanks for pointing this out to me.

So, since the table in the RFC has an entry for "Reference to environment variable with default from other environment variable" (and my immediate use-case would be solved with ~) I'm closing this in favor of waiting for the new expression syntax.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants