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

Sylvestre Ledru via cfe-commits cfe-commits at lists.llvm.org
Sat Aug 12 08:15:10 PDT 2017


Author: sylvestre
Date: Sat Aug 12 08:15:10 2017
New Revision: 310778

URL: http://llvm.org/viewvc/llvm-project?rev=310778&view=rev
Log:
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

Added:
    cfe/trunk/test/Format/verbose.cpp
Modified:
    cfe/trunk/docs/ClangFormat.rst
    cfe/trunk/docs/ReleaseNotes.rst
    cfe/trunk/tools/clang-format/ClangFormat.cpp

Modified: cfe/trunk/docs/ClangFormat.rst
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormat.rst?rev=310778&r1=310777&r2=310778&view=diff
==============================================================================
--- cfe/trunk/docs/ClangFormat.rst (original)
+++ cfe/trunk/docs/ClangFormat.rst Sat Aug 12 08:15:10 2017
@@ -71,6 +71,7 @@ to format C/C++/Obj-C code.
                                 Use -style="{key: value, ...}" to set specific
                                 parameters, e.g.:
                                   -style="{BasedOnStyle: llvm, IndentWidth: 8}"
+    -verbose                  - If set, shows the list of processed files
 
   Generic Options:
 

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=310778&r1=310777&r2=310778&view=diff
==============================================================================
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Sat Aug 12 08:15:10 2017
@@ -187,6 +187,9 @@ clang-format
 
 ...
 
+* Option -verbose added to the command line.
+  Shows the list of processed files.
+
 libclang
 --------
 

Added: cfe/trunk/test/Format/verbose.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Format/verbose.cpp?rev=310778&view=auto
==============================================================================
--- cfe/trunk/test/Format/verbose.cpp (added)
+++ cfe/trunk/test/Format/verbose.cpp Sat Aug 12 08:15:10 2017
@@ -0,0 +1,16 @@
+// RUN: clang-format %s  2> %t.stderr
+// RUN: not grep "Formatting" %t.stderr
+// RUN: clang-format %s -verbose 2> %t.stderr
+// RUN: grep -E "Formatting (.*)verbose.cpp(.*)" %t.stderr
+// RUN: clang-format %s -verbose=false 2> %t.stderr
+// RUN: not grep "Formatting" %t.stderr
+
+int a;
+// RUN: clang-format %s  2> %t.stderr
+// RUN: not grep "Formatting" %t.stderr
+// RUN: clang-format %s -verbose 2> %t.stderr
+// RUN: grep -E "Formatting (.*)verbose.cpp(.*)" %t.stderr
+// RUN: clang-format %s -verbose=false 2> %t.stderr
+// RUN: not grep "Formatting" %t.stderr
+
+int a;

Modified: cfe/trunk/tools/clang-format/ClangFormat.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=310778&r1=310777&r2=310778&view=diff
==============================================================================
--- cfe/trunk/tools/clang-format/ClangFormat.cpp (original)
+++ cfe/trunk/tools/clang-format/ClangFormat.cpp Sat Aug 12 08:15:10 2017
@@ -102,6 +102,10 @@ static cl::opt<bool> SortIncludes(
              "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 @@ int main(int argc, const char **argv) {
   }
 
   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;
 }
-




More information about the cfe-commits mailing list