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

--jpath does not support multiple search paths #744

Open
skuzzle opened this issue Feb 21, 2024 · 3 comments
Open

--jpath does not support multiple search paths #744

skuzzle opened this issue Feb 21, 2024 · 3 comments

Comments

@skuzzle
Copy link

skuzzle commented Feb 21, 2024

Hi,

I was surprised by this behavior, also the console help text is not very precise regarding whether multiple search paths are even allowed or not.

Given the following directory structure:

project/
├─ vendor1/
│  ├─ lib1/
│  │  ├─ shared1.txt    // content: "shared1"
├─ vendor2/
│  ├─ lib2/
│  │  ├─ shared2.txt    // content: "shared2"

Passing multiple library directories via JSONNET_PATH seems to work as expected, properly resolving files from both library locations:

JSONNET_PATH=$(pwd)/vendor1:$(pwd)/vendor2 jsonnet -e "(importstr 'lib1/shared1.txt')+(importstr 'lib2/shared2.txt')"

> "shared1shared2"

However, the same with the -J or --jpath argument does not work:

jsonnet --jpath $(pwd)/vendor1:$(pwd)/vendor2 -e "(importstr 'lib1/shared1.txt')+(importstr 'lib2/shared2.txt')" 

RUNTIME ERROR: couldn't open import "lib1/shared1.txt": no match locally or in the Jsonnet library paths
	<cmdline>:1:2-30	$
	During evaluation	

Tested with

jsonnet -version

> Jsonnet commandline interpreter (Go implementation) v0.20.0

Quick reproducer project with the example from above can be found here: https://github.com/skuzzle/jpath-issue-reproducer

@skuzzle skuzzle changed the title --jpathdoes not support multiple search paths --jpath does not support multiple search paths Feb 21, 2024
@zarelit
Copy link

zarelit commented Apr 19, 2024

@skuzzle you can specify the option multiple times like jsonnet -J $(pwd)/vendor1 -J $(pwd)/vendor2, in case the file is present in multiple directories the last one wins.

Issuing jsonnet --help prints an example of how JSONNET_PATH env variable and -J options interact together

Environment variables:
JSONNET_PATH is a colon (semicolon on Windows) separated list of directories
added in reverse order before the paths specified by --jpath (i.e. left-most
wins). E.g. these are equivalent:
JSONNET_PATH=a:b jsonnet -J c -J d
JSONNET_PATH=d:c:a:b jsonnet
jsonnet -J b -J a -J c -J d

@skuzzle
Copy link
Author

skuzzle commented Apr 22, 2024

Oh, not sure how I could miss that. Thanks for pointing this out. Anyway, I wonder whether there'd be some value in -J accepting multiples paths in a single parameter? To me this would at least feel a bit more consistent if -J and JSONNET_PATH accepted the same values

@zarelit
Copy link

zarelit commented Apr 23, 2024

AFAICT from the code it doesn't look like it, but I'll leave the actual answer to the devs

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