52 if(i.has_value() && !
options[*i].values.empty())
53 return options[*i].values.front();
67 "unknown command line option", option);
78 options[*i].values.push_back(value);
83 "unknown command line option", option);
103 if(i.has_value() && !
options[*i].values.empty())
104 return options[*i].values.front();
110 const std::string &option)
const
120 std::list<std::string>
123 std::list<std::string> separated_values;
128 separated_values.insert(
129 separated_values.end(), values.begin(), values.end());
132 return separated_values;
137 for(std::size_t i=0; i<
options.size(); i++)
141 return std::optional<std::size_t>();
146 for(std::size_t i=0; i<
options.size(); i++)
147 if(
options[i].optstring==option)
150 return std::optional<std::size_t>();
167 while(optstring[0] != 0)
172 optstring[0] !=
':',
"cmdlinet::parse: Invalid option string\n");
174 if(optstring[0] ==
'(')
178 option.
isset =
false;
181 for(optstring++; optstring[0] !=
')' && optstring[0] != 0; optstring++)
184 if(optstring[0] ==
')')
192 option.
isset =
false;
197 if(optstring[0] ==
':')
209 std::vector<std::string>
214 std::size_t distance;
215 std::string suggestion;
217 bool operator<(
const suggestiont &other)
const
219 return distance < other.distance;
223 auto argument_suggestions = std::vector<suggestiont>{};
228 for(
const auto &option :
options)
232 const auto long_name =
"--" + option.optstring;
233 if(
auto distance = argument_matcher.get_edit_distance(long_name))
235 argument_suggestions.push_back({distance.value(), long_name});
240 const auto short_name = std::string{
"-"} + option.optchar;
241 if(
auto distance = argument_matcher.get_edit_distance(short_name))
243 argument_suggestions.push_back({distance.value(), short_name});
248 auto final_suggestions = std::vector<std::string>{};
249 if(!argument_suggestions.empty())
253 auto min = std::min_element(
254 argument_suggestions.begin(), argument_suggestions.end());
256 min != argument_suggestions.end(),
257 "there is a minimum because it's not empty");
258 for(
auto const &suggestion : argument_suggestions)
260 if(suggestion.distance == min->distance)
262 final_suggestions.push_back(suggestion.suggestion);
266 return final_suggestions;
271 for(
int i = 1; i < argc; i++)
273 if(argv[i][0] !=
'-')
274 args.push_back(argv[i]);
277 std::optional<std::size_t> optnr;
279 if(argv[i][1] != 0 && argv[i][2] == 0)
281 else if(argv[i][1] ==
'-')
289 if(!optnr.has_value())
293 if(!optnr.has_value())
303 if(argv[i][2] == 0 ||
options[*optnr].islong)
308 if(argv[i][0] ==
'-' && argv[i][1] != 0)
310 options[*optnr].values.push_back(argv[i]);
313 options[*optnr].values.push_back(argv[i] + 2);
323 : command_line(command_line), index(index)
333 goto_next_valid_index();
347 while(index < command_line->
options.size() && !is_valid_index())
369 return index == other.
index;
376 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
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...