diff --git a/cmd/dagger/cmd/common/common.go b/cmd/dagger/cmd/common/common.go index cac81e68..d2c041fb 100644 --- a/cmd/dagger/cmd/common/common.go +++ b/cmd/dagger/cmd/common/common.go @@ -2,10 +2,12 @@ package common import ( "context" + "strings" "github.com/rs/zerolog/log" "github.com/spf13/viper" "go.dagger.io/dagger/client" + "go.dagger.io/dagger/compiler" "go.dagger.io/dagger/environment" "go.dagger.io/dagger/solver" "go.dagger.io/dagger/state" @@ -97,3 +99,43 @@ func EnvironmentUp(ctx context.Context, state *state.State, noCache bool) *envir } return result } + +// ValueType returns the String representation of the cue value +func ValueType(val *compiler.Value) string { + if val.HasAttr("artifact") { + return "dagger.#Artifact" + } + if val.HasAttr("secret") { + return "dagger.#Secret" + } + return val.Cue().IncompleteKind().String() +} + +// ValueDocString returns the value doc from the comment lines +func ValueDocString(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, " ") +} diff --git a/cmd/dagger/cmd/input/list.go b/cmd/dagger/cmd/input/list.go index aae85878..7f23e167 100644 --- a/cmd/dagger/cmd/input/list.go +++ b/cmd/dagger/cmd/input/list.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "os" - "strings" "text/tabwriter" "go.dagger.io/dagger/client" @@ -75,10 +74,10 @@ var listCmd = &cobra.Command{ fmt.Fprintf(w, "%s\t%s\t%s\t%t\t%s\n", inp.Path(), - getType(inp), + common.ValueType(inp), valStr, isUserSet(st, inp), - getDocString(inp), + common.ValueDocString(inp), ) } @@ -103,44 +102,6 @@ func isUserSet(env *state.State, val *compiler.Value) bool { return false } -func getType(val *compiler.Value) string { - if val.HasAttr("artifact") { - return "dagger.#Artifact" - } - if val.HasAttr("secret") { - return "dagger.#Secret" - } - 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)")