hof icon indicating copy to clipboard operation
hof copied to clipboard

hof generate doesn't work if cue file is not present in same directory

Open newbeelearn opened this issue 3 years ago • 2 comments

i am using hof in a script like this hof gen $SRCD/chartapijson.cue -T $SRCT/chartgen.go -O $TRGT where SRCD is the directory for cue files, SRCT is directory for template files and TRGT is directory for output files.

This does not work if the cue file is not present in the directory from where the script is called. It gives "file does not exist" error however if i place a dummy cue file than it works fine. It takes the config data from the cue file in SRCD directory and generates output correctly.

It would be great if this restriction can be removed.

newbeelearn avatar Sep 22 '22 16:09 newbeelearn

@newbeelearn are you using absolute or relative paths in those vars? Does it look like one of these issues?

  • https://github.com/cue-lang/cue/issues/1908
  • https://github.com/cue-lang/cue/issues/1899

If you could make a complete reproducer like (https://github.com/cue-lang/cue/wiki/Creating-test-or-performance-reproducers), that would be helpful.

Which version of hof are you using? (hof version) If using v0.6.6, can you also try v0.6.7-rc.2

Generally speaking, the CUE entrypoints (files &| dirs) are passed directly to the CUE loader, so I suspect the issue is upstream.

verdverm avatar Sep 22 '22 17:09 verdverm

are you using absolute or relative paths in those vars? Does it look like one of these issues?

I am using absolute paths

Which version of hof are you using?

Version: v0.6.7-rc.2

If you could make a complete reproducer

sure, i will create a test script so that it can be reproduced locally

so I suspect the issue is upstream

Ok, i am not familiar with cue tooling. My introduction to cue is through hof :-) .

newbeelearn avatar Sep 23 '22 10:09 newbeelearn

This seems to be a restriction from CUE and not something they are likely to permit. I'm not sure I can fix this for inputs, as they are passed directly to CUE, but could fix absolute output paths if they are not working already.

verdverm avatar Nov 22 '22 01:11 verdverm

We could probably detect absolute paths, load them into the overlay, and adjust the entrypoint(s) as needed. Will have to think about how paths work in this case (errors, working dir), or maybe it will work with absolute path entrypoints if they are in the overlay? (test needed)

verdverm avatar Jan 22 '23 04:01 verdverm

I'm not sure if this is related, but I'm getting the same error even when using relative paths. I am also getting the error with absolute paths.

 hof gen ../data/common/json/base/full/AmountType.json.cue -T ../generators/enrich2.cue
file does not exist

cat ../generators/enrich2.cue works.

I also tried piping:

cat ../data/common/json/base/full/AmountType.json.cue | hof gen -T ../generators/enrich2.cue
Errors while loading Cue entrypoints:  []
no CUE files in .

cat ../data/common/json/base/full/AmountType.json-full.json | hof gen -T ../generators/enrich2.cue
Errors while loading Cue entrypoints:  []
no CUE files in .

magick93 avatar Mar 11 '23 02:03 magick93

When you cat <file> | hof gen - ..., you need a hyphen to specify an entrypoint from stdin. You can mix this with regular files too.

I will look into the relative path support as a regular entrypoint, I am able to reproduce it locally.

verdverm avatar Mar 11 '23 20:03 verdverm

The relative paths should now be fixed in _dev by #156

I don't see supporting absolute paths in the same way unless CUE does, so closing for now.

If the rel fix does not work as expected, please open a new issue

verdverm avatar Mar 11 '23 22:03 verdverm