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