27#if __has_include("defs.h")
39 OptParser (std::vector<const char*>& list);
42 OptParser (std::initializer_list<const char*> list);
54 int parse (
int argc,
const char*
const* argv,
int* stop = 0);
58 bool next (std::string& opt, std::string& optarg,
char sep =
'|');
61 bool next (std::string& opt, std::vector<std::string>& optarg);
66 int getopt (
const std::string& option, std::string& optarg,
char sep =
'|')
const;
69 int getopt (
const std::string& option, std::vector<std::string>& optarg)
const;
72 int getopt (
char option, std::string& optarg,
char sep =
'|')
const;
75 int getopt (
char option, std::vector<std::string>& optarg)
const;
80 bool hasopt (
const std::string& option)
const;
83 bool hasopt (
char option)
const;
90 const std::string
description (
size_t indent_size = 2)
const;
93 const std::string&
appname ()
const;
101 std::string arg_descr;
102 std::vector<std::string> arg;
106 std::vector<opt>::const_iterator find_option (
const std::string& opt)
const;
107 std::vector<opt>::const_iterator find_option (
char opt)
const;
108 void format_arg (std::string& str,
const opt& option,
char sep)
const;
110 std::vector<opt> optlist;
111 std::vector<opt> cmd;
112 std::vector<opt>::iterator nextop;
129 return find_option (option) != cmd.end ();
138 return find_option (option) != cmd.end ();
151 auto p = find_option (option);
168 auto p = find_option (option);
Command Line Parsing class.
Definition options.h:34
int getopt(const std::string &option, std::string &optarg, char sep='|') const
Definition options.cpp:447
const std::string synopsis() const
Return a nicely formatted syntax string containing all the options.
Definition options.cpp:471
OptParser()
Initialize parser.
Definition options.cpp:97
bool hasopt(const std::string &option) const
Definition options.h:127
const std::string description(size_t indent_size=2) const
Return options description.
Definition options.cpp:539
bool next(std::string &opt, std::string &optarg, char sep='|')
Definition options.cpp:396
void add_option(const char *descr)
Add a new option descriptor to the list of options.
Definition options.cpp:200
void set_options(std::vector< const char * > &list)
Set list of valid options.
Definition options.cpp:141
int parse(int argc, const char *const *argv, int *stop=0)
Parse a command line.
Definition options.cpp:242
const std::string & appname() const
Return program name.
Definition options.h:119