[clang-tools-extra] r191322 - clang-apply-replacements: Clean up -help and -version

Edwin Vane edwin.vane at intel.com
Tue Sep 24 11:14:55 PDT 2013


Author: revane
Date: Tue Sep 24 13:14:54 2013
New Revision: 191322

URL: http://llvm.org/viewvc/llvm-project?rev=191322&view=rev
Log:
clang-apply-replacements: Clean up -help and -version

Options that leak from other parts of LLVM are now pruned out of -help.

-version output is specific to clang-apply-replacements now.

Differential Revision: http://llvm-reviews.chandlerc.com/D1747


Modified:
    clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp

Modified: clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp?rev=191322&r1=191321&r2=191322&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp (original)
+++ clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp Tue Sep 24 13:14:54 2013
@@ -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 @@ static cl::opt<bool> RemoveTUReplacement
              "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 @@ private:
   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());





More information about the cfe-commits mailing list