@@ -4,19 +4,22 @@ import (
4
4
"fmt"
5
5
"log"
6
6
"os"
7
+ "strings"
7
8
8
9
"github.com/kong/deck/convert"
9
10
"github.com/kong/deck/cprint"
11
+ "github.com/kong/deck/file"
10
12
"github.com/kong/deck/utils"
11
13
"github.com/spf13/cobra"
12
14
)
13
15
14
16
var (
15
17
convertCmdSourceFormat string
16
- convertCmdDestinationFormat string
18
+ convertCmdDestinationFormat string // konnect/kong-gateway-3.x/etc
17
19
convertCmdInputFile string
18
20
convertCmdOutputFile string
19
21
convertCmdAssumeYes bool
22
+ convertCmdStateFormat string // yaml/json output
20
23
)
21
24
22
25
func executeConvert (_ * cobra.Command , _ []string ) error {
@@ -38,7 +41,13 @@ func executeConvert(_ *cobra.Command, _ []string) error {
38
41
return nil
39
42
}
40
43
41
- err = convert .Convert ([]string {convertCmdInputFile }, convertCmdOutputFile , sourceFormat , destinationFormat , false )
44
+ err = convert .Convert (
45
+ []string {convertCmdInputFile },
46
+ convertCmdOutputFile ,
47
+ file .Format (strings .ToUpper (convertCmdStateFormat )),
48
+ sourceFormat ,
49
+ destinationFormat ,
50
+ false )
42
51
if err != nil {
43
52
return fmt .Errorf ("converting file: %w" , err )
44
53
}
@@ -52,7 +61,13 @@ func executeConvert(_ *cobra.Command, _ []string) error {
52
61
return fmt .Errorf ("getting files from directory: %w" , err )
53
62
}
54
63
for _ , filename := range files {
55
- err = convert .Convert ([]string {filename }, filename , sourceFormat , destinationFormat , false )
64
+ err = convert .Convert (
65
+ []string {filename },
66
+ filename ,
67
+ file .Format (strings .ToUpper (convertCmdStateFormat )),
68
+ sourceFormat ,
69
+ destinationFormat ,
70
+ false )
56
71
if err != nil {
57
72
return fmt .Errorf ("converting '%s' file: %w" , filename , err )
58
73
}
@@ -100,6 +115,9 @@ can be converted into a 'kong-gateway-3.x' configuration file.`,
100
115
"file to write configuration to after conversion. Use `-` to write to stdout." )
101
116
convertCmd .Flags ().BoolVar (& convertCmdAssumeYes , "yes" ,
102
117
false , "assume `yes` to prompts and run non-interactively." )
118
+ convertCmd .Flags ().StringVar (& convertCmdStateFormat , "format" ,
119
+ "yaml" , "output file format: json or yaml." )
120
+
103
121
return convertCmd
104
122
}
105
123
0 commit comments