Skip to content

Commit

Permalink
fixes; review + args for files
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed Jul 17, 2023
1 parent 5ca2755 commit 9cf04c7
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions cmd/file_render.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
package cmd

import (
"fmt"

"github.com/kong/deck/convert"
"github.com/spf13/cobra"
)

var (
fileRenderCmdKongStateFile []string
fileRenderCmdKongFileOutput string
fileRenderCmdStateFormat string
)

func executeFileRenderCmd(_ *cobra.Command, _ []string) error {
destinationFormat, err := convert.ParseFormat(fileRenderCmdStateFormat)
if err != nil {
return err
}

return convert.Convert(fileRenderCmdKongStateFile, fileRenderCmdKongFileOutput,
convert.FormatDistributed, destinationFormat, true)
convert.FormatDistributed, convert.FormatKongGateway3x, true)
}

func newFileRenderCmd() *cobra.Command {
Expand All @@ -31,23 +23,21 @@ func newFileRenderCmd() *cobra.Command {
Args: validateNoArgs,
RunE: executeFileRenderCmd,
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(fileRenderCmdStateFormat) == 0 {
return fmt.Errorf("a state file with Kong's configuration " +
"must be specified using `-s`/`--state` flag")
fileRenderCmdKongStateFile = args
if len(fileRenderCmdKongStateFile) == 0 {
fileRenderCmdKongStateFile = []string{"-"} // default to stdin
}
return preRunSilenceEventsFlag()
},
}

renderCmd.Flags().StringSliceVarP(&fileRenderCmdKongStateFile,
"state", "s", []string{"-"}, "file(s) containing Kong's configuration.\n"+
"This flag can be specified multiple times for multiple files.\n"+
"Use `-` to read from stdin.")
renderCmd.Flags().StringVarP(&fileRenderCmdKongFileOutput, "output-file", "o",
"-", "file to which to write Kong's configuration."+
"Use `-` to write to stdout.")
renderCmd.Flags().StringVar(&fileRenderCmdStateFormat, "format",
"yaml", "output file format: json or yaml.")

// TODO: support json output
// renderCmd.Flags().StringVar(&fileRenderCmdStateFormat, "format",
// "yaml", "output file format: json or yaml.")

return renderCmd
}

0 comments on commit 9cf04c7

Please sign in to comment.