1ZARGS(3)                          CZMQ Manual                         ZARGS(3)
2
3
4

NAME

6       zargs - Class for Platform independent command line argument parsing
7       helpers
8

SYNOPSIS

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 parameters.
58       CZMQ_EXPORT const char *
59           zargs_param_name (zargs_t *self);
60
61       //  *** Draft method, for development use, may change without warning ***
62       //  Return value of named parameter or NULL is it has no value (or was not specified)
63       CZMQ_EXPORT const char *
64           zargs_get (zargs_t *self, const char *name);
65
66       //  *** Draft method, for development use, may change without warning ***
67       //  Return value of one of parameter(s) or NULL is it has no value (or was not specified)
68       CZMQ_EXPORT const char *
69           zargs_getx (zargs_t *self, const char *name, ...);
70
71       //  *** Draft method, for development use, may change without warning ***
72       //  Returns true if named parameter was specified on command line
73       CZMQ_EXPORT bool
74           zargs_has (zargs_t *self, const char *name);
75
76       //  *** Draft method, for development use, may change without warning ***
77       //  Returns true if named parameter(s) was specified on command line
78       CZMQ_EXPORT bool
79           zargs_hasx (zargs_t *self, const char *name, ...);
80
81       //  *** Draft method, for development use, may change without warning ***
82       //  Print an instance of zargs.
83       CZMQ_EXPORT void
84           zargs_print (zargs_t *self);
85
86       //  *** Draft method, for development use, may change without warning ***
87       //  Self test of this class.
88       CZMQ_EXPORT void
89           zargs_test (bool verbose);
90
91       #endif // CZMQ_BUILD_DRAFT_API
92       Please add '@interface' section in './../src/zargs.c'.
93

DESCRIPTION

95       zargs - Platform independent command line argument parsing helpers
96
97       Platform independent command line argument parsing helpers
98
99       There are two kind of elements provided by this class foo
100       --named-parameter --parameter with_value positional arguments -a
101       gain-parameter zargs keeps poision only for arguments, parameters are
102       to be accessed like hash.
103
104       It DOES: * provide easy to use CLASS compatible API for accessing argv
105       * is platform independent * provide getopt_long style — argument, which
106       delimits parameters from arguments * makes parameters positon
107       independent
108
109       It does NOT * change argv * provide a "declarative" way to define
110       command line interface
111
112       In future it SHALL * hide several formats of command line to one
113       (-Idir, --include=dir, --include dir are the same from API pov)
114
115       Please add @discuss section in ./../src/zargs.c.
116

EXAMPLE

118       From zargs_test method.
119
120           //  Simple create/destroy test
121
122           char *argv1[] = {"progname", "--named1", "-n1", "val1", "positional1", "--with", "value", "--with2=value2", "-W3value3", "--", "--thisis", "considered", "positional", NULL};
123
124           zargs_t *self = zargs_new (13, argv1);
125           assert (self);
126
127           assert (streq (zargs_progname (self), "progname"));
128           assert (streq (zargs_first (self), "positional1"));
129           assert (streq (zargs_next (self), "--thisis"));
130           assert (streq (zargs_next (self), "considered"));
131           assert (streq (zargs_next (self), "positional"));
132           assert (!zargs_next (self));
133
134           assert (zargs_has (self, "--named1"));
135           assert (zargs_has (self, "-n1"));
136           assert (!zargs_has (self, "--not at all"));
137
138           assert (!(zargs_get (self, "--named1")));
139           assert (streq (zargs_get (self, "-n1"), "val1"));
140
141           // common usages - test for -h/--help
142           bool has_help = zargs_hasx (self, "--help", "-h", NULL);
143           assert (!has_help);
144
145           zargs_destroy (&self);
146
147

AUTHORS

149       The czmq manual was written by the authors in the AUTHORS file.
150

RESOURCES

152       Main web site:
153
154       Report bugs to the email <zeromq-dev@lists.zeromq.org[1]>
155
157       Copyright (c) the Contributors as noted in the AUTHORS file. This file
158       is part of CZMQ, the high-level C binding for 0MQ:
159       http://czmq.zeromq.org. This Source Code Form is subject to the terms
160       of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
161       distributed with this file, You can obtain one at
162       http://mozilla.org/MPL/2.0/. LICENSE included with the czmq
163       distribution.
164

NOTES

166        1. zeromq-dev@lists.zeromq.org
167           mailto:zeromq-dev@lists.zeromq.org
168
169
170
171CZMQ 4.2.0                        01/28/2020                          ZARGS(3)
Impressum