Skip to content

Commit

Permalink
fix(convert): the file-convert command should use positional args
Browse files Browse the repository at this point in the history
This lines up with other "file" subcommands
  • Loading branch information
Tieske committed Jul 17, 2023
1 parent c6529c1 commit 549b213
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions cmd/file_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,14 @@ func executeConvert(_ *cobra.Command, _ []string) error {
func newConvertCmd(deprecated bool) *cobra.Command {
short := "Convert files from one format into another format"
execute := executeConvert
args := cobra.ArbitraryArgs
if deprecated {
short = "[deprecated] use 'file convert' instead"
execute = func(cmd *cobra.Command, args []string) error {
log.Println("Warning: the 'deck convert' command was deprecated and moved to 'deck file convert'")
return executeConvert(cmd, args)
}
args = validateNoArgs
}

convertCmd := &cobra.Command{
Expand All @@ -99,8 +101,23 @@ func newConvertCmd(deprecated bool) *cobra.Command {
Long: `The convert command changes configuration files from one format
into another compatible format. For example, a configuration for 'kong-gateway-2.x'
can be converted into a 'kong-gateway-3.x' configuration file.`,
Args: validateNoArgs,
Args: args,
RunE: execute,
PreRunE: func(cmd *cobra.Command, args []string) error {
if deprecated {
if len(fileRenderCmdKongStateFile) == 0 {
return fmt.Errorf("a file containing the Kong configuration " +
"must be specified using `--input-file` flag")
}
return preRunSilenceEventsFlag()
}

fileRenderCmdKongStateFile = args
if len(fileRenderCmdKongStateFile) == 0 {
fileRenderCmdKongStateFile = []string{"-"} // default to stdin
}
return preRunSilenceEventsFlag()
},
}

sourceFormats := []convert.Format{convert.FormatKongGateway, convert.FormatKongGateway2x}
Expand All @@ -109,8 +126,10 @@ 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", "",
"configuration file to be converted. Use `-` to read from stdin.")
if deprecated {
convertCmd.Flags().StringVar(&convertCmdInputFile, "input-file", "",
"configuration file to be converted. Use `-` to read from stdin.")
}
convertCmd.Flags().StringVarP(&convertCmdOutputFile, "output-file", "o", "kong.yaml",
"file to write configuration to after conversion. Use `-` to write to stdout.")
convertCmd.Flags().BoolVar(&convertCmdAssumeYes, "yes",
Expand Down

0 comments on commit 549b213

Please sign in to comment.