-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(render): add new command to render final file
- Loading branch information
Showing
29 changed files
with
674 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,17 @@ | ||
/* | ||
Copyright © 2023 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// | ||
// | ||
// Define the CLI data for the file sub-command | ||
// | ||
// | ||
|
||
func newAddFileCmd() *cobra.Command { | ||
addFileCmd := &cobra.Command{ | ||
Use: "file [sub-command]...", | ||
Use: "file", | ||
Short: "Sub-command to host the decK file manipulation operations", | ||
Long: `Sub-command to host the decK file manipulation operations`, | ||
} | ||
|
||
addFileCmd.AddCommand(newFileRenderCmd()) | ||
|
||
return addFileCmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package cmd | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/kong/deck/convert" | ||
"github.com/kong/deck/file" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
fileRenderCmdKongStateFile []string | ||
fileRenderCmdKongFileOutput string | ||
fileRenderCmdStateFormat string | ||
) | ||
|
||
func executeFileRenderCmd(_ *cobra.Command, _ []string) error { | ||
return convert.Convert( | ||
fileRenderCmdKongStateFile, | ||
fileRenderCmdKongFileOutput, | ||
file.Format(strings.ToUpper(fileRenderCmdStateFormat)), | ||
convert.FormatDistributed, | ||
convert.FormatKongGateway3x, | ||
true) | ||
} | ||
|
||
func newFileRenderCmd() *cobra.Command { | ||
renderCmd := &cobra.Command{ | ||
Use: "render", | ||
Short: "Render the configuration as Kong declarative config", | ||
Long: ``, | ||
Args: validateNoArgs, | ||
RunE: executeFileRenderCmd, | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
fileRenderCmdKongStateFile = args | ||
if len(fileRenderCmdKongStateFile) == 0 { | ||
fileRenderCmdKongStateFile = []string{"-"} // default to stdin | ||
} | ||
return preRunSilenceEventsFlag() | ||
}, | ||
} | ||
|
||
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.") | ||
|
||
return renderCmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
output.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.