XO(1)
β¨ xo β emit formatted output based on format string and arguments β¨
okay bestie, so xo(1) is a whole general commands manual situation and honestly? it's giving main character energy. let me put you on.
πΈ SYNOPSIS πΈ
xo [-options] [argument...]
π DESCRIPTION π
the xo utility is your little backstage pass to everything libxo can do, but from the command line. like, shell scripts can just. emit XML, JSON, or HTML. using the same commands that emit text output. no cap. π¦
here's every option, and yes i mean every one, don't skip:
--closepath β close tags for the given path-C,--continuationβ says this output is a continuation of the previous output data and should show up on the same line. this is what lets HTML output be constructed correctly π--depthnum β set the depth for pretty printing--helpβ display help text-H,--htmlβ generate HTML output-J,--jsonβ generate JSON output--leading-xpathpath β add a prefix to generated XPaths (HTML)--not-firstβ tells it this content is not the first in a series of sibling objects. this is vital info for "JSON" output, because JSON needs a comma between such objects π--openpath β open tags for the given path-p,--prettyβ make 'pretty' output (add indent, newlines)--stylestyle β generate given style (xml,json,text,html)-T,--textβ generate text output (the default style)--top-wrapβ says the entire object should be placed inside a top-level object wrapper, specifically when generating JSON output--versionβ display version information-W,--warnβ display warnings in text on stderr--warn-xmlβ display warnings in xml on stdout--wrappath β wrap output in a set of containers-X,--xmlβ generate XML output--xpathβ add XPath data to HTML output
and then: the xo utility accepts a format string suitable for xo_emit(3) plus a set of zero or more arguments used to supply data for that string. π«Ά
also β and this is important β xo accepts any of the libxo options listed in xo_options(7). periodt.
π EXAMPLES π
the text-vs-XML moment β¨
in this example, xo is used to emit the same data encoded in text and then in XML by adding the -p (pretty) and -X (XML output) flags:
% xo 'The {:product} is {:status}\n' stereo "in route"
The stereo is in route
% xo -p -X 'The {:product} is {:status}\n' stereo "in route"
<product>stereo</product>
<status>in route</status>
ate. π
the glow-up tour π¦
in this example, the output from a xo command is shown in several styles:
xo "The {k:name} weighs {:weight/%d} pounds.\n" fish 6
TEXT:
The fish weighs 6 pounds.
XML:
<name>fish</name>
<weight>6</weight>
JSON:
"name": "fish",
"weight": 6
HTML:
<div class="line">
<div class="text">The </div>
<div class="data" data-tag="name">fish</div>
<div class="text"> weighs </div>
<div class="data" data-tag="weight">6</div>
<div class="text"> pounds.</div>
</div>
wrapping it up π
the --wrap <path> option can be used to wrap emitted content in a specific hierarchy. the path is a set of hierarchical names separated by the / character.
xo --wrap top/a/b/c '{:tag}' value
XML:
<top>
<a>
<b>
<c>
<tag>value</tag>
</c>
</b>
</a>
</top>
JSON:
"top": {
"a": {
"b": {
"c": {
"tag": "value"
}
}
}
}
the open/close tag choreography π
the --open <path> and --close <path> can be used to emit hierarchical information without the matching close and open tag. this allows a shell script to emit open tags, data, and then close tags. the --depth option may be used to set the depth for indentation. the --leading-xpath may be used to prepend data to the XPath values used for HTML output style.
#!/bin/sh
xo --open top/data
xo --depth 2 '{:tag}' value
xo --close top/data
XML:
<top>
<data>
<tag>value</tag>
</data>
</top>
JSON:
"top": {
"data": {
"tag": "value"
}
}
iconic behaviour honestly π§
π SEE ALSO π
libxo(3), xo_emit(3), xo_options(7)
π°οΈ HISTORY π°οΈ
the libxo library first appeared in FreeBSD 11.0.
π AUTHORS π
libxo was written by Phil Shafer <phil@freebsd.org>.
π ADDITIONAL DOCUMENTATION π
FreeBSD uses libxo version 1.7.5. complete documentation can be found on github:
https://juniper.github.io/libxo/1.7.5/html/index.html
libxo lives on github as:
https://github.com/Juniper/libxo
the latest release of libxo is available at:
https://github.com/Juniper/libxo/releases
π°οΈ HISTORY π°οΈ
the libxo library was added in FreeBSD 11.0.
β AUTHOR β
Phil Shafer
and that's the whole page bestie πβ¨π it's from the Debian crew, dated December 4, 2014, and it's filed under XO(1) in the General Commands Manual. go forth and emit formatted output, you absolute legend π«ΆπΈπ
π¦ where this page comes from
- epel 9: libxo 1.7.5-1.el9 Β· LicenseRef-Callaway-BSD
- fedora 43: libxo 1.7.5-2.fc43 Β· LicenseRef-Callaway-BSD
- fedora 43: libxo 1.7.5-2.fc43 Β· LicenseRef-Callaway-BSD
- fedora 44: libxo 1.7.5-3.fc44 Β· LicenseRef-Callaway-BSD
- fedora 44: libxo 1.7.5-3.fc44 Β· LicenseRef-Callaway-BSD
- nixpkgs unstable: libxo 1.7.5
- Copyright (c) 2014, Juniper Networks, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms