57 if(i.has_value() && !
options[*i].values.empty())
58 return options[*i].values.front();
72 "unknown command line option", option);
83 options[*i].values.push_back(value);
88 "unknown command line option", option);
113 if(i.has_value() && !
options[*i].values.empty())
114 return options[*i].values.front();
120 const std::string &option)
const
130 std::list<std::string>
133 std::list<std::string> separated_values;
138 separated_values.insert(
139 separated_values.end(), values.begin(), values.end());
142 return separated_values;
147 for(std::size_t i=0; i<
options.size(); i++)
151 return std::optional<std::size_t>();
156 for(std::size_t i=0; i<
options.size(); i++)
157 if(
options[i].optstring==option)
160 return std::optional<std::size_t>();
177 while(optstring[0] != 0)
182 optstring[0] !=
':',
"cmdlinet::parse: Invalid option string\n");
184 if(optstring[0] ==
'(')
188 option.
isset =
false;
191 for(optstring++; optstring[0] !=
')' && optstring[0] != 0; optstring++)
194 if(optstring[0] ==
')')
202 option.
isset =
false;
207 if(optstring[0] ==
':')
219 std::vector<std::string>
224 std::size_t distance;
225 std::string suggestion;
227 bool operator<(
const suggestiont &other)
const
229 return distance < other.distance;
233 auto argument_suggestions = std::vector<suggestiont>{};
238 for(
const auto &option :
options)
242 const auto long_name =
"--" + option.optstring;
243 if(
auto distance = argument_matcher.get_edit_distance(long_name))
245 argument_suggestions.push_back({distance.value(), long_name});
250 const auto short_name = std::string{
"-"} + option.optchar;
251 if(
auto distance = argument_matcher.get_edit_distance(short_name))
253 argument_suggestions.push_back({distance.value(), short_name});
258 auto final_suggestions = std::vector<std::string>{};
259 if(!argument_suggestions.empty())
263 auto min = std::min_element(
264 argument_suggestions.begin(), argument_suggestions.end());
266 min != argument_suggestions.end(),
267 "there is a minimum because it's not empty");
268 for(
auto const &suggestion : argument_suggestions)
270 if(suggestion.distance == min->distance)
272 final_suggestions.push_back(suggestion.suggestion);
276 return final_suggestions;
281 for(
int i = 1; i < argc; i++)
283 if(argv[i][0] !=
'-')
284 args.push_back(argv[i]);
287 std::optional<std::size_t> optnr;
289 if(argv[i][1] != 0 && argv[i][2] == 0)
291 else if(argv[i][1] ==
'-')
299 if(!optnr.has_value())
303 if(!optnr.has_value())
313 if(argv[i][2] == 0 ||
options[*optnr].islong)
318 if(argv[i][0] ==
'-' && argv[i][1] != 0)
320 options[*optnr].values.push_back(argv[i]);
323 options[*optnr].values.push_back(argv[i] + 2);
333 : command_line(command_line), index(index)
343 goto_next_valid_index();
357 while(index < command_line->
options.size() && !is_valid_index())
379 return index == other.
index;
386 return index != other.
index;
std::string get_value(char option) const
virtual bool isset(char option) const
std::list< std::string > get_comma_separated_values(const char *option) const
Collect all occurrences of option option and split their values on each comma, merging them into a si...
std::optional< std::size_t > getoptnr(char option) const
std::optional< std::string > value_opt(char option) const
bool parse_arguments(int argc, const char **argv)
Parses a commandline according to a previously parsed optstring and writes the result to cmdlinet::op...
std::vector< optiont > options
virtual void set(const std::string &option, bool value=true)
Set option option to value, or true if the value is omitted.
virtual bool parse(int argc, const char **argv, const char *optstring)
Parses a commandline according to a specification given in optstring.
std::vector< std::string > get_argument_suggestions(const std::string &unknown_argument)
void parse_optstring(const char *optstring)
Parses an optstring and writes the result to cmdlinet::options.
option_namest option_names() const
Pseudo-object that can be used to iterate over options in this cmdlinet (should not outlive this)
const std::list< std::string > & get_values(const std::string &option) const
Thrown when users pass incorrect command line arguments, for example passing no files to analysis or ...
static std::list< std::string > immutable_empty_list
bool operator<(const reaching_definitiont &a, const reaching_definitiont &b)
In order to use instances of this structure as keys in ordered containers, such as std::map,...
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
#define PRECONDITION(CONDITION)
void split_string(const std::string &s, char delim, std::vector< std::string > &result, bool strip, bool remove_empty)
bool is_valid_index() const
const std::string & operator*()
const cmdlinet * command_line
bool operator==(const option_names_iteratort &other)
void goto_next_valid_index()
bool operator!=(const option_names_iteratort &other)
option_names_iteratort()=default
option_names_iteratort & operator++()
option_names_iteratort end()
option_names_iteratort begin()
option_namest(const cmdlinet &command_line)
const cmdlinet & command_line
Simple automaton that can detect whether a string can be transformed into another with a limited numb...