1.\" # 2.\" # Copyright (c) 2014, Juniper Networks, Inc. 3.\" # All rights reserved. 4.\" # This SOFTWARE is licensed under the LICENSE provided in the 5.\" # ../Copyright file. By downloading, installing, copying, or 6.\" # using the SOFTWARE, you agree to be bound by the terms of that 7.\" # LICENSE. 8.\" # Phil Shafer, July 2014 9.\" 10.Dd December 4, 2014 11.Dt XO 1 12.Os 13.Sh NAME 14.Nm xo 15.Nd emit formatted output based on format string and arguments 16.Sh SYNOPSIS 17.Nm 18.Op Fl options 19.Op Ar argument... 20.Sh DESCRIPTION 21The 22.Nm 23utility allows command line access to the functionality of 24the 25.Nm libxo 26library. 27Using 28.Nm , 29shell scripts can emit 30.Em XML , 31.Em JSON , 32or 33.Em HTML 34using the same commands that emit text output. 35.Pp 36.Bl -tag -width "12345678901234567" 37.It Fl "-close <path>" 38Close tags for the given path 39.It Fl "-depth <num>" 40Set the depth for pretty printing 41.It Fl "-help" 42Display this help text 43.It Fl "-html OR -H" 44Generate HTML output 45.It Fl "-json OR -J" 46Generate JSON output 47.It Fl "-leading-xpath <path>" 48Add a prefix to generated XPaths (HTML) 49.It Fl "-open <path>" 50Open tags for the given path 51.It Fl "-pretty OR -p" 52Make 'pretty' output (add indent, newlines) 53.It Fl "-style <style>" 54Generate given style (xml, json, text, html) 55.It Fl "-text OR -T" 56Generate text output (the default style) 57.It Fl "-version" 58Display version information 59.It Fl "-warn OR -W" 60Display warnings in text on stderr 61.It Fl "-warn-xml" 62Display warnings in xml on stdout 63.It Fl "-wrap <path>" 64Wrap output in a set of containers 65.It Fl "-xml OR -X" 66Generate XML output 67.It Fl "-xpath" 68Add XPath data to HTML output 69.El 70.Pp 71The 72.Nm 73utility accepts a format string suitable for 74.Xr xo_emit 3 75and a set of zero or more arguments used to supply data for that string. 76.Bd -literal -offset indent 77 xo "The {k:name} weighs {:weight/%d} pounds.\n" fish 6 78 79 TEXT: 80 The fish weighs 6 pounds. 81 XML: 82 <name>fish</name> 83 <weight>6</weight> 84 JSON: 85 "name": "fish", 86 "weight": 6 87 HTML: 88 <div class="line"> 89 <div class="text">The </div> 90 <div class="data" data-tag="name">fish</div> 91 <div class="text"> weighs </div> 92 <div class="data" data-tag="weight">6</div> 93 <div class="text"> pounds.</div> 94 </div> 95.Ed 96.Pp 97The 98.Fl "-wrap <path>" 99option can be used to wrap emitted content in a 100specific hierarchy. 101The path is a set of hierarchical names separated 102by the '/' character. 103.Bd -literal -offset indent 104 xo --wrap top/a/b/c '{:tag}' value 105 106 XML: 107 <top> 108 <a> 109 <b> 110 <c> 111 <tag>value</tag> 112 </c> 113 </b> 114 </a> 115 </top> 116 JSON: 117 "top": { 118 "a": { 119 "b": { 120 "c": { 121 "tag": "value" 122 } 123 } 124 } 125 } 126.Ed 127.Pp 128The 129.Fl "\-open <path>" 130and 131.Fl "\-close <path>" 132can be used to emit 133hierarchical information without the matching close and open 134tag. 135This allows a shell script to emit open tags, data, and 136then close tags. 137The 138.Fl \-depth 139option may be used to set the 140depth for indentation. 141The 142.Fl "\-leading-xpath" 143may be used to 144prepend data to the XPath values used for HTML output style. 145.Bd -literal -offset indent 146 #!/bin/sh 147 xo --open top/data 148 xo --depth 2 '{tag}' value 149 xo --close top/data 150 XML: 151 <top> 152 <data> 153 <tag>value</tag> 154 </data> 155 </top> 156 JSON: 157 "top": { 158 "data": { 159 "tag": "value" 160 } 161 } 162.Ed 163.Sh EXAMPLE 164.Bd -literal 165 % xo 'The {:product} is {:status}\n' stereo "in route" 166 The stereo is in route 167 % xo -p -X 'The {:product} is {:status}\n' stereo "in route" 168 <product>stereo</product> 169 <status>in route</status> 170.Ed 171.Sh ADDITIONAL DOCUMENTATION 172Complete documentation can be found on github: 173.Bd -literal -offset indent 174http://juniper.github.io/libxo/libxo-manual.html 175.Ed 176.Pp 177.Nm libxo 178lives on github as: 179.Bd -literal -offset indent 180https://github.com/Juniper/libxo 181.Ed 182.Pp 183The latest release of 184.Nm libxo 185is available at: 186.Bd -literal -offset indent 187https://github.com/Juniper/libxo/releases 188.Ed 189.Sh SEE ALSO 190.Xr libxo 3 , 191.Xr xo_emit 3 192.Sh HISTORY 193The 194.Nm libxo 195library was added in 196.Fx 11.0 . 197.Sh AUTHOR 198Phil Shafer 199