本文整理汇总了C++中Options::args方法的典型用法代码示例。如果您正苦于以下问题:C++ Options::args方法的具体用法?C++ Options::args怎么用?C++ Options::args使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Options
的用法示例。
在下文中一共展示了Options::args方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Help
int
main(int argc, char **argv)
{
std::vector<std::string> args = std::vector<std::string>(argv + 1, argv + argc);
/*
* Parse out the options, or print help & exit.
*/
Options options;
std::pair<bool, std::string> result = libutil::Options::Parse<Options>(&options, args);
if (!result.first) {
return Help(result.second);
}
/*
* Handle the basic options that don't need SDKs.
*/
if (options.tool().empty()) {
if (options.help()) {
return Help();
} else if (options.version()) {
return Version();
}
}
/*
* Parse fallback options from the environment.
*/
std::string toolchainsInput = options.toolchain();
if (toolchainsInput.empty()) {
if (char const *toolchains = getenv("TOOLCHAINS")) {
toolchainsInput = std::string(toolchains);
}
}
std::string SDK = options.SDK();
if (SDK.empty()) {
if (char const *sdkroot = getenv("SDKROOT")) {
SDK = std::string(sdkroot);
} else {
/* Default SDK. */
SDK = "macosx";
}
}
bool verbose = options.verbose() || getenv("xcrun_verbose") != NULL;
bool log = options.log() || getenv("xcrun_log") != NULL;
bool nocache = options.noCache() || getenv("xcrun_nocache") != NULL;
/*
* Warn about unhandled arguments.
*/
if (nocache || options.killCache()) {
fprintf(stderr, "warning: cache options not implemented\n");
}
/*
* Create filesystem.
*/
auto filesystem = std::unique_ptr<Filesystem>(new DefaultFilesystem());
/*
* Load the SDK manager from the developer root.
*/
ext::optional<std::string> developerRoot = xcsdk::Environment::DeveloperRoot(filesystem.get());
if (!developerRoot) {
fprintf(stderr, "error: unable to find developer root\n");
return -1;
}
auto configuration = xcsdk::Configuration::Load(filesystem.get(), xcsdk::Configuration::DefaultPaths());
auto manager = xcsdk::SDK::Manager::Open(filesystem.get(), *developerRoot, configuration);
if (manager == nullptr) {
fprintf(stderr, "error: unable to load manager from '%s'\n", developerRoot->c_str());
return -1;
}
if (verbose) {
fprintf(stderr, "verbose: using developer root '%s'\n", manager->path().c_str());
}
/*
* Determine the SDK to use.
*/
xcsdk::SDK::Target::shared_ptr target = manager->findTarget(SDK);
if (target == nullptr) {
fprintf(stderr, "error: unable to find sdk '%s'\n", SDK.c_str());
return -1;
}
if (verbose) {
fprintf(stderr, "verbose: using sdk '%s': %s\n", target->canonicalName().c_str(), target->path().c_str());
}
/*
* Determine the toolchains to use. Default to the SDK's toolchains.
*/
xcsdk::SDK::Toolchain::vector toolchains;
if (!toolchainsInput.empty()) {
/* If the custom toolchain exists, use it instead. */
std::vector<std::string> toolchainTokens = pbxsetting::Type::ParseList(toolchainsInput);
for (std::string const &toolchainToken : toolchainTokens) {
if (auto TC = manager->findToolchain(toolchainToken)) {
toolchains.push_back(TC);
}
//.........这里部分代码省略.........