Skip to content

Commit f482df6

Browse files
committed
csgrep --set-imp-level: set importance level on all defects
... to the specified value Related: https://issues.redhat.com/browse/OSH-343 Closes: #149
1 parent d059bc7 commit f482df6

7 files changed

+2468
-0
lines changed

src/csgrep.cc

+2
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ int main(int argc, char *argv[])
577577
("warning-rate-limit", po::value<int>(), "stop processing a warning if the count of its occurrences exceeds the specified limit")
578578
("limit-msg-len", po::value<int>(), "limit message length by a number provided")
579579
("remove-duplicates,u", "remove defects that are not unique by their key event")
580+
("set-imp-level", po::value<int>(), "set importance level on all defects to the specified value")
580581
("set-scan-prop", po::value<TStringList>(), "NAME:VALUE pair to override the specified scan property")
581582
("strip-path-prefix", po::value<string>(), "string prefix to strip from path (applied after all filters)")
582583
("prepend-path-prefix", po::value<string>(), "string prefix to prepend to relative paths (applied after all filters)")
@@ -682,6 +683,7 @@ int main(int argc, char *argv[])
682683
if (!chainDecoratorIntArg<EventPrunner>(&eng, vm, "prune-events")
683684
|| !chainDecoratorIntArg<RateLimitter>(&eng, vm, "warning-rate-limit")
684685
|| !chainDecoratorIntArg<MsgTrimmer>(&eng, vm, "limit-msg-len")
686+
|| !chainDecoratorIntArg<ImpLevelSetter>(&eng, vm, "set-imp-level")
685687
|| !chainDecoratorIntArg<CtxEmbedder>(&eng, vm, "embed-context"))
686688
// error message already printed, eng already feeed
687689
return 1;

src/lib/filter.cc

+11
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,14 @@ void MsgTrimmer::handleDef(const Defect &defOrig)
337337

338338
agent_->handleDef(def);
339339
}
340+
341+
342+
// /////////////////////////////////////////////////////////////////////////////
343+
// implementation of ImpLevelSetter
344+
345+
void ImpLevelSetter::handleDef(const Defect &defOrig)
346+
{
347+
Defect def = defOrig;
348+
def.imp = impLevel_;
349+
agent_->handleDef(def);
350+
}

src/lib/filter.hh

+15
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,19 @@ class MsgTrimmer: public GenericAbstractFilter {
192192
void handleDef(const Defect &defOrig) override;
193193
};
194194

195+
/// set importance level on all defects to the specified value
196+
class ImpLevelSetter: public GenericAbstractFilter {
197+
private:
198+
const int impLevel_;
199+
200+
public:
201+
ImpLevelSetter(AbstractWriter *agent, const int impLevel):
202+
GenericAbstractFilter(agent),
203+
impLevel_(impLevel)
204+
{
205+
}
206+
207+
void handleDef(const Defect &defOrig) override;
208+
};
209+
195210
#endif /* H_GUARD_FILTER_H */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--mode=json --set-imp-level=0

tests/csgrep/0117-csgrep-set-imp-level-stdin.txt

+1,222
Large diffs are not rendered by default.

tests/csgrep/0117-csgrep-set-imp-level-stdout.txt

+1,216
Large diffs are not rendered by default.

tests/csgrep/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,4 @@ test_csgrep("0113-gitleaks-limit-msg-len" )
160160
test_csgrep("0114-json-sc-column" )
161161
test_csgrep("0115-csgrep-imp-filter" )
162162
test_csgrep("0116-csgrep-warning-rate-limit" )
163+
test_csgrep("0117-csgrep-set-imp-level" )

0 commit comments

Comments
 (0)