Remove cmd output
Signed-off-by: Joel Longtine <joel@dagger.io>
This commit is contained in:
parent
16733fa9eb
commit
817a73b7e0
@ -1,33 +0,0 @@
|
||||
package output
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var dirCmd = &cobra.Command{
|
||||
Use: "dir PATH",
|
||||
Short: "Add a local directory as output artifact",
|
||||
Args: cobra.ExactArgs(1),
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
// Fix Viper bug for duplicate flags:
|
||||
// https://github.com/spf13/viper/issues/233
|
||||
if err := viper.BindPFlags(cmd.Flags()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// lg := logger.New()
|
||||
// ctx := lg.WithContext(cmd.Context())
|
||||
|
||||
panic("not implemented")
|
||||
},
|
||||
// Remove hidden flag once command has been implemented
|
||||
Hidden: true,
|
||||
}
|
||||
|
||||
func init() {
|
||||
if err := viper.BindPFlags(dirCmd.Flags()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
@ -1,94 +0,0 @@
|
||||
package output
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
|
||||
"go.dagger.io/dagger/cmd/dagger/cmd/common"
|
||||
"go.dagger.io/dagger/cmd/dagger/logger"
|
||||
"go.dagger.io/dagger/environment"
|
||||
"go.dagger.io/dagger/solver"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var listCmd = &cobra.Command{
|
||||
Use: "list [TARGET] [flags]",
|
||||
Short: "List the outputs of an environment",
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
// Fix Viper bug for duplicate flags:
|
||||
// https://github.com/spf13/viper/issues/233
|
||||
if err := viper.BindPFlags(cmd.Flags()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
lg := logger.New()
|
||||
ctx := lg.WithContext(cmd.Context())
|
||||
|
||||
project := common.CurrentProject(ctx)
|
||||
st := common.CurrentEnvironmentState(ctx, project)
|
||||
|
||||
lg = lg.With().
|
||||
Str("environment", st.Name).
|
||||
Logger()
|
||||
|
||||
doneCh := common.TrackProjectCommand(ctx, cmd, project, st)
|
||||
|
||||
env, err := environment.New(st)
|
||||
if err != nil {
|
||||
lg.Fatal().Err(err).Msg("unable to create environment")
|
||||
}
|
||||
|
||||
cl := common.NewClient(ctx)
|
||||
err = cl.Do(ctx, env.Context(), func(ctx context.Context, s solver.Solver) error {
|
||||
return ListOutputs(ctx, env, true)
|
||||
})
|
||||
|
||||
<-doneCh
|
||||
|
||||
if err != nil {
|
||||
lg.Fatal().Err(err).Msg("failed to scan outputs")
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func ListOutputs(ctx context.Context, env *environment.Environment, isTTY bool) error {
|
||||
lg := log.Ctx(ctx).With().
|
||||
Str("environment", env.Name()).
|
||||
Logger()
|
||||
|
||||
outputs, err := env.ScanOutputs(ctx)
|
||||
if err != nil {
|
||||
lg.Error().Err(err).Msg("failed to scan outputs")
|
||||
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\tValue\tDescription")
|
||||
|
||||
for _, out := range outputs {
|
||||
fmt.Fprintf(w, "%s\t%s\t%s\n",
|
||||
out.Path(),
|
||||
common.FormatValue(out),
|
||||
common.ValueDocOneLine(out),
|
||||
)
|
||||
}
|
||||
|
||||
w.Flush()
|
||||
return nil
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package output
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
// Cmd exposes the top-level command
|
||||
var Cmd = &cobra.Command{
|
||||
Use: "output",
|
||||
Short: "Manage an environment's outputs",
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Cmd.AddCommand(dirCmd)
|
||||
Cmd.AddCommand(listCmd)
|
||||
}
|
@ -8,7 +8,6 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"go.dagger.io/dagger/cmd/dagger/cmd/mod"
|
||||
"go.dagger.io/dagger/cmd/dagger/cmd/output"
|
||||
"go.dagger.io/dagger/cmd/dagger/logger"
|
||||
"go.dagger.io/dagger/keychain"
|
||||
|
||||
@ -63,7 +62,6 @@ func init() {
|
||||
historyCmd,
|
||||
loginCmd,
|
||||
logoutCmd,
|
||||
output.Cmd,
|
||||
versionCmd,
|
||||
docCmd,
|
||||
mod.Cmd,
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
"cuelang.org/go/cue"
|
||||
"go.dagger.io/dagger/client"
|
||||
"go.dagger.io/dagger/cmd/dagger/cmd/common"
|
||||
"go.dagger.io/dagger/cmd/dagger/cmd/output"
|
||||
"go.dagger.io/dagger/cmd/dagger/logger"
|
||||
"go.dagger.io/dagger/compiler"
|
||||
"go.dagger.io/dagger/environment"
|
||||
@ -108,7 +107,7 @@ var upCmd = &cobra.Command{
|
||||
if tty != nil {
|
||||
tty.Stop()
|
||||
}
|
||||
return output.ListOutputs(ctx, env, term.IsTerminal(int(os.Stdout.Fd())))
|
||||
return nil
|
||||
})
|
||||
|
||||
<-doneCh
|
||||
|
Reference in New Issue
Block a user