-
Notifications
You must be signed in to change notification settings - Fork 171
Support type assertion #881
Comments
Have you explored Also, instead of this function, you could consider using |
it call
When unmarshal json raw to In toml, float and int should be strict, this function here to fix this. |
Validate takes Options, in which you can omit final |
@verdverm But i need it do validation for each eval. |
are you fetching mods during eval(s) and/or build(s)? regarding the original question, what would |
fetching mod only mod not exists in cache, but always checking during evals and builds.
no effects for output. It is a validation enhancement. When a value annotated for reference or incomplete value, should validate sub node first. However, i feel golang like let vv, isString = v.(string)
if isString {}
let vv, isInt = v.(int)
if isInt {} |
I'm slightly confused as to what is being discussed/requested here. It's already possible to check the type of a value:
(although I will note this is one of the many confusing overloads for Is there anything else required here?
@morlay we're definitely open to expanding builtins beyond what is currently provided. There is clearly a balance between the standard builtins becoming a kitchen sink of everything, and us fragmenting the language by supporting custom builtins. Please feel free to make suggestions for things you think should be added: it will help to shape the conversation if we have real examples. |
@myitcv Cool. I learned one new tip. #X: {
optional?: string
}
list: [...#X] & [
{optional: "xxx"},
{},
]
for i, x in list {
if ({optional: _} & x) != _|_ {
"\(i)": x.optional
}
}
a built-in function
I understand this, so I'm not requesting to add new built-in functions. After converting helm chart to cue codes, we could use helm chart like below: package localpathprovisioner
import (
"github.com/rancher/local-path-provisioner/deploy/chart"
)
"local-path-provisioner": {
@translate("helm")
chart
release: name: "local-path-provisioner"
release: namespace: "local-path-provisioner"
values: {}
} A realworld example: https://github.com/querycap/harbor/blob/master/components/harbor/app.cue I don't think this feature should be a cuelang builtin. Btw, cuelang is a hero. Back to this issue. I define a special attr if I mark like this
so I have to wrap
However, two disadvantages here:
Also, cuelang api may provide |
I'm still a bit unclear what the goal is here, but here are some other ideas: An upcoming CL (planned for
to inject a For example, in my client
resolves to
Maybe that is something that is helpful. |
Where did the "foo" come from in the resolved text? Should that have been a: 1 instead? |
This issue has been migrated to cue-lang/cue#881. For more details about CUE's migration to a new home, please see cue-lang/cue#1078. |
Is your feature request related to a problem? Please describe.
Based on cuelang, i wrote a small tool to manage k8s resources similar like helm.
Avoiding forking cuelang to add built-in functions, i use an attr
@translate("xxx")
to convert some cue value to special configuration format which cuelang not provided.https://github.com/octohelm/cuemod#post-processing-translatename
For example, a toml format:
Now I have to wrap with
json.Marshal
to make type constraints happy, then convert to toml from json raw codes.But if type assertion supported. we could avoid wrap the
json.Marshal
, and convert to toml from struct value directly.Describe the solution you'd like
may just a new built-in value attr
@as(type)
Describe alternatives you've considered
or golang like
.(type)
The text was updated successfully, but these errors were encountered: