Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

FieldByName Can't Get Hidden Field #880

Closed
rawkode opened this issue Apr 5, 2021 · 3 comments
Closed

FieldByName Can't Get Hidden Field #880

rawkode opened this issue Apr 5, 2021 · 3 comments
Labels
wontfix This will not be worked on

Comments

@rawkode
Copy link

rawkode commented Apr 5, 2021

What version of CUE are you using (cue version)?

0.3.0

Does this issue reproduce with the latest release?

FieldByName has a second parameter, a bool; which according to the comments should allow us to get a hidden field or definition.

package main

import (
	"fmt"

	"cuelang.org/go/cue"
)

func main() {
	var cueRuntime cue.Runtime

	testCue := `{
	_schema: {
		version: "v1"
	}
}`

	cueInstance, err := cueRuntime.Compile("", testCue)
	cueValue := cueInstance.Value()

	hiddenField, err := cueValue.FieldByName("_schema", true)
	if err != nil {
		fmt.Println("Error", err)
	}
	fmt.Println(hiddenField.Name)

	fields, _ := cueValue.Fields(cue.All())
	for fields.Next() {
		if fields.Label() == "_schema" {
			fmt.Println("Found _schema", fields.Value())
		}
	}
}
@mpvl
Copy link
Contributor

mpvl commented Apr 8, 2021

We have just officially deprecated FieldByName. Hidden fields are tricky, as they are scoped by package, pretty much like Go's non-exported names. So FieldByName was broken for that purpose.

Really the only thing you'll need for looking up fields is LookupPath.

E.g. v.LookupPath(cue.MakePath(cue.Hid("_schema", "_"))).

This API will allow looking up hidden fields related to any of the packages.

@mpvl mpvl added wontfix This will not be worked on and removed NeedsInvestigation labels Apr 8, 2021
@mpvl
Copy link
Contributor

mpvl commented Apr 8, 2021

Note that the Iterator interface is broken too in that regard. We should implement Selector, instead of Label, to be accurate.

The API is currently being reworked to use the Path/Selector approach, which is nice, much more powerful, and prepares for the CUE query extension (#165 ).

@cueckoo
Copy link

cueckoo commented Jul 3, 2021

This issue has been migrated to cue-lang/cue#880.

For more details about CUE's migration to a new home, please see cue-lang/cue#1078.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants