Skip to content

Commit d4fe1c8

Browse files
committed
csgprep --ignore-parser-warnings: parser warnings do not affect exit code
The `--quiet` option controls printing of error/warning messages whereas `--ignore-parser-warnings` controls whether the exit code is affected by the parsers or not. Closes: #122
1 parent 80c89a3 commit d4fe1c8

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

Diff for: src/csgrep.cc

+4
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ int main(int argc, char *argv[])
562562
("prepend-path-prefix", po::value<string>(), "string prefix to prepend to relative paths (applied after all filters)")
563563

564564
("ignore-case,i", "ignore case when matching regular expressions")
565+
("ignore-parser-warnings", "if enabled, parser warnings about the input files do not affect exit code")
565566
("invert-match,v", "select defects that do not match the selected criteria")
566567
("invert-regex,n", "invert regular expressions in all predicates")
567568
("filter-file,f", po::value<TStringList>(), "read custom filtering rules from a file in JSON format");
@@ -664,6 +665,9 @@ int main(int argc, char *argv[])
664665
// error message already printed, eng already feeed
665666
return 1;
666667

668+
if (vm.count("ignore-parser-warnings"))
669+
eng->setIgnoreParserWarnings(true);
670+
667671
bool hasError = false;
668672

669673
if (!vm.count("input-file")) {

Diff for: src/lib/writer.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ bool AbstractWriter::handleFile(Parser &parser)
4444
while (parser.getNext(&def))
4545
this->handleDef(def);
4646

47-
return !parser.hasError();
47+
return ignoreParserWarnings_ || !parser.hasError();
4848
}
4949

5050
bool AbstractWriter::handleFile(InStream &input)

Diff for: src/lib/writer.hh

+5
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,15 @@ class AbstractWriter {
5858

5959
virtual void setScanProps(const TScanProps &);
6060

61+
void setIgnoreParserWarnings(const bool val) {
62+
ignoreParserWarnings_ = val;
63+
}
64+
6165

6266
private:
6367
EFileFormat inputFormat_ = FF_INVALID;
6468
const TScanProps emptyProps_{};
69+
bool ignoreParserWarnings_ = false;
6570
};
6671

6772
using TWriterPtr = std::unique_ptr<AbstractWriter>;

0 commit comments

Comments
 (0)