Skip to content

Commit 7602b13

Browse files
committed
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: https://llvm.org/svn/llvm-project/cfe/trunk@310778 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 4e37891 commit 7602b13

File tree

4 files changed

+36
-16
lines changed

4 files changed

+36
-16
lines changed

docs/ClangFormat.rst

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ to format C/C++/Obj-C code.
7171
Use -style="{key: value, ...}" to set specific
7272
parameters, e.g.:
7373
-style="{BasedOnStyle: llvm, IndentWidth: 8}"
74+
-verbose - If set, shows the list of processed files
7475
7576
Generic Options:
7677

docs/ReleaseNotes.rst

+3
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ clang-format
187187

188188
...
189189

190+
* Option -verbose added to the command line.
191+
Shows the list of processed files.
192+
190193
libclang
191194
--------
192195

test/Format/verbose.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: clang-format %s 2> %t.stderr
2+
// RUN: not grep "Formatting" %t.stderr
3+
// RUN: clang-format %s -verbose 2> %t.stderr
4+
// RUN: grep -E "Formatting (.*)verbose.cpp(.*)" %t.stderr
5+
// RUN: clang-format %s -verbose=false 2> %t.stderr
6+
// RUN: not grep "Formatting" %t.stderr
7+
8+
int a;
9+
// RUN: clang-format %s 2> %t.stderr
10+
// RUN: not grep "Formatting" %t.stderr
11+
// RUN: clang-format %s -verbose 2> %t.stderr
12+
// RUN: grep -E "Formatting (.*)verbose.cpp(.*)" %t.stderr
13+
// RUN: clang-format %s -verbose=false 2> %t.stderr
14+
// RUN: not grep "Formatting" %t.stderr
15+
16+
int a;

tools/clang-format/ClangFormat.cpp

+16-16
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ static cl::opt<bool> SortIncludes(
102102
"SortIncludes style flag"),
103103
cl::cat(ClangFormatCategory));
104104

105+
static cl::opt<bool>
106+
Verbose("verbose", cl::desc("If set, shows the list of processed files"),
107+
cl::cat(ClangFormatCategory));
108+
105109
static cl::list<std::string> FileNames(cl::Positional, cl::desc("[<file> ...]"),
106110
cl::cat(ClangFormatCategory));
107111

@@ -365,23 +369,19 @@ int main(int argc, const char **argv) {
365369
}
366370

367371
bool Error = false;
368-
switch (FileNames.size()) {
369-
case 0:
372+
if (FileNames.empty()) {
370373
Error = clang::format::format("-");
371-
break;
372-
case 1:
373-
Error = clang::format::format(FileNames[0]);
374-
break;
375-
default:
376-
if (!Offsets.empty() || !Lengths.empty() || !LineRanges.empty()) {
377-
errs() << "error: -offset, -length and -lines can only be used for "
378-
"single file.\n";
379-
return 1;
380-
}
381-
for (unsigned i = 0; i < FileNames.size(); ++i)
382-
Error |= clang::format::format(FileNames[i]);
383-
break;
374+
return Error ? 1 : 0;
375+
}
376+
if (FileNames.size() != 1 && (!Offsets.empty() || !Lengths.empty() || !LineRanges.empty())) {
377+
errs() << "error: -offset, -length and -lines can only be used for "
378+
"single file.\n";
379+
return 1;
380+
}
381+
for (const auto &FileName : FileNames) {
382+
if (Verbose)
383+
errs() << "Formatting " << FileName << "\n";
384+
Error |= clang::format::format(FileName);
384385
}
385386
return Error ? 1 : 0;
386387
}
387-

0 commit comments

Comments
 (0)