Skip to content

Commit bc84bcf

Browse files
authored
remove xml decoder (#5)
Signed-off-by: Nico Braun <[email protected]>
1 parent db04c92 commit bc84bcf

File tree

2 files changed

+4
-20
lines changed

2 files changed

+4
-20
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Go Template CLI (tpl)
22

3-
Render json, yaml, toml & xml with go templates from the command line.
3+
Render json, yaml, & toml with go templates from the command line.
44

55
The templates are executed with the [text/template](https://pkg.go.dev/text/template) package. This means they come with the additional risks and benefits the text templates provide.
66

@@ -12,7 +12,7 @@ Options:
1212
-f, --file stringArray template file path. Can be specified multiple times
1313
-g, --glob stringArray template file glob. Can be specified multiple times
1414
-n, --name string if specified, execute the template with the given name
15-
-d, --decoder string decoder to use for input data. Supported values: json, yaml, toml, xml (default "json")
15+
-d, --decoder string decoder to use for input data. Supported values: json, yaml, toml (default "json")
1616
--options stringArray options to pass to the template engine
1717
--no-newline do not print newline at the end of the output
1818
-h, --help show the help text

cmd/tpl/tpl.go

+2-18
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"encoding/json"
5-
"encoding/xml"
65
"errors"
76
"fmt"
87
"io"
@@ -151,10 +150,9 @@ type decode func(io.Reader, *any) error
151150
// a map of decoder functions
152151
func decoderMap() map[string]decode {
153152
return map[string]decode{
153+
"json": decodeJson,
154154
"yaml": decodeYaml,
155155
"toml": decodeToml,
156-
"xml": decodeXml,
157-
"json": decodeJson,
158156
}
159157
}
160158

@@ -179,20 +177,6 @@ func decodeToml(in io.Reader, out *any) error {
179177
return err
180178
}
181179

182-
func decodeXml(in io.Reader, out *any) error {
183-
dec := xml.NewDecoder(in)
184-
for {
185-
err := dec.Decode(out)
186-
if err != nil {
187-
if err == io.EOF {
188-
break
189-
}
190-
return err
191-
}
192-
}
193-
return nil
194-
}
195-
196180
func decodeJson(in io.Reader, out *any) error {
197181
dec := json.NewDecoder(in)
198182
for {
@@ -227,7 +211,7 @@ func parseFlags() {
227211
flag.StringArrayVarP(&files, "file", "f", []string{}, "template file path. Can be specified multiple times")
228212
flag.StringArrayVarP(&globs, "glob", "g", []string{}, "template file glob. Can be specified multiple times")
229213
flag.StringVarP(&templateName, "name", "n", "", "if specified, execute the template with the given name")
230-
flag.StringVarP(&decoder, "decoder", "d", "json", "decoder to use for input data. Supported values: json, yaml, toml, xml")
214+
flag.StringVarP(&decoder, "decoder", "d", "json", "decoder to use for input data. Supported values: json, yaml, toml")
231215
flag.StringArrayVar(&options, "options", []string{}, "options to pass to the template engine")
232216
flag.BoolVar(&noNewline, "no-newline", false, "do not print newline at the end of the output")
233217
flag.BoolVarP(&showHelp, "help", "h", false, "show the help text")

0 commit comments

Comments
 (0)