XO(1)

πŸ“¦
version 1.7.5 Β· 2 versions
, in epel 9, fedora 43, fedora 44, nixpkgs unstable

✨ 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:

  • --close path β€” 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 πŸŽ€
  • --depth num β€” set the depth for pretty printing
  • --help β€” display help text
  • -H, --html β€” generate HTML output
  • -J, --json β€” generate JSON output
  • --leading-xpath path β€” 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 😭
  • --open path β€” open tags for the given path
  • -p, --pretty β€” make 'pretty' output (add indent, newlines)
  • --style style β€” 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
  • --wrap path β€” 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