Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cli): create 'gateway' subcommand for network commands #962

Merged
merged 3 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
179 changes: 0 additions & 179 deletions cmd/dump.go

This file was deleted.

10 changes: 5 additions & 5 deletions cmd/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"github.com/spf13/cobra"
)

func newAddFileCmd() *cobra.Command {
addFileCmd := &cobra.Command{
func newFileSubCmd() *cobra.Command {
fileCmd := &cobra.Command{
Use: "file [sub-command]...",
Short: "Subcommand to host the decK file manipulation operations",
Long: `Subcommand to host the decK file manipulation operations.`,
Short: "Subcommand to host the decK file operations",
Long: `Subcommand to host the decK file operations.`,
}

return addFileCmd
return fileCmd
}
18 changes: 15 additions & 3 deletions cmd/file_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,21 @@ func executeConvert(_ *cobra.Command, _ []string) error {
}

// newConvertCmd represents the convert command
func newConvertCmd() *cobra.Command {
func newConvertCmd(deprecated bool) *cobra.Command {
short := "Convert files from one format into another format"
execute := executeConvert
fileInDefault := "-"
fileOutDefault := "-"
if deprecated {
short = "[deprecated] use 'file convert' instead"
execute = func(cmd *cobra.Command, args []string) error {
cprint.UpdatePrintf("Warning: 'deck convert' is DEPRECATED and will be removed in a future version. " +
"Use 'deck file convert' instead.\n")
return executeConvert(cmd, args)
}
fileInDefault = ""
fileOutDefault = "kong.yaml"
}

convertCmd := &cobra.Command{
Use: "convert",
Expand All @@ -103,9 +115,9 @@ can be converted into a 'kong-gateway-3.x' configuration file.`,
fmt.Sprintf("format of the source file, allowed formats: %v", sourceFormats))
convertCmd.Flags().StringVar(&convertCmdDestinationFormat, "to", "",
fmt.Sprintf("desired format of the output, allowed formats: %v", destinationFormats))
convertCmd.Flags().StringVar(&convertCmdInputFile, "input-file", "",
convertCmd.Flags().StringVar(&convertCmdInputFile, "input-file", fileInDefault,
"configuration file to be converted. Use `-` to read from stdin.")
convertCmd.Flags().StringVar(&convertCmdOutputFile, "output-file", "kong.yaml",
convertCmd.Flags().StringVarP(&convertCmdOutputFile, "output-file", "o", fileOutDefault,
"file to write configuration to after conversion. Use `-` to write to stdout.")
convertCmd.Flags().BoolVar(&convertCmdAssumeYes, "yes",
false, "assume `yes` to prompts and run non-interactively.")
Expand Down
15 changes: 15 additions & 0 deletions cmd/gateway.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cmd

import (
"github.com/spf13/cobra"
)

func newGatewaySubCmd() *cobra.Command {
gatewaySubCmd := &cobra.Command{
Use: "gateway [sub-command]...",
Short: "Subcommand to host the decK network operations",
Long: `Subcommand to host the decK network operations.`,
}

return gatewaySubCmd
}
69 changes: 49 additions & 20 deletions cmd/diff.go → cmd/gateway_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"

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

Expand All @@ -14,35 +15,63 @@ var (
diffJSONOutput bool
)

func executeDiff(cmd *cobra.Command, _ []string) error {
return syncMain(cmd.Context(), diffCmdKongStateFile, true,
diffCmdParallelism, 0, diffWorkspace, diffJSONOutput)
}

// newDiffCmd represents the diff command
func newDiffCmd() *cobra.Command {
diffCmd := &cobra.Command{
Use: "diff",
Short: "Diff the current entities in Kong with the one on disks",
Long: `The diff command is similar to a dry run of the 'decK sync' command.
func newDiffCmd(deprecated bool) *cobra.Command {
use := "diff [flags] [kong-state-files...]"
short := "Diff the current entities in Kong with the one on disks"
execute := executeDiff
argsValidator := cobra.MinimumNArgs(0)
preRun := func(cmd *cobra.Command, args []string) error {
diffCmdKongStateFile = args
if len(diffCmdKongStateFile) == 0 {
diffCmdKongStateFile = []string{"-"}
}
return preRunSilenceEventsFlag()
}

It loads entities from Kong and performs a diff with
the entities in local files. This allows you to see the entities
that will be created, updated, or deleted.
`,
Args: validateNoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return syncMain(cmd.Context(), diffCmdKongStateFile, true,
diffCmdParallelism, 0, diffWorkspace, diffJSONOutput)
},
PreRunE: func(cmd *cobra.Command, args []string) error {
if deprecated {
use = "diff"
short = "[deprecated] use 'gateway diff' instead"
execute = func(cmd *cobra.Command, args []string) error {
cprint.UpdatePrintf("Warning: 'deck diff' is DEPRECATED and will be removed in a future version. " +
"Use 'deck gateway diff' instead.\n")
return executeDiff(cmd, args)
}
argsValidator = validateNoArgs
preRun = func(cmd *cobra.Command, args []string) error {
if len(diffCmdKongStateFile) == 0 {
return fmt.Errorf("a state file with Kong's configuration " +
"must be specified using `-s`/`--state` flag")
}
return preRunSilenceEventsFlag()
},
}
}

diffCmd.Flags().StringSliceVarP(&diffCmdKongStateFile,
"state", "s", []string{"kong.yaml"}, "file(s) containing Kong's configuration.\n"+
"This flag can be specified multiple times for multiple files.\n"+
"Use `-` to read from stdin.")
diffCmd := &cobra.Command{
Use: use,
Short: short,
Long: `The diff command is similar to a dry run of the 'decK kong sync' command.

It loads entities from Kong and performs a diff with
the entities in local files. This allows you to see the entities
that will be created, updated, or deleted.
`,
Args: argsValidator,
RunE: execute,
PreRunE: preRun,
}

if deprecated {
diffCmd.Flags().StringSliceVarP(&diffCmdKongStateFile,
"state", "s", []string{"kong.yaml"}, "file(s) containing Kong's configuration.\n"+
"This flag can be specified multiple times for multiple files.\n"+
"Use `-` to read from stdin.")
}
diffCmd.Flags().StringVarP(&diffWorkspace, "workspace", "w",
"", "Diff configuration with a specific workspace "+
"(Kong Enterprise only).\n"+
Expand Down
Loading
Loading