Skip to content

Commit

Permalink
Add output flag to destroy and preview commands
Browse files Browse the repository at this point in the history
This mimics the setup for apply; adding an option for providing the
output format of the destroy and preview commands.
  • Loading branch information
fsommar committed Oct 29, 2020
1 parent 5e68050 commit 7a1f6af
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 9 additions & 1 deletion cmd/destroy/cmddestroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
package destroy

import (
"fmt"
"strings"

"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
Expand All @@ -28,6 +31,9 @@ func GetDestroyRunner(provider provider.Provider, ioStreams genericclioptions.IO
RunE: r.RunE,
}

cmd.Flags().StringVar(&r.output, "output", printers.DefaultPrinter(),
fmt.Sprintf("Output format, must be one of %s", strings.Join(printers.SupportedPrinters(), ",")))

r.Command = cmd
return r
}
Expand All @@ -44,6 +50,8 @@ type DestroyRunner struct {
ioStreams genericclioptions.IOStreams
Destroyer *apply.Destroyer
provider provider.Provider

output string
}

func (r *DestroyRunner) RunE(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -72,6 +80,6 @@ func (r *DestroyRunner) RunE(cmd *cobra.Command, args []string) error {

// The printer will print updates from the channel. It will block
// until the channel is closed.
printer := printers.GetPrinter(printers.EventsPrinter, r.ioStreams)
printer := printers.GetPrinter(r.output, r.ioStreams)
return printer.Print(ch, r.Destroyer.DryRunStrategy)
}
8 changes: 7 additions & 1 deletion cmd/preview/cmdpreview.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package preview

import (
"context"
"fmt"
"strings"

"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
Expand Down Expand Up @@ -44,6 +46,8 @@ func GetPreviewRunner(provider provider.Provider, ioStreams genericclioptions.IO
cmd.Flags().BoolVar(&noPrune, "no-prune", noPrune, "If true, do not prune previously applied objects.")
cmd.Flags().BoolVar(&serverDryRun, "server-side", serverDryRun, "If true, preview runs in the server instead of the client.")
cmd.Flags().BoolVar(&previewDestroy, "destroy", previewDestroy, "If true, preview of destroy operations will be displayed.")
cmd.Flags().StringVar(&r.output, "output", printers.DefaultPrinter(),
fmt.Sprintf("Output format, must be one of %s", strings.Join(printers.SupportedPrinters(), ",")))

r.Command = cmd
return r
Expand All @@ -62,6 +66,8 @@ type PreviewRunner struct {
Applier *apply.Applier
Destroyer *apply.Destroyer
provider provider.Provider

output string
}

// RunE is the function run from the cobra command.
Expand Down Expand Up @@ -133,6 +139,6 @@ func (r *PreviewRunner) RunE(cmd *cobra.Command, args []string) error {

// The printer will print updates from the channel. It will block
// until the channel is closed.
printer := printers.GetPrinter(printers.EventsPrinter, r.ioStreams)
printer := printers.GetPrinter(r.output, r.ioStreams)
return printer.Print(ch, drs)
}

0 comments on commit 7a1f6af

Please sign in to comment.