[PATCH] clang-apply-replacements: Clean up -help and -version
Edwin Vane
edwin.vane at intel.com
Tue Sep 24 10:47:12 PDT 2013
Hi tareqsiraj, arielbernal,
Options that leak from other parts of LLVM are now pruned out of -help.
-version output is specific to clang-apply-replacements now.
http://llvm-reviews.chandlerc.com/D1747
Files:
clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
Index: clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
===================================================================
--- clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
+++ clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
@@ -17,7 +17,10 @@
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/Version.h"
#include "clang/Rewrite/Core/Rewriter.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringSet.h"
#include "llvm/Support/CommandLine.h"
using namespace llvm;
@@ -33,6 +36,11 @@
"merging/replacing."),
cl::init(false));
+// Update this list of options to show in -help as new options are added.
+// Should add even those options marked as 'Hidden'. Any option not listed
+// here will get marked 'ReallyHidden' so they don't appear in any -help text.
+const char *OptionsToShow[] = { "help", "version", "remove-change-desc-files" };
+
// Helper object to remove the TUReplacement files (triggered by
// "remove-change-desc-files" command line option) when exiting current scope.
class ScopedFileRemover {
@@ -50,7 +58,22 @@
clang::DiagnosticsEngine &Diag;
};
+void printVersion() {
+ outs() << "clang-apply-replacements version " CLANG_VERSION_STRING << "\n";
+}
+
int main(int argc, char **argv) {
+ // Only include our options in -help output.
+ StringMap<cl::Option*> OptMap;
+ cl::getRegisteredOptions(OptMap);
+ const char **EndOpts = OptionsToShow + array_lengthof(OptionsToShow);
+ for (StringMap<cl::Option *>::iterator I = OptMap.begin(), E = OptMap.end();
+ I != E; ++I) {
+ if (std::find(OptionsToShow, EndOpts, I->getKey()) == EndOpts)
+ I->getValue()->setHiddenFlag(cl::ReallyHidden);
+ }
+
+ cl::SetVersionPrinter(&printVersion);
cl::ParseCommandLineOptions(argc, argv);
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1747.1.patch
Type: text/x-patch
Size: 1971 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130924/244708cf/attachment.bin>
More information about the cfe-commits
mailing list