From 66929f8a63a00fe0ec0d582823afb872c6a5864a Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Wed, 2 Jun 2021 11:42:59 +0200 Subject: [PATCH] compiler.Value abstraction for docstring and incompletekind Signed-off-by: Sam Alba --- cmd/dagger/cmd/common/common.go | 4 ++-- cmd/dagger/cmd/input/list.go | 9 --------- compiler/value.go | 9 +++++++++ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cmd/dagger/cmd/common/common.go b/cmd/dagger/cmd/common/common.go index a83560e8..712757f2 100644 --- a/cmd/dagger/cmd/common/common.go +++ b/cmd/dagger/cmd/common/common.go @@ -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, " ") diff --git a/cmd/dagger/cmd/input/list.go b/cmd/dagger/cmd/input/list.go index a4c8130d..0d97d0f4 100644 --- a/cmd/dagger/cmd/input/list.go +++ b/cmd/dagger/cmd/input/list.go @@ -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 diff --git a/compiler/value.go b/compiler/value.go index ded6e810..fb772b5f 100644 --- a/compiler/value.go +++ b/compiler/value.go @@ -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() +}