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

Create output directories if they do not exist #195

Open
brbbs opened this issue May 25, 2016 · 5 comments
Open

Create output directories if they do not exist #195

brbbs opened this issue May 25, 2016 · 5 comments

Comments

@brbbs
Copy link
Contributor

brbbs commented May 25, 2016

I'd like to be able to invoke jsonnet like: jsonnet -o foo/bar.json -e "{ foo: 'bar' }" and have it create the foo/ directory if it does not already exist. I'd like this to apply to multi-file output invocations as well. My use case is to have a file of the form:

{
  'a.json': { /* snip */ },
  'subdir/b.json': /* ... */,
  'subdir/c.json': /* ... */,
}

but I'd like to be able to invoke jsonnet -m without having to know which subdirectories to create beforehand.

Currently, both invocations fail with the error:

$ jsonnet -o foo/bar.json -e "{ foo: 'bar' }"
Writing to output file: foo/bar.json: No such file or directory
$ jsonnet -m . foo.jsonnet
./a.json
./subdir/b.json
Opening output file: ./subdir/b.json: No such file or directory
@sparkprime
Copy link
Member

The big challenge here is that Jsonnet is currently pure C++ but the ability to create a dir requires posix / win32 / etc.

@brbbs
Copy link
Contributor Author

brbbs commented May 25, 2016

Ah, that is a problem.

I suppose as a workaround I can do something like:

jsonnet foo.jsonnet -o out.json
for p in $(jq -r keys[] < out.json); do mkdir -p $(dirname "$p"); done
jsonnet -m . out.json # or something equivalent with jq

Feel free to close this as will not fix if you don't think you'll end up implementing it.

@sparkprime
Copy link
Member

I am sort of thinking that it is really the commandline executable that would need this ability, and having that require posix (or having a chunk of functionality disabled if posix is not detected) is a lot less worse than having the libjsonnet lib (i.e. the core VM) need it. So it may not be too bad.

@Duologic
Copy link
Contributor

Duologic commented Jun 1, 2021

ref for search to pick up on this issue: The Go jsonnet version has the flag -c or --create-output-dirs to accomplish this.

@sbarzowski
Copy link
Collaborator

If someone wants to pick this up here, feel free to open the PR. Ideally the interface would be compatible with the one in go-jsonnet. (However, if you're using Jsonnet as a command, you probably want to use go-jsonnet implementation anyway).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants