xref: /freebsd/contrib/libxo/libxo/xo_parse_args.3 (revision 325151a3)
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 LIBXO 3
12.Os
13.Sh NAME
14.Nm xo_parse_args , xo_set_program
15.Nd detect, parse, and remove arguments for libxo
16.Sh LIBRARY
17.Lb libxo
18.Sh SYNOPSIS
19.In libxo/xo.h
20.Ft int
21.Fn xo_parse_args "int argc" "char **argv"
22.Ft int
23.Fn xo_set_program "const char *name"
24.Sh DESCRIPTION
25The
26.Fn xo_parse_args
27function is used to process command-line arguments.
28.Nm libxo
29specific
30options are processed and removed
31from the argument list so the calling application does not
32need to process them.
33If successful, a new value for argc is returned.
34On failure, a message it emitted and -1 is returned.
35.Bd -literal -offset indent
36    argc = xo_parse_args(argc, argv);
37    if (argc < 0)
38        exit(EXIT_FAILURE);
39.Ed
40.Pp
41Following the call to
42.Fn xo_parse_args ,
43the application can process the remaining arguments in a normal manner.
44.Pp
45.Nm libxo
46uses command line options to trigger rendering behavior.
47The following options are recognised:
48.Pp
49.Bl -tag -width "--libxo"
50.It
51\-\^\-libxo <options>
52.It
53\-\^\-libxo=<options>
54.It
55\-\^\-libxo:<brief-options>
56.El
57.Pp
58Options is a comma-separated list of tokens that correspond to output
59styles, flags, or features:
60.Pp
61.Bl -tag -width "12345678"
62.It Sy "Token   Action"
63.It Dv dtrt
64Enable "Do The Right Thing" mode
65.It Dv html
66Emit HTML output
67.It Dv indent=xx
68Set the indentation level
69.It Dv info
70Add info attributes (HTML)
71.It Dv json
72Emit JSON output
73.It Dv keys
74Emit the key attribute for keys (XML)
75.It Dv log-gettext
76Log (via stderr) each
77.Xr gettext 3
78string lookup
79.It Dv log-syslog
80Log (via stderr) each syslog message (via
81.Xr xo_syslog 3 )
82.If Dv no-humanize
83Ignore the {h:} modifier (TEXT, HTML)
84.It Dv no-locale
85Do not initialize the locale setting
86.It Dv no-top
87Do not emit a top set of braces (JSON)
88.It Dv not-first
89Pretend the 1st output item was not 1st (JSON)
90.It Dv pretty
91Emit pretty-printed output
92.It Dv text
93Emit TEXT output
94.If Dv underscores
95Replace XML-friendly "-"s with JSON friendly "_"s e
96.It Dv units
97Add the 'units' (XML) or 'data-units (HTML) attribute
98.It Dv warn
99Emit warnings when libxo detects bad calls
100.It Dv warn-xml
101Emit warnings in XML
102.It Dv xml
103Emit XML output
104.It Dv xpath
105Add XPath expressions (HTML)
106.El
107.Pp
108The
109.Dq brief-options
110are single letter commands, designed for those with
111too little patience to use real tokens.
112No comma separator is used.
113.Bl -column "i<num>"
114.It Sy "Token   Action"
115.It "H      " "Enable HTML output (XO_STYLE_HTML)"
116.It "I      " "Enable info output (XOF_INFO)"
117.It "i<num> " "Indent by <number>"
118.It "J      " "Enable JSON output (XO_STYLE_JSON)"
119.It "P      " "Enable pretty-printed output (XOF_PRETTY)"
120.It "T      " "Enable text output (XO_STYLE_TEXT)"
121.It "W      " "Enable warnings (XOF_WARN)"
122.It "X      " "Enable XML output (XO_STYLE_XML)"
123.It "x      " "Enable XPath data (XOF_XPATH)"
124.El
125.Pp
126The
127.Fn xo_set_program
128function sets name of the program as reported by
129functions like
130.Fn xo_failure ,
131.Fn xo_warn ,
132.Fn xo_err ,
133etc.
134The program name is initialized by
135.Fn xo_parse_args ,
136but subsequent calls to
137.Fn xo_set_program
138can override this value.
139.Pp
140Note that the value is not copied, so the memory passed to
141.Fn xo_set_program
142(and
143.Fn xo_parse_args )
144must be maintained by the caller.
145.Pp
146.Sh SEE ALSO
147.Xr xo_emit 3 ,
148.Xr libxo 3
149