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

fix(cli): deprecated commands default to kong.yaml #1073

Merged
merged 1 commit into from
Nov 1, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ _testmain.go
deck
dist/
docs/cli-docs/

# vscode editor files
.vscode/
31 changes: 21 additions & 10 deletions cmd/file_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import (
)

var (
convertCmdSourceFormat string
convertCmdDestinationFormat string // konnect/kong-gateway-3.x/etc
convertCmdInputFile string
convertCmdOutputFile string
convertCmdAssumeYes bool
convertCmdStateFormat string // yaml/json output
convertCmdSourceFormat string
convertCmdDestinationFormat string // konnect/kong-gateway-3.x/etc
convertCmdInputFile string
convertCmdOutputFile string
convertCmdInputFileDeprecated string
convertCmdOutputFileDeprecated string
convertCmdAssumeYes bool
convertCmdStateFormat string // yaml/json output
)

func executeConvert(_ *cobra.Command, _ []string) error {
Expand Down Expand Up @@ -91,6 +93,8 @@ func newConvertCmd(deprecated bool) *cobra.Command {
if deprecated {
short = "[deprecated] use 'file convert' instead"
execute = func(cmd *cobra.Command, args []string) error {
convertCmdInputFile = convertCmdInputFileDeprecated
convertCmdOutputFile = convertCmdOutputFileDeprecated
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)
Expand All @@ -115,10 +119,17 @@ 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", fileInDefault,
"configuration file to be converted. Use `-` to read from stdin.")
convertCmd.Flags().StringVarP(&convertCmdOutputFile, "output-file", "o", fileOutDefault,
"file to write configuration to after conversion. Use `-` to write to stdout.")
if deprecated {
convertCmd.Flags().StringVar(&convertCmdInputFileDeprecated, "input-file", fileInDefault,
"configuration file to be converted. Use `-` to read from stdin.")
convertCmd.Flags().StringVarP(&convertCmdOutputFileDeprecated, "output-file", "o", fileOutDefault,
"file to write configuration to after conversion. Use `-` to write to stdout.")
} else {
convertCmd.Flags().StringVar(&convertCmdInputFile, "input-file", fileInDefault,
"configuration file to be converted. Use `-` to read from stdin.")
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.")
convertCmd.Flags().StringVar(&convertCmdStateFormat, "format",
Expand Down
24 changes: 16 additions & 8 deletions cmd/gateway_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ import (
const defaultFileOutName = "kong"

var (
dumpCmdKongStateFile string
dumpCmdStateFormat string
dumpWorkspace string
dumpAllWorkspaces bool
dumpWithID bool
dumpCmdKongStateFileDeprecated string
dumpCmdKongStateFile string
dumpCmdStateFormat string
dumpWorkspace string
dumpAllWorkspaces bool
dumpWithID bool
)

func listWorkspaces(ctx context.Context, client *kong.Client) ([]string, error) {
Expand Down Expand Up @@ -149,6 +150,7 @@ func newDumpCmd(deprecated bool) *cobra.Command {
if deprecated {
short = "[deprecated] use 'gateway dump' instead"
execute = func(cmd *cobra.Command, args []string) error {
dumpCmdKongStateFile = dumpCmdKongStateFileDeprecated
cprint.UpdatePrintf("Warning: 'deck dump' is DEPRECATED and will be removed in a future version. " +
"Use 'deck gateway dump' instead.\n")
return executeDump(cmd, args)
Expand All @@ -168,9 +170,15 @@ configure Kong.`,
RunE: execute,
}

dumpCmd.Flags().StringVarP(&dumpCmdKongStateFile, "output-file", "o",
fileOutDefault, "file to which to write Kong's configuration."+
"Use `-` to write to stdout.")
if deprecated {
dumpCmd.Flags().StringVarP(&dumpCmdKongStateFileDeprecated, "output-file", "o",
fileOutDefault, "file to which to write Kong's configuration."+
"Use `-` to write to stdout.")
} else {
dumpCmd.Flags().StringVarP(&dumpCmdKongStateFile, "output-file", "o",
fileOutDefault, "file to which to write Kong's configuration."+
"Use `-` to write to stdout.")
}
dumpCmd.Flags().StringVar(&dumpCmdStateFormat, "format",
"yaml", "output file format: json or yaml.")
dumpCmd.Flags().BoolVar(&dumpWithID, "with-id",
Expand Down