@@ -64,9 +64,9 @@ func initCommand(cmd *cobra.Command, args []string) (string, []string, error) {
64
64
}
65
65
if inputFormat == "" || inputFormat == "auto" || inputFormat == "a" {
66
66
67
- inputFormat = yqlib .FormatFromFilename (inputFilename )
67
+ inputFormat = yqlib .FormatStringFromFilename (inputFilename )
68
68
69
- _ , err := yqlib .InputFormatFromString (inputFormat )
69
+ _ , err := yqlib .FormatFromString (inputFormat )
70
70
if err != nil {
71
71
// unknown file type, default to yaml
72
72
yqlib .GetLogger ().Debug ("Unknown file format extension '%v', defaulting to yaml" , inputFormat )
@@ -86,23 +86,23 @@ func initCommand(cmd *cobra.Command, args []string) (string, []string, error) {
86
86
// before this was introduced, `yq -pcsv things.csv`
87
87
// would produce *yaml* output.
88
88
//
89
- outputFormat = yqlib .FormatFromFilename (inputFilename )
89
+ outputFormat = yqlib .FormatStringFromFilename (inputFilename )
90
90
if inputFilename != "-" {
91
91
yqlib .GetLogger ().Warning ("yq default output is now 'auto' (based on the filename extension). Normally yq would output '%v', but for backwards compatibility 'yaml' has been set. Please use -oy to specify yaml, or drop the -p flag." , outputFormat )
92
92
}
93
93
outputFormat = "yaml"
94
94
}
95
95
96
- outputFormatType , err := yqlib .OutputFormatFromString (outputFormat )
96
+ outputFormatType , err := yqlib .FormatFromString (outputFormat )
97
97
98
98
if err != nil {
99
99
return "" , nil , err
100
100
}
101
101
yqlib .GetLogger ().Debug ("Using input format %v" , inputFormat )
102
102
yqlib .GetLogger ().Debug ("Using output format %v" , outputFormat )
103
103
104
- if outputFormatType == yqlib .YamlOutputFormat ||
105
- outputFormatType == yqlib .PropsOutputFormat {
104
+ if outputFormatType == yqlib .YamlFormat ||
105
+ outputFormatType == yqlib .PropertiesFormat {
106
106
unwrapScalar = true
107
107
}
108
108
if unwrapScalarFlag .IsExplicitlySet () {
@@ -113,42 +113,20 @@ func initCommand(cmd *cobra.Command, args []string) (string, []string, error) {
113
113
}
114
114
115
115
func configureDecoder (evaluateTogether bool ) (yqlib.Decoder , error ) {
116
- yqlibInputFormat , err := yqlib .InputFormatFromString (inputFormat )
116
+ format , err := yqlib .FormatFromString (inputFormat )
117
117
if err != nil {
118
118
return nil , err
119
119
}
120
- yqlibDecoder , err := createDecoder (yqlibInputFormat , evaluateTogether )
120
+ yqlib .ConfiguredYamlPreferences .EvaluateTogether = evaluateTogether
121
+
122
+ yqlibDecoder := format .DecoderFactory ()
121
123
if yqlibDecoder == nil {
122
124
return nil , fmt .Errorf ("no support for %s input format" , inputFormat )
123
125
}
124
- return yqlibDecoder , err
126
+ return yqlibDecoder , nil
125
127
}
126
128
127
- func createDecoder (format yqlib.InputFormat , evaluateTogether bool ) (yqlib.Decoder , error ) {
128
- switch format {
129
- case yqlib .LuaInputFormat :
130
- return yqlib .NewLuaDecoder (yqlib .ConfiguredLuaPreferences ), nil
131
- case yqlib .XMLInputFormat :
132
- return yqlib .NewXMLDecoder (yqlib .ConfiguredXMLPreferences ), nil
133
- case yqlib .PropertiesInputFormat :
134
- return yqlib .NewPropertiesDecoder (), nil
135
- case yqlib .JsonInputFormat :
136
- return yqlib .NewJSONDecoder (), nil
137
- case yqlib .CSVObjectInputFormat :
138
- return yqlib .NewCSVObjectDecoder (yqlib .ConfiguredCsvPreferences ), nil
139
- case yqlib .TSVObjectInputFormat :
140
- return yqlib .NewCSVObjectDecoder (yqlib .ConfiguredTsvPreferences ), nil
141
- case yqlib .TomlInputFormat :
142
- return yqlib .NewTomlDecoder (), nil
143
- case yqlib .YamlInputFormat :
144
- prefs := yqlib .ConfiguredYamlPreferences
145
- prefs .EvaluateTogether = evaluateTogether
146
- return yqlib .NewYamlDecoder (prefs ), nil
147
- }
148
- return nil , fmt .Errorf ("invalid decoder: %v" , format )
149
- }
150
-
151
- func configurePrinterWriter (format * yqlib.PrinterOutputFormat , out io.Writer ) (yqlib.PrinterWriter , error ) {
129
+ func configurePrinterWriter (format * yqlib.Format , out io.Writer ) (yqlib.PrinterWriter , error ) {
152
130
153
131
var printerWriter yqlib.PrinterWriter
154
132
@@ -166,18 +144,10 @@ func configurePrinterWriter(format *yqlib.PrinterOutputFormat, out io.Writer) (y
166
144
}
167
145
168
146
func configureEncoder () (yqlib.Encoder , error ) {
169
- yqlibOutputFormat , err := yqlib .OutputFormatFromString (outputFormat )
147
+ yqlibOutputFormat , err := yqlib .FormatFromString (outputFormat )
170
148
if err != nil {
171
149
return nil , err
172
150
}
173
- yqlibEncoder , err := createEncoder (yqlibOutputFormat )
174
- if yqlibEncoder == nil {
175
- return nil , fmt .Errorf ("no support for %s output format" , outputFormat )
176
- }
177
- return yqlibEncoder , err
178
- }
179
-
180
- func createEncoder (format * yqlib.PrinterOutputFormat ) (yqlib.Encoder , error ) {
181
151
yqlib .ConfiguredXMLPreferences .Indent = indent
182
152
yqlib .ConfiguredYamlPreferences .Indent = indent
183
153
yqlib .ConfiguredJSONPreferences .Indent = indent
@@ -191,11 +161,12 @@ func createEncoder(format *yqlib.PrinterOutputFormat) (yqlib.Encoder, error) {
191
161
192
162
yqlib .ConfiguredYamlPreferences .PrintDocSeparators = ! noDocSeparators
193
163
194
- encoder := format .EncoderFactory ()
164
+ encoder := yqlibOutputFormat .EncoderFactory ()
165
+
195
166
if encoder == nil {
196
- return nil , fmt .Errorf ("invalid encoder: %v " , format )
167
+ return nil , fmt .Errorf ("no support for %s output format " , outputFormat )
197
168
}
198
- return encoder , nil
169
+ return encoder , err
199
170
}
200
171
201
172
// this is a hack to enable backwards compatibility with githubactions (which pipe /dev/null into everything)
0 commit comments