Skip to content

Commit 8400b85

Browse files
authored
Merge pull request #263 from fsommar/add-output-flag
Add output flag to destroy and preview commands
2 parents db61213 + 7a1f6af commit 8400b85

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

cmd/destroy/cmddestroy.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
package destroy
55

66
import (
7+
"fmt"
8+
"strings"
9+
710
"github.com/spf13/cobra"
811
"k8s.io/cli-runtime/pkg/genericclioptions"
912
cmdutil "k8s.io/kubectl/pkg/cmd/util"
@@ -28,6 +31,9 @@ func GetDestroyRunner(provider provider.Provider, ioStreams genericclioptions.IO
2831
RunE: r.RunE,
2932
}
3033

34+
cmd.Flags().StringVar(&r.output, "output", printers.DefaultPrinter(),
35+
fmt.Sprintf("Output format, must be one of %s", strings.Join(printers.SupportedPrinters(), ",")))
36+
3137
r.Command = cmd
3238
return r
3339
}
@@ -44,6 +50,8 @@ type DestroyRunner struct {
4450
ioStreams genericclioptions.IOStreams
4551
Destroyer *apply.Destroyer
4652
provider provider.Provider
53+
54+
output string
4755
}
4856

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

7381
// The printer will print updates from the channel. It will block
7482
// until the channel is closed.
75-
printer := printers.GetPrinter(printers.EventsPrinter, r.ioStreams)
83+
printer := printers.GetPrinter(r.output, r.ioStreams)
7684
return printer.Print(ch, r.Destroyer.DryRunStrategy)
7785
}

cmd/preview/cmdpreview.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package preview
55

66
import (
77
"context"
8+
"fmt"
9+
"strings"
810

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

4852
r.Command = cmd
4953
return r
@@ -62,6 +66,8 @@ type PreviewRunner struct {
6266
Applier *apply.Applier
6367
Destroyer *apply.Destroyer
6468
provider provider.Provider
69+
70+
output string
6571
}
6672

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

134140
// The printer will print updates from the channel. It will block
135141
// until the channel is closed.
136-
printer := printers.GetPrinter(printers.EventsPrinter, r.ioStreams)
142+
printer := printers.GetPrinter(r.output, r.ioStreams)
137143
return printer.Print(ch, drs)
138144
}

0 commit comments

Comments
 (0)