Skip to content

Commit c736dbc

Browse files
committed
Added xmlfmt utility
1 parent 4f7da36 commit c736dbc

8 files changed

Lines changed: 754 additions & 0 deletions

File tree

.goreleaser.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,23 @@ builds:
245245
- -X main.COMMIT={{.ShortCommit}}
246246
- -X main.BUILDER=goreleaser
247247

248+
- id: xmlfmt
249+
main: ./cmd/xmlfmt/xmlfmt.go
250+
binary: xmlfmt
251+
env:
252+
- CGO_ENABLED=0
253+
goos:
254+
- linux
255+
- windows
256+
- darwin
257+
ldflags:
258+
- -s
259+
- -w
260+
- -X main.VERSION={{.Version}}
261+
- -X main.LASTMOD={{.CommitDate}}
262+
- -X main.COMMIT={{.ShortCommit}}
263+
- -X main.BUILDER=goreleaser
264+
248265
archives:
249266
- formats: [tar.gz]
250267
# this name template makes the OS and Arch compatible with the results of `uname`.
@@ -278,6 +295,7 @@ homebrew_casks:
278295
- unicount
279296
- uniwhat
280297
- urly
298+
- xmlfmt
281299
# manpages:
282300
# completions:
283301
directory: Casks
@@ -308,6 +326,7 @@ homebrew_casks:
308326
system_command "/usr/bin/xattr", args: ["-dr", "com.apple.quarantine", "#{staged_path}/unicount"]
309327
system_command "/usr/bin/xattr", args: ["-dr", "com.apple.quarantine", "#{staged_path}/uniwhat"]
310328
system_command "/usr/bin/xattr", args: ["-dr", "com.apple.quarantine", "#{staged_path}/urly"]
329+
system_command "/usr/bin/xattr", args: ["-dr", "com.apple.quarantine", "#{staged_path}/xmlfmt"]
311330
end
312331
313332
nfpms:

cmd/xmlfmt/README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# xmlfmt
2+
3+
Format XML
4+
5+
## Usage
6+
7+
xmlfmt [options] [file|-]
8+
9+
If no input file is provided, xmlfmt reads from stdin.
10+
If no mode is specified, xmlfmt defaults to pretty output.
11+
12+
## Modes
13+
14+
* --pretty: Emit pretty-printed XML
15+
* --compact: Emit compact XML
16+
* --indent: Pretty indent style, either tab or an integer number of spaces (default: 2)
17+
18+
Only one of --pretty or --compact may be used.
19+
20+
## XML Transform Options
21+
22+
* --sort-elements: Sort child elements recursively by tag name
23+
* --default-namespace: Set or switch the default namespace on the root element
24+
* --clear-default-namespace: Remove the default namespace from the root element
25+
* --remove-namespace: Remove a namespace by prefix or URI (repeatable)
26+
* --named-entities-to-numeric: Convert HTML named entities to numeric entities
27+
* --remove-doctype: Remove the DOCTYPE directive
28+
* --set-doctype: Set the DOCTYPE directive (with or without leading DOCTYPE)
29+
* --remove-declaration: Remove the XML declaration
30+
* --set-declaration: Set XML declaration content, for example version="1.0" encoding="UTF-8"
31+
32+
Only one of --remove-doctype or --set-doctype may be used.
33+
Only one of --remove-declaration or --set-declaration may be used.
34+
35+
## Output Options
36+
37+
* --trailing-newline: Emit a trailing newline
38+
* --eol: End-of-line style, one of lf, cr, or crlf (default: lf)
39+
40+
## Standard Flags
41+
42+
* --help, -h: Show help message
43+
* --version: Print version information
44+
45+
## Examples
46+
47+
Pretty print a file with 4-space indentation:
48+
49+
xmlfmt --pretty --indent 4 input.xml
50+
51+
Compact output from stdin:
52+
53+
cat input.xml | xmlfmt --compact
54+
55+
Sort elements and change the default namespace:
56+
57+
xmlfmt --sort-elements --default-namespace urn:example input.xml
58+
59+
Remove one namespace prefix and convert named entities:
60+
61+
xmlfmt --remove-namespace a --named-entities-to-numeric input.xml
62+
63+
Remove declaration and doctype:
64+
65+
xmlfmt --remove-declaration --remove-doctype input.xml
66+

0 commit comments

Comments
 (0)