Skip to content

Commit

Permalink
cmd/input: added support for Description from cue doc string
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Alba <sam.alba@gmail.com>
  • Loading branch information
samalba committed May 26, 2021
1 parent 78fcb50 commit 16553b2
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions cmd/dagger/cmd/input/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"strings"
"text/tabwriter"

"go.dagger.io/dagger/client"
Expand Down Expand Up @@ -49,7 +50,7 @@ var listCmd = &cobra.Command{
inputs := env.ScanInputs(ctx)

w := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
fmt.Fprintln(w, "Input\tType\tValue\tSet by user")
fmt.Fprintln(w, "Input\tType\tValue\tSet by user\tDescription")

for _, inp := range inputs {
isConcrete := (inp.IsConcreteR() == nil)
Expand All @@ -69,11 +70,12 @@ var listCmd = &cobra.Command{
}
}

fmt.Fprintf(w, "%s\t%s\t%s\t%t\n",
fmt.Fprintf(w, "%s\t%s\t%s\t%t\t%s\n",
inp.Path(),
getType(inp),
valStr,
isUserSet(st, inp),
getDocString(inp),
)
}

Expand Down Expand Up @@ -108,6 +110,34 @@ func getType(val *compiler.Value) string {
return val.Cue().IncompleteKind().String()
}

func getDocString(val *compiler.Value) string {
docs := []string{}
for _, c := range val.Cue().Doc() {
docs = append(docs, strings.TrimSpace(c.Text()))
}
doc := strings.Join(docs, " ")

lines := strings.Split(doc, "\n")

// Strip out FIXME, TODO, and INTERNAL comments
docs = []string{}
for _, line := range lines {
if strings.HasPrefix(line, "FIXME: ") ||
strings.HasPrefix(line, "TODO: ") ||
strings.HasPrefix(line, "INTERNAL: ") {
continue
}
if len(line) == 0 {
continue
}
docs = append(docs, line)
}
if len(docs) == 0 {
return "-"
}
return strings.Join(docs, " ")
}

func init() {
listCmd.Flags().BoolP("all", "a", false, "List all inputs (include non-overridable)")

Expand Down

0 comments on commit 16553b2

Please sign in to comment.