compiler.Value abstraction for docstring and incompletekind

Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
Sam Alba 2021-06-02 11:42:59 +02:00
parent fd31afeda0
commit 66929f8a63
3 changed files with 11 additions and 11 deletions

View File

@ -110,7 +110,7 @@ func FormatValue(val *compiler.Value) string {
return "dagger.#Secret"
}
if val.IsConcreteR() != nil {
return val.Cue().IncompleteKind().String()
return val.IncompleteKindString()
}
// value representation in Cue
valStr := fmt.Sprintf("%v", val.Cue())
@ -121,7 +121,7 @@ func FormatValue(val *compiler.Value) string {
// ValueDocString returns the value doc from the comment lines
func ValueDocString(val *compiler.Value) string {
docs := []string{}
for _, c := range val.Cue().Doc() {
for _, c := range val.Doc() {
docs = append(docs, strings.TrimSpace(c.Text()))
}
doc := strings.Join(docs, " ")

View File

@ -57,15 +57,6 @@ var listCmd = &cobra.Command{
for _, inp := range inputs {
isConcrete := (inp.IsConcreteR() == nil)
_, hasDefault := inp.Default()
// valStr := "-"
// if isConcrete {
// valStr, _ = inp.Cue().String()
// }
// if hasDefault {
// valStr = fmt.Sprintf("%s (default)", valStr)
// }
// valStr = strings.ReplaceAll(valStr, "\n", "\\n")
if !viper.GetBool("all") {
// skip input that is not overridable

View File

@ -5,6 +5,7 @@ import (
"strconv"
"cuelang.org/go/cue"
"cuelang.org/go/cue/ast"
cueformat "cuelang.org/go/cue/format"
)
@ -270,3 +271,11 @@ func (v *Value) Default() (*Value, bool) {
val, hasDef := v.val.Default()
return v.cc.Wrap(val), hasDef
}
func (v *Value) Doc() []*ast.CommentGroup {
return v.Cue().Doc()
}
func (v *Value) IncompleteKindString() string {
return v.Cue().IncompleteKind().String()
}