cmd/input: changed list output based on feedback
Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
parent
efb4ee209e
commit
03d58e074f
@ -2,6 +2,7 @@ package common
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
@ -100,15 +101,21 @@ func EnvironmentUp(ctx context.Context, state *state.State, noCache bool) *envir
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValueType returns the String representation of the cue value
|
// FormatValue returns the String representation of the cue value
|
||||||
func ValueType(val *compiler.Value) string {
|
func FormatValue(val *compiler.Value) string {
|
||||||
if val.HasAttr("artifact") {
|
if val.HasAttr("artifact") {
|
||||||
return "dagger.#Artifact"
|
return "dagger.#Artifact"
|
||||||
}
|
}
|
||||||
if val.HasAttr("secret") {
|
if val.HasAttr("secret") {
|
||||||
return "dagger.#Secret"
|
return "dagger.#Secret"
|
||||||
}
|
}
|
||||||
|
if val.IsConcreteR() != nil {
|
||||||
return val.Cue().IncompleteKind().String()
|
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
|
// ValueDocString returns the value doc from the comment lines
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
"go.dagger.io/dagger/client"
|
"go.dagger.io/dagger/client"
|
||||||
@ -53,20 +52,20 @@ var listCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
w := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
|
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 {
|
for _, inp := range inputs {
|
||||||
isConcrete := (inp.IsConcreteR() == nil)
|
isConcrete := (inp.IsConcreteR() == nil)
|
||||||
_, hasDefault := inp.Default()
|
_, hasDefault := inp.Default()
|
||||||
valStr := "-"
|
// valStr := "-"
|
||||||
if isConcrete {
|
// if isConcrete {
|
||||||
valStr, _ = inp.Cue().String()
|
// valStr, _ = inp.Cue().String()
|
||||||
}
|
// }
|
||||||
if hasDefault {
|
// if hasDefault {
|
||||||
valStr = fmt.Sprintf("%s (default)", valStr)
|
// valStr = fmt.Sprintf("%s (default)", valStr)
|
||||||
}
|
// }
|
||||||
|
|
||||||
valStr = strings.ReplaceAll(valStr, "\n", "\\n")
|
// valStr = strings.ReplaceAll(valStr, "\n", "\\n")
|
||||||
|
|
||||||
if !viper.GetBool("all") {
|
if !viper.GetBool("all") {
|
||||||
// skip input that is not overridable
|
// 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(),
|
inp.Path(),
|
||||||
common.ValueType(inp),
|
common.FormatValue(inp),
|
||||||
valStr,
|
|
||||||
isUserSet(st, inp),
|
isUserSet(st, inp),
|
||||||
common.ValueDocString(inp),
|
common.ValueDocString(inp),
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user