Skip to content

Commit 86baa33

Browse files
hannes-steffenhagen-diffblueHannes Steffenhagen
authored and
Hannes Steffenhagen
committed
Add some extra documentation to cmdlinet::parse
1 parent ca018f7 commit 86baa33

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

src/util/cmdline.h

+61
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,58 @@ Author: Daniel Kroening, [email protected]
2020
class cmdlinet
2121
{
2222
public:
23+
/// Parses a commandline according to a specification given in \p optstring.
24+
/// \param argc How many arguments there are.
25+
/// \param argv An array of C strings.
26+
/// The 0th element is assumed to be the name of the command as
27+
/// it was invoked (e.g. /usr/bin/cmake) and is ignored. It is
28+
/// further assumed the array holds \p argc+1 elements with the C
29+
/// string at index argc being a terminating null pointer.
30+
/// This argument is parsed based on \p optstring.
31+
/// \param optstring A specification of allowed command line options.
32+
/// This is a C string container any number of single
33+
/// characters other than '(', ')' or ':' signifying a
34+
/// "short" option consisting of just that character, or
35+
/// names consisting of any characters other than ')'
36+
/// surrounded by a matching pair of '(' and ')' signifying a
37+
/// "long" option with the name being the string between '('
38+
/// and ')', both of which can be optionally followed by a
39+
/// single ':' indicating that the option takes a argument,
40+
/// if not present it does not. arguments must be in the
41+
/// next array element in \p argv , except for short options
42+
/// whose argument may also be concatenated directly on them.
43+
///
44+
/// Option names in \p argv must start with either '-' or "--",
45+
/// no distinction between long and short options is made
46+
/// here, although it is customary to use only one '-' for
47+
/// short options and "--" for long options.
48+
///
49+
/// All options are optional, if some are required it is up
50+
/// to the user to check that they are present.
51+
///
52+
/// Examples:
53+
///
54+
/// argc = 4
55+
/// argv = `{"name", "-V", "--name", "CProver", nullptr}`
56+
/// opstring = `"V(version)(name):"`
57+
///
58+
/// here the argument to "name" would be "CProver", and
59+
/// "V" is a short option passed without arguments.
60+
///
61+
/// argc = 3
62+
/// argv = `{"other-name", "-fFilename", "--trace", nullptr}`
63+
/// optstring = `"f:(trace)(some-other-option):G"`
64+
///
65+
/// here the argument to option "f" would be "Filename",
66+
/// "trace" is a long option with no argument, and
67+
/// "some-other-option" and "G" are both allowed options that
68+
/// don’t appear on the commandline (with and without
69+
/// argument respectively).
70+
///
71+
/// \return true if there was an error while parsing argv, false otherwise. If
72+
/// this failed due to an unknown option name being in argv, the
73+
/// public variable cmdlinet::unknown_arg will be non-empty and
74+
/// contain the name of that option.
2375
virtual bool parse(int argc, const char **argv, const char *optstring);
2476

2577
std::string get_value(char option) const;
@@ -115,7 +167,16 @@ class cmdlinet
115167
{}
116168
};
117169

170+
/// Parses an optstring and writes the result to cmdlinet::options.
171+
/// It is considered a logic error to pass an invalid option string here.
172+
/// \see cmdlinet::parse(int,const char**,const char*)
173+
/// for details on the format of the optstring
118174
void parse_optstring(const char *optstring);
175+
176+
/// Parses a commandline according to a previously parsed optstring and
177+
/// writes the result to cmdlinet::options.
178+
/// \see cmdlinet::parse(int,const char**,const char*)
179+
/// for details the meaning of argc and argv
119180
bool parse_arguments(int argc, const char **argv);
120181

121182
std::vector<optiont> options;

0 commit comments

Comments
 (0)