239239)
240240cli_arg_parser .add_argument (
241241 "-x" ,
242- "--extra-args" ,
243- default = "" ,
242+ "--extra-arg" ,
243+ default = [],
244+ action = "append" ,
244245 help = """A string of extra arguments passed to clang-tidy for use as
245- compiler arguments.
246+ compiler arguments. This can be specified more than once for each
247+ additional argument. Recommend using quotes around the value here:
248+
249+ .. code-block:: shell
250+
251+ cpp-linter --extra-arg="-std=c++17" --extra-arg="-Wall"
246252
247253Defaults to ``'%(default)s'``.
248254""" ,
@@ -487,7 +493,7 @@ def run_clang_tidy(
487493 lines_changed_only : int ,
488494 database : str ,
489495 repo_root : str ,
490- extra_args : str ,
496+ extra_args : List [ str ] ,
491497) -> None :
492498 """Run clang-tidy on a certain file.
493499
@@ -500,7 +506,7 @@ def run_clang_tidy(
500506 diff info.
501507 :param database: The path to the compilation database.
502508 :param repo_root: The path to the repository root folder.
503- :param extra_args: A string of extra arguments used by clang-tidy as compiler
509+ :param extra_args: A list of extra arguments used by clang-tidy as compiler
504510 arguments.
505511 """
506512 if checks == "-*" : # if all checks are disabled, then clang-tidy is skipped
@@ -524,8 +530,10 @@ def run_clang_tidy(
524530 line_ranges = dict (name = filename , lines = file_obj ["line_filter" ][ranges ])
525531 logger .info ("line_filter = %s" , json .dumps ([line_ranges ]))
526532 cmds .append (f"--line-filter={ json .dumps ([line_ranges ])} " )
527- if extra_args :
528- cmds .append (f"--extra-arg={ repr (extra_args )} " )
533+ if len (extra_args ) == 1 and " " in extra_args [0 ]:
534+ extra_args = extra_args [0 ].split ()
535+ for extra_arg in extra_args :
536+ cmds .append (f"--extra-arg={ extra_arg } " )
529537 cmds .append (filename )
530538 # clear yml file's content before running clang-tidy
531539 Path ("clang_tidy_output.yml" ).write_bytes (b"" )
@@ -638,7 +646,7 @@ def capture_clang_tools_output(
638646 lines_changed_only : int ,
639647 database : str ,
640648 repo_root : str ,
641- extra_args : str ,
649+ extra_args : List [ str ] ,
642650):
643651 """Execute and capture all output from clang-tidy and clang-format. This aggregates
644652 results in the :attr:`~cpp_linter.Globals.OUTPUT`.
@@ -652,7 +660,7 @@ def capture_clang_tools_output(
652660 diff info.
653661 :param database: The path to the compilation database.
654662 :param repo_root: The path to the repository root folder.
655- :param extra_args: A string of extra arguments used by clang-tidy as compiler
663+ :param extra_args: A list of extra arguments used by clang-tidy as compiler
656664 arguments.
657665 """
658666 # temporary cache of parsed notifications for use in log commands
@@ -987,7 +995,7 @@ def main():
987995 args .lines_changed_only ,
988996 args .database ,
989997 args .repo_root ,
990- args .extra_args ,
998+ args .extra_arg ,
991999 )
9921000
9931001 start_log_group ("Posting comment(s)" )
0 commit comments