-
Notifications
You must be signed in to change notification settings - Fork 170
Root keys with dashes in their name cannot be extracted with cue eval -e #358
Comments
This is some tracing I have done to follow the code path:
This is where we go to the parser with the flag, and likely return the wrong kind of expression. This is where to put a break point and check input/output with Delve. The following may be related:
These may be a bit out of order, but the main points are there. My best guess is that something in parsing the expressions is broken down this path. I have also tried the input Really need to get into Delve more by default... |
TL;DR At https://github.com/cuelang/cue/blob/master/cmd/cue/cmd/common.go#L472
while
and
|
Here might be the "root" question... "How does one access top-level keys which require indexing due to the format of the identifier?" https://cuelang.org/docs/tutorials/tour/references/selectors/ In this link, the indexing happens on a struct field. Is there a notation to specify the root / file level equivalent to a in this example? |
This is not a bug: the dashed key is not a valid identifier, and the Within CUE, the workaround is to use a field alias
As aliases are not visible outside the scope in which they are defined, this is not a solution for There are two possible solutions:
The latter was actually supported at some point, but it seems to be too confusing. It may be a possibility, though. Option 1. has deliberately not been supported, as it is too easy to misuse this feature: it's use will almost always be wrong and it is hardly ever necessary. That said, we could consider supporting a symbol for root that is only available from the command line, such as The use of |
@mpvl From my end-user perspective, the dashed cue is "valid" in so much as we can import the cue file and get to the underlying values with paths like |
This issue has been migrated to cue-lang/cue#358. For more details about CUE's migration to a new home, please see cue-lang/cue#1078. |
What version of CUE are you using (
cue version
)?I performed a fresh
go get -u cuelang.org/go/cmd/cue
as of the time and date this issue was opened.Does this issue reproduce with the latest release?
I tested with the latest
devel
code as of the date and time this issue was created. I have not tested with any prior official releases.What did you do?
I attempted to extract a root key from a CUE file using
cue eval -e
. The root key has a dash in its name, which appears to be causing problems. Here is the repo case:Create a new
data.cue
file with the following contents:Run
cue eval data.cue -e foo
, which returnsone: 1
as expected.However, the following attempts to get the
foo-bar
key fail.What did you expect to see?
I expected to see
two: 2
returned.What did you see instead?
See above errors.
The text was updated successfully, but these errors were encountered: