diff --git a/cmd/dagger/cmd/output/list.go b/cmd/dagger/cmd/output/list.go index e835cf57..502d7b10 100644 --- a/cmd/dagger/cmd/output/list.go +++ b/cmd/dagger/cmd/output/list.go @@ -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) - } -} diff --git a/cmd/dagger/cmd/up.go b/cmd/dagger/cmd/up.go index cf9a8fb8..8916e515 100644 --- a/cmd/dagger/cmd/up.go +++ b/cmd/dagger/cmd/up.go @@ -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()))) }, }