clang-format: add an option -verbose to list the files being processed

Reviewers: djasper

Reviewed By: djasper

Subscribers: klimek, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D34824

git-svn-id: svn://svn.chromium.org/llvm-project/cfe/trunk/tools/clang-format@310778 0b72dbe1-c17f-4bc7-b9db-2b4152be0356
diff --git a/ClangFormat.cpp b/ClangFormat.cpp
index f8e2fe1..37c2d8b 100644
--- a/ClangFormat.cpp
+++ b/ClangFormat.cpp
@@ -102,6 +102,10 @@
              "SortIncludes style flag"),
     cl::cat(ClangFormatCategory));
 
+static cl::opt<bool>
+    Verbose("verbose", cl::desc("If set, shows the list of processed files"),
+            cl::cat(ClangFormatCategory));
+
 static cl::list<std::string> FileNames(cl::Positional, cl::desc("[<file> ...]"),
                                        cl::cat(ClangFormatCategory));
 
@@ -365,23 +369,19 @@
   }
 
   bool Error = false;
-  switch (FileNames.size()) {
-  case 0:
+  if (FileNames.empty()) {
     Error = clang::format::format("-");
-    break;
-  case 1:
-    Error = clang::format::format(FileNames[0]);
-    break;
-  default:
-    if (!Offsets.empty() || !Lengths.empty() || !LineRanges.empty()) {
-      errs() << "error: -offset, -length and -lines can only be used for "
-                "single file.\n";
-      return 1;
-    }
-    for (unsigned i = 0; i < FileNames.size(); ++i)
-      Error |= clang::format::format(FileNames[i]);
-    break;
+    return Error ? 1 : 0;
+  }
+  if (FileNames.size() != 1 && (!Offsets.empty() || !Lengths.empty() || !LineRanges.empty())) {
+    errs() << "error: -offset, -length and -lines can only be used for "
+              "single file.\n";
+    return 1;
+  }
+  for (const auto &FileName : FileNames) {
+    if (Verbose)
+      errs() << "Formatting " << FileName << "\n";
+    Error |= clang::format::format(FileName);
   }
   return Error ? 1 : 0;
 }
-