cmd/input: changed list output based on feedback

Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
Sam Alba 2021-06-01 14:12:37 +02:00
parent efb4ee209e
commit 03d58e074f
2 changed files with 21 additions and 16 deletions

View File

@ -2,6 +2,7 @@ package common
import (
"context"
"fmt"
"strings"
"github.com/rs/zerolog/log"
@ -100,15 +101,21 @@ 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 {
// FormatValue returns the String representation of the cue value
func FormatValue(val *compiler.Value) string {
if val.HasAttr("artifact") {
return "dagger.#Artifact"
}
if val.HasAttr("secret") {
return "dagger.#Secret"
}
if val.IsConcreteR() != nil {
return val.Cue().IncompleteKind().String()
}
// value representation in Cue
valStr := fmt.Sprintf("%v", val.Cue())
// escape \n
return strings.ReplaceAll(valStr, "\n", "\\n")
}
// ValueDocString returns the value doc from the comment lines

View File

@ -4,7 +4,6 @@ import (
"context"
"fmt"
"os"
"strings"
"text/tabwriter"
"go.dagger.io/dagger/client"
@ -53,20 +52,20 @@ var listCmd = &cobra.Command{
}
w := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
fmt.Fprintln(w, "Input\tType\tValue\tSet by user\tDescription")
fmt.Fprintln(w, "Input\tValue\tSet by user\tDescription")
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 := "-"
// if isConcrete {
// valStr, _ = inp.Cue().String()
// }
// if hasDefault {
// valStr = fmt.Sprintf("%s (default)", valStr)
// }
valStr = strings.ReplaceAll(valStr, "\n", "\\n")
// valStr = strings.ReplaceAll(valStr, "\n", "\\n")
if !viper.GetBool("all") {
// skip input that is not overridable
@ -75,10 +74,9 @@ var listCmd = &cobra.Command{
}
}
fmt.Fprintf(w, "%s\t%s\t%s\t%t\t%s\n",
fmt.Fprintf(w, "%s\t%s\t%t\t%s\n",
inp.Path(),
common.ValueType(inp),
valStr,
common.FormatValue(inp),
isUserSet(st, inp),
common.ValueDocString(inp),
)