cue icon indicating copy to clipboard operation
cue copied to clipboard

cue export doesn't work with named pipe

Open rogpeppe opened this issue 4 years ago • 1 comments

commit 9e7d4d63acf9cfcf7fdc33731dedfe420c0e2689

This command prints the empty object, where it should not:

% cue export cue: <(echo '{"x": 1'})
{}

This works OK if the input treated as JSON or YAML:

rogpeppe@snazzy2:~$ cue export json: <(echo '{"x": 1'})
{
    "x": 1
}
rogpeppe@snazzy2:~$ cue export yaml: <(echo '{"x": 1'})
{
    "x": 1
}

Something in the stack is probably reading the input twice without realising that reads can be destructive.

rogpeppe avatar Nov 29 '21 08:11 rogpeppe

It looks like this is probably because cuelang.org/go/cue/load.matchFile opens the file, reads its imports, then closes it again. It should probably do something different for non-regular files.

rogpeppe avatar Nov 30 '21 10:11 rogpeppe

This is fixed in master:

$ cue export cue: <(echo '{"x": 1'})
{
    "x": 1
}

https://review.gerrithub.io/c/cue-lang/cue/+/1194381 added a test case for it, see exec cue export cue: somefile. It's unclear exactly when it got fixed in the last 2.5 years, but that doesn't seem particularly important.

mvdan avatar May 21 '24 09:05 mvdan