Skip to content

Commit

Permalink
fix(cli): improve deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed Nov 27, 2023
1 parent ee1522b commit 670c084
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 17 deletions.
10 changes: 6 additions & 4 deletions cmd/file_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"

"github.com/kong/deck/convert"
"github.com/kong/go-database-reconciler/pkg/cprint"
"github.com/kong/go-database-reconciler/pkg/file"
"github.com/kong/go-database-reconciler/pkg/utils"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -91,12 +90,15 @@ func newConvertCmd(deprecated bool) *cobra.Command {
fileInDefault := "-"
fileOutDefault := "-"
if deprecated {
short = "[deprecated] use 'file convert' instead"
short = "[deprecated] see 'deck file convert --help' for changes to the command"
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")
fmt.Fprintf(os.Stderr, "Warning: 'deck convert' is DEPRECATED and will be removed in a "+
"future version. Use 'deck file convert' instead.\n"+
" Note: - see 'deck file convert --help' for changes to the command\n"+
" - files changed to positional arguments without the '-s/--state' flag\n"+
" - the default changed from 'kong.yaml' to '-' (stdin/stdout)\n")
return executeConvert(cmd, args)
}
fileInDefault = ""
Expand Down
8 changes: 6 additions & 2 deletions cmd/gateway_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ func newDiffCmd(deprecated bool) *cobra.Command {

if deprecated {
use = "diff"
short = "[deprecated] use 'gateway diff' instead"
short = "[deprecated] see 'deck gateway diff --help' for changes to the command"
execute = func(cmd *cobra.Command, args []string) error {
fmt.Fprintf(os.Stderr, "Warning: 'deck diff' is DEPRECATED and will be removed in a future version. "+
"Use 'deck gateway diff' instead.\n")
"Use 'deck gateway diff' instead.\n"+
" Note: - see 'deck gateway diff --help' for changes to the command\n"+
" - files changed to positional arguments without the '-s/--state' flag\n"+
" - the default changed from 'kong.yaml' to '-' (stdin/stdout)\n")

return executeDiff(cmd, args)
}
argsValidator = validateNoArgs
Expand Down
8 changes: 5 additions & 3 deletions cmd/gateway_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,13 @@ func newDumpCmd(deprecated bool) *cobra.Command {
execute := executeDump
fileOutDefault := "-"
if deprecated {
short = "[deprecated] use 'gateway dump' instead"
short = "[deprecated] see 'deck gateway dump --help' for changes to the command"
execute = func(cmd *cobra.Command, args []string) error {
dumpCmdKongStateFile = dumpCmdKongStateFileDeprecated
fmt.Fprintf(os.Stderr, "Warning: 'deck dump' is DEPRECATED and will be removed in a future version. "+
"Use 'deck gateway dump' instead.\n")
fmt.Fprintf(os.Stderr, "Warning: 'deck dump' is DEPRECATED and will be removed in a "+
"future version. Use 'deck gateway dump' instead.\n"+
" Note: - see 'deck gateway dump --help' for changes to the command\n"+
" - the default changed from 'kong.yaml' to '-' (stdin/stdout)\n")
return executeDump(cmd, args)
}
fileOutDefault = defaultFileOutName
Expand Down
2 changes: 1 addition & 1 deletion cmd/gateway_ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func newPingCmd(deprecated bool) *cobra.Command {
short := "Verify connectivity with Kong"
execute := executePing
if deprecated {
short = "[deprecated] use 'gateway ping' instead"
short = "[deprecated] use 'deck gateway ping' instead"
execute = func(cmd *cobra.Command, args []string) error {
fmt.Fprintf(os.Stderr, "Warning: 'deck ping' is DEPRECATED and will be removed in a future version. "+
"Use 'deck gateway ping' instead.\n")
Expand Down
2 changes: 1 addition & 1 deletion cmd/gateway_reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func newResetCmd(deprecated bool) *cobra.Command {
short := "Reset deletes all entities in Kong"
execute := executeReset
if deprecated {
short = "[deprecated] use 'gateway reset' instead"
short = "[deprecated] use 'deck gateway reset' instead"
execute = func(cmd *cobra.Command, args []string) error {
fmt.Fprintf(os.Stderr, "Warning: 'deck reset' is DEPRECATED and will be removed in a future version. "+
"Use 'deck gateway reset' instead.\n")
Expand Down
9 changes: 6 additions & 3 deletions cmd/gateway_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ func newSyncCmd(deprecated bool) *cobra.Command {

if deprecated {
use = "sync"
short = "[deprecated] use 'gateway sync' instead"
short = "[deprecated] see 'deck gateway sync --help' for changes to the command"
execute = func(cmd *cobra.Command, args []string) error {
fmt.Fprintf(os.Stderr, "Warning: 'deck sync' is DEPRECATED and will be removed in a future version. "+
"Use 'deck gateway sync' instead.\n")
fmt.Fprintf(os.Stderr, "Warning: 'deck sync' is DEPRECATED and will be removed in a "+
"future version. Use 'deck gateway sync' instead.\n"+
" Note: - see 'deck gateway sync --help' for changes to the command\n"+
" - files changed to positional arguments without the '-s/--state' flag\n"+
" - the default changed from 'kong.yaml' to '-' (stdin/stdout)\n")
return executeSync(cmd, args)
}
argsValidator = validateNoArgs
Expand Down
11 changes: 8 additions & 3 deletions cmd/gateway_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ and alerts if there are broken relationships, or missing links present.

if deprecated {
use = "validate"
short = "[deprecated] use 'gateway validate' or 'file validate' instead"
short = "[deprecated] see 'deck [file|gateway] validate --help' for changes to the commands"
long = `The validate command reads the state file and ensures validity.
It reads all the specified state files and reports YAML/JSON
parsing issues. It also checks for foreign relationships
Expand All @@ -99,8 +99,13 @@ this command unless --online flag is used.
`

execute = func(cmd *cobra.Command, args []string) error {
fmt.Fprintf(os.Stderr, "Warning: 'deck validate' is DEPRECATED and will be removed in a future version. "+
"Use 'deck gateway validate' instead.\n")
fmt.Fprintf(os.Stderr, "Warning: 'deck validate' is DEPRECATED and will be removed in a "+
"future version. Use 'deck [file|gateway] validate' instead.\n"+
" Note: - see 'deck [file|gateway] validate --help' for changes to the command\n"+
" - files changed to positional arguments without the '-s/--state' flag\n"+
" - the '--online' flag is removed, use either 'deck file' or 'deck gateway'\n"+
" - the default changed from 'kong.yaml' to '-' (stdin/stdout)\n")

return executeValidate(cmd, args)
}
argsValidator = validateNoArgs
Expand Down

0 comments on commit 670c084

Please sign in to comment.