diff --git a/cmd/dagger/cmd/output/list.go b/cmd/dagger/cmd/output/list.go index 58512875..e835cf57 100644 --- a/cmd/dagger/cmd/output/list.go +++ b/cmd/dagger/cmd/output/list.go @@ -46,6 +46,10 @@ func ListOutputs(ctx context.Context, st *state.State, all bool) { 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") @@ -87,7 +91,7 @@ func ListOutputs(ctx context.Context, st *state.State, all bool) { }) if err != nil { - lg.Warn().Err(err).Msg("failed to query environment") + lg.Fatal().Err(err).Msg("failed to query environment") } } diff --git a/cmd/dagger/cmd/up.go b/cmd/dagger/cmd/up.go index 8376da13..cf9a8fb8 100644 --- a/cmd/dagger/cmd/up.go +++ b/cmd/dagger/cmd/up.go @@ -48,6 +48,11 @@ 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) }, } diff --git a/environment/environment.go b/environment/environment.go index a80300c2..72a7f2e5 100644 --- a/environment/environment.go +++ b/environment/environment.go @@ -326,7 +326,7 @@ func (e *Environment) ScanInputs(ctx context.Context, mergeUserInputs bool) ([]* func (e *Environment) ScanOutputs(ctx context.Context) ([]*compiler.Value, error) { if e.state.Computed == "" { - return nil, errors.New("cannot query environment outputs: please run `dagger up` first") + return nil, errors.New("environment has been computed yet") } src, err := e.prepare(ctx)