-
Notifications
You must be signed in to change notification settings - Fork 277
Split up the two parts of cmdlinet::parse into separate functions #5462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tautschnig
merged 3 commits into
diffblue:develop
from
hannes-steffenhagen-diffblue:refactor/split-up-cmdline-parse
Jan 18, 2021
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,58 @@ Author: Daniel Kroening, [email protected] | |
class cmdlinet | ||
{ | ||
public: | ||
/// Parses a commandline according to a specification given in \p optstring. | ||
/// \param argc How many arguments there are. | ||
/// \param argv An array of C strings. | ||
/// The 0th element is assumed to be the name of the command as | ||
/// it was invoked (e.g. /usr/bin/cmake) and is ignored. It is | ||
/// further assumed the array holds \p argc+1 elements with the C | ||
/// string at index argc being a terminating null pointer. | ||
/// This argument is parsed based on \p optstring. | ||
/// \param optstring A specification of allowed command line options. | ||
/// This is a C string container any number of single | ||
/// characters other than '(', ')' or ':' signifying a | ||
/// "short" option consisting of just that character, or | ||
/// names consisting of any characters other than ')' | ||
/// surrounded by a matching pair of '(' and ')' signifying a | ||
/// "long" option with the name being the string between '(' | ||
/// and ')', both of which can be optionally followed by a | ||
/// single ':' indicating that the option takes a argument, | ||
/// if not present it does not. arguments must be in the | ||
/// next array element in \p argv , except for short options | ||
/// whose argument may also be concatenated directly on them. | ||
/// | ||
/// Option names in \p argv must start with either '-' or "--", | ||
/// no distinction between long and short options is made | ||
/// here, although it is customary to use only one '-' for | ||
/// short options and "--" for long options. | ||
/// | ||
/// All options are optional, if some are required it is up | ||
/// to the user to check that they are present. | ||
/// | ||
/// Examples: | ||
/// | ||
/// argc = 4 | ||
/// argv = `{"name", "-V", "--name", "CProver", nullptr}` | ||
/// opstring = `"V(version)(name):"` | ||
/// | ||
/// here the argument to "name" would be "CProver", and | ||
/// "V" is a short option passed without arguments. | ||
/// | ||
/// argc = 3 | ||
/// argv = `{"other-name", "-fFilename", "--trace", nullptr}` | ||
/// optstring = `"f:(trace)(some-other-option):G"` | ||
/// | ||
/// here the argument to option "f" would be "Filename", | ||
/// "trace" is a long option with no argument, and | ||
/// "some-other-option" and "G" are both allowed options that | ||
/// don’t appear on the commandline (with and without | ||
/// argument respectively). | ||
/// | ||
/// \return true if there was an error while parsing argv, false otherwise. If | ||
/// this failed due to an unknown option name being in argv, the | ||
/// public variable cmdlinet::unknown_arg will be non-empty and | ||
/// contain the name of that option. | ||
virtual bool parse(int argc, const char **argv, const char *optstring); | ||
|
||
std::string get_value(char option) const; | ||
|
@@ -115,6 +167,18 @@ class cmdlinet | |
{} | ||
}; | ||
|
||
/// Parses an optstring and writes the result to cmdlinet::options. | ||
/// It is considered a logic error to pass an invalid option string here. | ||
/// \see cmdlinet::parse(int,const char**,const char*) | ||
/// for details on the format of the optstring | ||
void parse_optstring(const char *optstring); | ||
thomasspriggs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// Parses a commandline according to a previously parsed optstring and | ||
/// writes the result to cmdlinet::options. | ||
/// \see cmdlinet::parse(int,const char**,const char*) | ||
/// for details the meaning of argc and argv | ||
bool parse_arguments(int argc, const char **argv); | ||
thomasspriggs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
std::vector<optiont> options; | ||
|
||
optionalt<std::size_t> getoptnr(char option) const; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ container -> containing