#include <CommandLine.h>
Definition at line 20 of file CommandLine.h.
◆ OptionPossibility
Value/name/description tuples. If [1] is the value on the commandline for an option, we'd set the value for the associated Option to [0].
Definition at line 30 of file CommandLine.h.
◆ PossibilityDescription
◆ PossibilityDescriptions
◆ OptionBase() [1/2]
Definition at line 33 of file CommandLine.h.
OptionBase(std::string name, std::string description)
◆ OptionBase() [2/2]
Definition at line 38 of file CommandLine.h.
41 assert(
name[0] !=
'-' &&
"OptionBase: name starts with '-'");
PossibilityDescriptions possibilityDescriptions
For when we have possibilities like in an OptionMap.
static std::map< std::string, OptionBase * > & getOptionsMap(void)
static bool isHelpName(const std::string name)
Returns whether name is one of the reserved help options.
◆ buildUsage()
Sets the usage member to a usage string, built from the static list of options. argv0 is argv[0] and callFormat is how the command should be used, minus the command name (e.g. "[options] <input-bitcode...>".
Definition at line 174 of file CommandLine.h.
179 unsigned longest = 0;
180 for (
const std::pair<std::string, OptionBase *> nopt :
getOptionsMap())
191 if (
name.length() > longest) longest =
name.length();
197 if (possibility.length() + 3 > longest) longest = possibility.length() + 3;
201 std::stringstream ss;
205 ss <<
"USAGE:" << std::endl;
206 ss <<
" " << argv0 <<
" " << callFormat << std::endl;
209 ss <<
"OPTIONS:" << std::endl;
212 std::unordered_set<const OptionBase *> handled;
213 for (
const std::pair<std::string, OptionBase *> nopt :
getOptionsMap())
217 if (handled.find(option) != handled.end())
continue;
218 handled.insert(option);
231 ss <<
" -" << possibility <<
std::string(longest - possibility.length() + 2,
' ');
249 ss <<
" =" << possibility <<
std::string(longest - possibility.length() + 2,
' ');
257 ss <<
" -help" <<
std::string(longest - 4 + 2,
' ') <<
"- show usage and exit" << std::endl;
258 ss <<
" -h" <<
std::string(longest - 1 + 2,
' ') <<
"- show usage and exit" << std::endl;
262 ss <<
"Note: for boolean options, -name true and -name false are invalid." << std::endl;
263 ss <<
" Use -name, -name=true, or -name=false." << std::endl;
std::pair< std::string, std::string > PossibilityDescription
Name/description pairs.
virtual bool isMultiple(void) const
Whether this option is an OptionMultiple.
◆ canSet()
virtual bool OptionBase::canSet |
( |
void |
| ) |
const |
|
protectedpure virtual |
Can this option be set?
Implemented in OptionMultiple< T >, OptionMultiple< PointerAnalysis::PTATY >, OptionMultiple< WPAPass::AliasCheckRule >, OptionMap< T >, OptionMap< PointsTo::Type >, OptionMap< SVF::NodeIDAllocator::Strategy >, OptionMap< BVDataPTAImpl::PTBackingType >, OptionMap< enum hclust_fast_methods >, OptionMap< enum PTAStat::ClockType >, OptionMap< MemSSA::MemPartition >, Option< T >, Option< std::string >, Option< u32_t >, and Option< bool >.
◆ extractPossibilityDescriptions()
Definition at line 294 of file CommandLine.h.
297 for (
const OptionPossibility<T> &op : possibilities)
std::vector< std::pair< std::string, std::string > > PossibilityDescriptions
◆ getOption()
Find option based on name in options map. Returns nullptr if not found.
Definition at line 269 of file CommandLine.h.
273 else return optIt->second;
◆ getOptionsMap()
Not unordered map so we can have sorted names when building the usage string. Map of option names to their object.
Definition at line 307 of file CommandLine.h.
310 static std::map<std::string, OptionBase *> options;
◆ isBool()
virtual bool OptionBase::isBool |
( |
void |
| ) |
const |
|
inlineprotectedvirtual |
◆ isHelpName()
static bool OptionBase::isHelpName |
( |
const std::string |
name | ) |
|
|
inlinestaticprivate |
Returns whether name is one of the reserved help options.
Definition at line 285 of file CommandLine.h.
287 static std::vector<std::string> helpNames = {
"help",
"h",
"-help"};
288 return std::find(helpNames.begin(), helpNames.end(),
name) != helpNames.end();
◆ isMultiple()
virtual bool OptionBase::isMultiple |
( |
void |
| ) |
const |
|
inlineprotectedvirtual |
◆ parseAndSetValue()
virtual bool OptionBase::parseAndSetValue |
( |
const std::string |
value | ) |
|
|
protectedpure virtual |
From a given string, set the value of this option.
Implemented in OptionMultiple< T >, OptionMultiple< PointerAnalysis::PTATY >, OptionMultiple< WPAPass::AliasCheckRule >, OptionMap< T >, OptionMap< PointsTo::Type >, OptionMap< SVF::NodeIDAllocator::Strategy >, OptionMap< BVDataPTAImpl::PTBackingType >, OptionMap< enum hclust_fast_methods >, OptionMap< enum PTAStat::ClockType >, OptionMap< MemSSA::MemPartition >, Option< T >, Option< std::string >, Option< u32_t >, and Option< bool >.
◆ parseOptions()
Parse all constructed OptionBase children, returning positional arguments in the order they appeared.
Definition at line 75 of file CommandLine.h.
79 std::vector<std::string> positionalArguments;
81 for (
int i = 1; i < argc; ++i)
84 if (arg.empty())
continue;
89 positionalArguments.push_back(arg);
100 size_t equalsSign = arg.find(
'=');
101 if (equalsSign != std::string::npos)
104 argName = arg.substr(0, equalsSign);
110 std::cerr <<
"Unknown option: " << argName << std::endl;
114 argValue = arg.substr(equalsSign + 1);
124 std::cerr <<
"Unknown option: " << argName << std::endl;
140 else if (i + 1 < argc)
148 std::cerr <<
"Expected value for: " << argName << std::endl;
155 std::cerr <<
"Unable to set: " << argName <<
"; check for duplicates" << std::endl;
162 std::cerr <<
"Bad value for: " << argName << std::endl;
167 return positionalArguments;
virtual bool canSet(void) const =0
Can this option be set?
static std::string buildUsage(const std::string description, const std::string argv0, const std::string callFormat)
static OptionBase * getOption(const std::string optName)
Find option based on name in options map. Returns nullptr if not found.
static void usageAndExit(const std::string usage, bool error)
Print usage and exit. If error is set, print to stderr and exits with code 1.
virtual bool isBool(void) const
virtual bool parseAndSetValue(const std::string value)=0
From a given string, set the value of this option.
◆ usageAndExit()
static void OptionBase::usageAndExit |
( |
const std::string |
usage, |
|
|
bool |
error |
|
) |
| |
|
inlinestaticprivate |
Print usage and exit. If error is set, print to stderr and exits with code 1.
Definition at line 277 of file CommandLine.h.
279 if (
error) std::cerr << usage;
280 else std::cout << usage;
281 std::exit(
error ? 1 : 0);
◆ description
◆ name
◆ possibilityDescriptions
The documentation for this class was generated from the following file: