|
20 | 20 | #include "abstract-filter.hh"
|
21 | 21 | #include "filter.hh"
|
22 | 22 | #include "finger-print.hh"
|
| 23 | +#include "glob-expand.hh" |
23 | 24 | #include "msg-filter.hh"
|
24 | 25 | #include "parser.hh"
|
25 | 26 | #include "parser-common.hh"
|
@@ -615,6 +616,7 @@ int main(int argc, char *argv[])
|
615 | 616 | ("strip-path-prefix", po::value<string>(), "string prefix to strip from path (applied after all filters)")
|
616 | 617 | ("prepend-path-prefix", po::value<string>(), "string prefix to prepend to relative paths (applied after all filters)")
|
617 | 618 |
|
| 619 | + ("file-glob", "expand glob patterns in the names of input files") |
618 | 620 | ("ignore-case,i", "ignore case when matching regular expressions")
|
619 | 621 | ("ignore-parser-warnings", "if enabled, parser warnings about the input files do not affect exit code")
|
620 | 622 | ("invert-match,v", "select defects that do not match the selected criteria")
|
@@ -680,6 +682,15 @@ int main(int argc, char *argv[])
|
680 | 682 | return 1;
|
681 | 683 | }
|
682 | 684 |
|
| 685 | + // if the --file-glob flag was used, check whether a glob pattern was given |
| 686 | + const bool fileGlob = !!vm.count("file-glob"); |
| 687 | + const bool hasInputFile = !!vm.count("input-file"); |
| 688 | + if (fileGlob && !hasInputFile) { |
| 689 | + std::cerr << name |
| 690 | + << ": error: glob pattern is required with --file-glob\n"; |
| 691 | + return 1; |
| 692 | + } |
| 693 | + |
683 | 694 | // create a writer according to the selected mode
|
684 | 695 | WriterFactory factory;
|
685 | 696 | AbstractWriter *eng = factory.create(mode);
|
@@ -726,16 +737,20 @@ int main(int argc, char *argv[])
|
726 | 737 |
|
727 | 738 | bool hasError = false;
|
728 | 739 |
|
729 |
| - if (!vm.count("input-file")) { |
730 |
| - hasError = !eng->handleFile("-", silent); |
731 |
| - } |
732 |
| - else { |
733 |
| - const TStringList &files = vm["input-file"].as<TStringList>(); |
734 |
| - for (const string &fileName : files) { |
735 |
| - if (!eng->handleFile(fileName, silent)) |
736 |
| - hasError = true; |
737 |
| - } |
738 |
| - } |
| 740 | + // if no input file is given, read from stdin |
| 741 | + TStringList files = { "-" }; |
| 742 | + |
| 743 | + if (hasInputFile) |
| 744 | + // use the given list of input files (or glob patterns) |
| 745 | + files = vm["input-file"].as<TStringList>(); |
| 746 | + |
| 747 | + if (fileGlob) |
| 748 | + // expand file globs |
| 749 | + hasError |= !globExpand(&files); |
| 750 | + |
| 751 | + // process all input files one by one |
| 752 | + for (const string &fileName : files) |
| 753 | + hasError |= !eng->handleFile(fileName, silent); |
739 | 754 |
|
740 | 755 | eng->flush();
|
741 | 756 | delete eng;
|
|
0 commit comments