[PATCH] D152771: [docs] Fix LibTooling documentation for OptionsParser change
Hironao OTSUBO via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 12 21:14:44 PDT 2023
motemen created this revision.
motemen added reviewers: serge-sans-paille, nridge.
Herald added a project: All.
motemen requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Additional documentation fix per https://reviews.llvm.org/D94420
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D152771
Files:
clang/docs/LibTooling.rst
Index: clang/docs/LibTooling.rst
===================================================================
--- clang/docs/LibTooling.rst
+++ clang/docs/LibTooling.rst
@@ -69,9 +69,15 @@
static llvm::cl::OptionCategory MyToolCategory("my-tool options");
int main(int argc, const char **argv) {
- // CommonOptionsParser constructor will parse arguments and create a
- // CompilationDatabase. In case of error it will terminate the program.
- CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
+ // CommonOptionsParser::create will parse arguments and create a
+ // CompilationDatabase.
+ auto ExpectedParser = CommonOptionsParser::create(argc, argv, MyToolCategory);
+ if (!ExpectedParser) {
+ // Fail gracefully for unsupported options.
+ llvm::errs() << ExpectedParser.takeError();
+ return 1;
+ }
+ CommonOptionsParser &OptionsParser = ExpectedParser.get();
// Use OptionsParser.getCompilations() and OptionsParser.getSourcePathList()
// to retrieve CompilationDatabase and the list of input file paths.
@@ -133,7 +139,13 @@
static cl::extrahelp MoreHelp("\nMore help text...\n");
int main(int argc, const char **argv) {
- CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
+ auto ExpectedParser = CommonOptionsParser::create(argc, argv, MyToolCategory);
+ if (!ExpectedParser) {
+ // Fail gracefully for unsupported options.
+ llvm::errs() << ExpectedParser.takeError();
+ return 1;
+ }
+ CommonOptionsParser &OptionsParser = ExpectedParser.get();
ClangTool Tool(OptionsParser.getCompilations(),
OptionsParser.getSourcePathList());
return Tool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>().get());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152771.530761.patch
Type: text/x-patch
Size: 1759 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230613/f89755c1/attachment-0001.bin>
More information about the cfe-commits
mailing list