Skip to content

Commit

Permalink
Merge pull request #1312 from csordasmarton/extend-cmd-filters
Browse files Browse the repository at this point in the history
Extend command line filters
  • Loading branch information
gyorb authored Jan 30, 2018
2 parents 5c36828 + 672d940 commit 3dae479
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 28 deletions.
14 changes: 9 additions & 5 deletions docs/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -1281,14 +1281,18 @@ positional arguments:
optional arguments:
-h, --help show this help message and exit
-s, --suppressed Show only suppressed results instead of only
unsuppressed ones. (default: False)
-s, --suppressed DEPRECATED. Use the '--filter' option to get false
positive (suppressed) results. Show only suppressed
results instead of only unsuppressed ones.
--filter FILTER Filter results. The filter string has the following
format:
[<SEVERITIES>]:[<CHECKER_NAMES>]:[<FILE_PATHS>] where
severites, checker_names, file_paths should be a comma
[<SEVERITIES>]:[<CHECKER_NAMES>]:[<FILE_PATHS>]:
[<DETECTION_STATUSES>]:[<REVIEW_STATUSES>] where
severites, checker_names, file_paths,
detection_statuses and review_statuses should be a comma
separated list, e.g.:
"high,medium:unix,core:*.cpp,*.h" (default: ::)
"high,medium:unix,core:*.cpp,*.h:new,unresolved:
false_positive,intentional" (default: ::)
~~~~~~~~~~~~~~~~~~~~~

### <a name="cmd-diff"></a> Show differences between two runs (`diff`)
Expand Down
40 changes: 24 additions & 16 deletions libcodechecker/cmd/cmd_line_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,14 @@ def add_filter_conditions(report_filter, filter_str):
the checker id doesn't have to be complete (e.g. unix).
"""

if filter_str.count(':') != 2:
LOG.error("Filter string has to contain two colons (e.g. "
"\"high,medium:unix,core:*.cpp\").")
if filter_str.count(':') != 4:
LOG.error("Filter string has to contain four colons (e.g. "
"\"high,medium:unix,core:*.cpp:new,unresolved:"
"false_positive,intentional\").")
sys.exit(1)

severities, checkers, paths = map(lambda x: x.strip(),
filter_str.split(':'))
severities, checkers, paths, dt_statuses, rw_statuses = \
map(lambda x: x.strip(), filter_str.split(':'))

if severities:
report_filter.severity = map(
Expand All @@ -106,6 +107,16 @@ def add_filter_conditions(report_filter, filter_str):
report_filter.filepath = map(lambda x: '*' + x + '*',
paths.split(','))

if dt_statuses:
report_filter.detectionStatus = map(
lambda x: ttypes.DetectionStatus._NAMES_TO_VALUES[x.upper()],
dt_statuses.split(','))

if rw_statuses:
report_filter.reviewStatus = map(
lambda x: ttypes.ReviewStatus._NAMES_TO_VALUES[x.upper()],
rw_statuses.split(','))

# ---------------------------------------------------------------------------
# Argument handlers for the 'CodeChecker cmd' subcommands.
# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -163,24 +174,21 @@ def handle_list_results(args):
if args.output_format == 'json':
print(CmdLineOutputEncoder().encode(all_results))
else:

if args.suppressed:
header = ['File', 'Checker', 'Severity', 'Msg', 'Suppress comment']
else:
header = ['File', 'Checker', 'Severity', 'Msg']
header = ['File', 'Checker', 'Severity', 'Msg', 'Review status',
'Detection status']

rows = []
for res in all_results:
bug_line = res.line
checked_file = res.checkedFile + ' @ ' + str(bug_line)
sev = ttypes.Severity._VALUES_TO_NAMES[res.severity]
rw_status = \
ttypes.ReviewStatus._VALUES_TO_NAMES[res.reviewData.status]
dt_status = \
ttypes.DetectionStatus._VALUES_TO_NAMES[res.detectionStatus]

if args.suppressed:
rows.append((checked_file, res.checkerId, sev,
res.checkerMsg, res.suppressComment))
else:
rows.append(
(checked_file, res.checkerId, sev, res.checkerMsg))
rows.append((checked_file, res.checkerId, sev,
res.checkerMsg, rw_status, dt_status))

print(twodim_to_str(args.output_format, header, rows))

Expand Down
18 changes: 11 additions & 7 deletions libcodechecker/libhandlers/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,27 @@ def __add_filtering_arguments(parser):
Add some common filtering arguments to the given parser.
"""

# TODO: '-s' does not mean suppressed anymore in any other command.
parser.add_argument('-s', '--suppressed',
dest="suppressed",
action='store_true',
help="Show only suppressed results instead of only "
"unsuppressed ones.")
help="DEPRECATED. Use the '--filter' option to get "
"false positive (suppressed) results. Show only "
"suppressed results instead of only unsuppressed "
"ones.")

parser.add_argument('--filter',
type=str,
dest='filter',
default="::",
default="::::",
help="Filter results. The filter string has the "
"following format: "
"[<SEVERITIES>]:[<CHECKER_NAMES>]:[<FILE_PATHS>] "
"[<SEVERITIES>]:[<CHECKER_NAMES>]:[<FILE_PATHS>]:"
"[<DETECTION_STATUSES>]:[<REVIEW_STATUSES>]"
"where severites, checker_names, "
"file_paths should be a comma separated list, "
"e.g.: \"high,medium:unix,core:*.cpp,*.h\"")
"file_paths, detection_statuses, review_statuses "
"should be a comma separated list, e.g.:"
"\"high,medium:unix,core:*.cpp,*.h:"
"new,unresolved:false_positive,intentional\"")


def __register_results(parser):
Expand Down

0 comments on commit 3dae479

Please sign in to comment.