[PATCH] D34824: clang-format: add an option -verbose to list the files being processed
Sylvestre Ledru via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 18 06:29:44 PDT 2017
sylvestre.ledru updated this revision to Diff 107089.
sylvestre.ledru marked an inline comment as done.
sylvestre.ledru added a comment.
Fixed, thanks for spotting the mistake.
Looks like we could improve the testsuite as my mistake hasn't been catched.
https://reviews.llvm.org/D34824
Files:
docs/ClangFormat.rst
docs/ReleaseNotes.rst
test/Format/verbose.cpp
tools/clang-format/ClangFormat.cpp
Index: test/Format/verbose.cpp
===================================================================
--- test/Format/verbose.cpp
+++ test/Format/verbose.cpp
@@ -0,0 +1,8 @@
+// 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;
Index: docs/ClangFormat.rst
===================================================================
--- docs/ClangFormat.rst
+++ docs/ClangFormat.rst
@@ -71,6 +71,7 @@
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:
Index: docs/ReleaseNotes.rst
===================================================================
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -191,6 +191,9 @@
* Comment reflow support added. Overly long comment lines will now be reflown with the rest of
the paragraph instead of just broken. Option **ReflowComments** added and enabled by default.
+* Option -verbose added to the command line.
+ Shows the list of processed files.
+
libclang
--------
Index: tools/clang-format/ClangFormat.cpp
===================================================================
--- tools/clang-format/ClangFormat.cpp
+++ tools/clang-format/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;
}
-
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34824.107089.patch
Type: text/x-patch
Size: 3037 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170718/102b2a4d/attachment.bin>
More information about the cfe-commits
mailing list