1ZARGS(3) CZMQ Manual ZARGS(3)
2
3
4
6 zargs - Class for Platform independent command line argument parsing
7 helpers
8
10 // This is a draft class, and may change without notice. It is disabled in
11 // stable builds by default. If you use this in applications, please ask
12 // for it to be pushed to stable state. Use --enable-drafts to enable.
13 #ifdef CZMQ_BUILD_DRAFT_API
14 // *** Draft method, for development use, may change without warning ***
15 // Create a new zargs from command line arguments.
16 CZMQ_EXPORT zargs_t *
17 zargs_new (int argc, char **argv);
18
19 // *** Draft method, for development use, may change without warning ***
20 // Destroy zargs instance.
21 CZMQ_EXPORT void
22 zargs_destroy (zargs_t **self_p);
23
24 // *** Draft method, for development use, may change without warning ***
25 // Return program name (argv[0])
26 CZMQ_EXPORT const char *
27 zargs_progname (zargs_t *self);
28
29 // *** Draft method, for development use, may change without warning ***
30 // Return number of positional arguments
31 CZMQ_EXPORT size_t
32 zargs_arguments (zargs_t *self);
33
34 // *** Draft method, for development use, may change without warning ***
35 // Return first positional argument or NULL
36 CZMQ_EXPORT const char *
37 zargs_first (zargs_t *self);
38
39 // *** Draft method, for development use, may change without warning ***
40 // Return next positional argument or NULL
41 CZMQ_EXPORT const char *
42 zargs_next (zargs_t *self);
43
44 // *** Draft method, for development use, may change without warning ***
45 // Return first named parameter value, or NULL if there are no named
46 // parameters, or value for which zargs_param_empty (arg) returns true.
47 CZMQ_EXPORT const char *
48 zargs_param_first (zargs_t *self);
49
50 // *** Draft method, for development use, may change without warning ***
51 // Return next named parameter value, or NULL if there are no named
52 // parameters, or value for which zargs_param_empty (arg) returns true.
53 CZMQ_EXPORT const char *
54 zargs_param_next (zargs_t *self);
55
56 // *** Draft method, for development use, may change without warning ***
57 // Return current parameter name, or NULL if there are no named
58 // parameters.
59 CZMQ_EXPORT const char *
60 zargs_param_name (zargs_t *self);
61
62 // *** Draft method, for development use, may change without warning ***
63 // Return value of named parameter, NULL if no given parameter has
64 // been specified, or special value for wich zargs_param_empty ()
65 // returns true.
66 CZMQ_EXPORT const char *
67 zargs_param_lookup (zargs_t *self, const char *keys);
68
69 // *** Draft method, for development use, may change without warning ***
70 // Return value of named parameter(s), NULL if no given parameter has
71 // been specified, or special value for wich zargs_param_empty ()
72 // returns true.
73 CZMQ_EXPORT const char *
74 zargs_param_lookupx (zargs_t *self, const char *keys, ...);
75
76 // *** Draft method, for development use, may change without warning ***
77 // Returns true if there are --help -h arguments
78 CZMQ_EXPORT bool
79 zargs_has_help (zargs_t *self);
80
81 // *** Draft method, for development use, may change without warning ***
82 // Returns true if parameter did not have a value
83 CZMQ_EXPORT bool
84 zargs_param_empty (const char *arg);
85
86 // *** Draft method, for development use, may change without warning ***
87 // Print an instance of zargs.
88 CZMQ_EXPORT void
89 zargs_print (zargs_t *self);
90
91 // *** Draft method, for development use, may change without warning ***
92 // Self test of this class.
93 CZMQ_EXPORT void
94 zargs_test (bool verbose);
95
96 #endif // CZMQ_BUILD_DRAFT_API
97 Please add '@interface' section in './../src/zargs.c'.
98
100 zargs - Platform independent command line argument parsing helpers
101
102 Platform independent command line argument parsing helpers
103
104 There are two kind of elements provided by this class foo
105 --named-parameter --parameter with_value positional arguments -a
106 gain-parameter zargs keeps poision only for arguments, parameters are
107 to be accessed like hash.
108
109 It DOES: * provide easy to use CLASS compatible API for accessing argv
110 * is platform independent * provide getopt_long style — argument, which
111 delimits parameters from arguments * makes parameters positon
112 independent
113
114 It does NOT * change argv * provide a "declarative" way to define
115 command line interface
116
117 In future it SHALL * hide several formats of command line to one
118 (-Idir, --include=dir, --include dir are the same from API pov)
119
120 Please add @discuss section in ./../src/zargs.c.
121
123 From zargs_test method.
124
125 // Simple create/destroy test
126
127 char *argv1[] = {"progname", "--named1", "-n1", "val1", "positional1", "--with", "value", "--with2=value2", "-W3value3", "--", "--thisis", "considered", "positional", NULL};
128
129 zargs_t *self = zargs_new (13, argv1);
130 assert (self);
131
132 assert (streq (zargs_progname (self), "progname"));
133 assert (streq (zargs_first (self), "positional1"));
134 assert (streq (zargs_next (self), "--thisis"));
135 assert (streq (zargs_next (self), "considered"));
136 assert (streq (zargs_next (self), "positional"));
137 assert (!zargs_next (self));
138
139 assert (zargs_param_empty (zargs_param_lookup (self, "--named1")));
140 assert (!zargs_param_empty (zargs_param_lookup (self, "-n1")));
141 assert (streq (zargs_param_lookupx (self, "--not at all", "-n1", NULL), "val1"));
142 // TODO: this does not look like an easy hack w/o allocating extra memory
143 // ???
144 //assert (streq (zargs_param_lookup (self, "--with", NULL), "value2"));
145
146 zargs_destroy (&self);
147
148
150 The czmq manual was written by the authors in the AUTHORS file.
151
153 Main web site:
154
155 Report bugs to the email <zeromq-dev@lists.zeromq.org[1]>
156
158 Copyright (c) the Contributors as noted in the AUTHORS file. This file
159 is part of CZMQ, the high-level C binding for 0MQ:
160 http://czmq.zeromq.org. This Source Code Form is subject to the terms
161 of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
162 distributed with this file, You can obtain one at
163 http://mozilla.org/MPL/2.0/. LICENSE included with the czmq
164 distribution.
165
167 1. zeromq-dev@lists.zeromq.org
168 mailto:zeromq-dev@lists.zeromq.org
169
170
171
172CZMQ 4.1.1 07/24/2019 ZARGS(3)