-
Notifications
You must be signed in to change notification settings - Fork 469
Description
jsonnet --multi dir overwrites any files in dir which are produced by the Jsonnet script, and doesn't produce a warning when doing so.
While I recognize clobbering existing files is often useful (regenerate a set of files in a hermetic environment), there are also use cases that don't want to do so. In my case, I'm writing a Jsonnet program to generate an initial set of files, but I would like any further changes in those files to be preserved if the script is run a second time.
Since both approaches make sense, this behavior should probably be an additional flag (--noclobber or --dont-overwrite or something). Since both jsonnet and go-jsonnet currently overwrite, preserving that behavior as default probably makes sense. I'm not sure whether an automatic warning to stderr when it does overwrite is a good idea.
One reason to run the script a second time is if additional files have been added to the script, or you delete a file that got changed inappropriately and then regenerate it. In my particular case, I'm working with several programs that can build part of a skeletal directory; some files in that directory are shared and shouldn't be touched if a different program (or a human) created them, but any missing files should be created by my Jsonnet program.
AFAIK, the only way inside the language to tell if a file exists is to attempt to import it, e.g. local exists = importstr "/tmp/test/file1" but (a) the program doesn't know the path given to --multi, so it can't form the full path and (b) if the file doesn't exist the import will raise an error, and Jsonnet doesn't yet have an error recovery feature (try/catch or similar). So the only workaround I can think of is inspecting file existence in the shell and passing that as a top level argument, then omitting the extant files from the object returned by the script, which feels awkward at best.