cmd/output: list now lists all outputs everytime, even if not concrete - also allows to show outputs even if the env was never computes (based on UX feedback)

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

View File

@ -4,7 +4,6 @@ import (
"context"
"fmt"
"os"
"strings"
"text/tabwriter"
"go.dagger.io/dagger/client"
@ -37,19 +36,15 @@ var listCmd = &cobra.Command{
workspace := common.CurrentWorkspace(ctx)
st := common.CurrentEnvironmentState(ctx, workspace)
ListOutputs(ctx, st, viper.GetBool("all"))
ListOutputs(ctx, st, true)
},
}
func ListOutputs(ctx context.Context, st *state.State, all bool) {
func ListOutputs(ctx context.Context, st *state.State, isTTY bool) {
lg := log.Ctx(ctx).With().
Str("environment", st.Name).
Logger()
if st.Computed == "" {
lg.Fatal().Msg("cannot list environment outputs: please run `dagger up` first")
}
c, err := client.New(ctx, "", false)
if err != nil {
lg.Fatal().Err(err).Msg("unable to create client")
@ -61,27 +56,22 @@ func ListOutputs(ctx context.Context, st *state.State, all bool) {
return err
}
if !isTTY {
for _, out := range outputs {
lg.Info().Str("name", out.Path().String()).
Str("value", fmt.Sprintf("%v", out.Cue())).
Msg("output")
}
return nil
}
w := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
fmt.Fprintln(w, "Output\tType\tValue\tDescription")
fmt.Fprintln(w, "Output\tValue\tDescription")
for _, out := range outputs {
valStr := "-"
if out.IsConcreteR() == nil {
valStr, err = out.Cue().String()
if err != nil {
return err
}
} else if !all {
continue
}
valStr = strings.ReplaceAll(valStr, "\n", "\\n")
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n",
fmt.Fprintf(w, "%s\t%s\t%s\n",
out.Path(),
common.ValueType(out),
valStr,
common.FormatValue(out),
common.ValueDocString(out),
)
}
@ -94,11 +84,3 @@ func ListOutputs(ctx context.Context, st *state.State, all bool) {
lg.Fatal().Err(err).Msg("failed to query environment")
}
}
func init() {
listCmd.Flags().BoolP("all", "a", false, "List all outputs (include non-concrete)")
if err := viper.BindPFlags(listCmd.Flags()); err != nil {
panic(err)
}
}

View File

@ -48,12 +48,7 @@ var upCmd = &cobra.Command{
lg.Fatal().Err(err).Msg("failed to update environment")
}
if !term.IsTerminal(int(os.Stdout.Fd())) {
lg.Debug().Msg("not a tty, output list disabled")
return
}
output.ListOutputs(ctx, st, false)
output.ListOutputs(ctx, st, term.IsTerminal(int(os.Stdout.Fd())))
},
}