From 61c84f79bdfa22ace5db07b24551a6e43e479984 Mon Sep 17 00:00:00 2001 From: Tyler Weaver Date: Mon, 4 Jan 2021 15:01:26 -0700 Subject: [PATCH] Add clang-format-version option to ament_clang_format Signed-off-by: Tyler Weaver --- ament_clang_format/ament_clang_format/main.py | 7 +++++++ ament_clang_format/doc/index.rst | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ament_clang_format/ament_clang_format/main.py b/ament_clang_format/ament_clang_format/main.py index 942617a0..87120628 100755 --- a/ament_clang_format/ament_clang_format/main.py +++ b/ament_clang_format/ament_clang_format/main.py @@ -47,6 +47,9 @@ def main(argv=sys.argv[1:]): help='The files or directories to check. For directories files ending ' 'in %s will be considered.' % ', '.join(["'.%s'" % e for e in extensions])) + parser.add_argument( + '--clang-format-version', + help='The version of clang-format to use.') parser.add_argument( '--reformat', action='store_true', @@ -80,6 +83,10 @@ def main(argv=sys.argv[1:]): 'clang-format-3.4', 'clang-format-3.3', ] + + if args.clang_format_version: + bin_names = ['clang-format-' + args.clang_format_version] + clang_format_bin = find_executable(bin_names) if not clang_format_bin: print('Could not find %s executable' % diff --git a/ament_clang_format/doc/index.rst b/ament_clang_format/doc/index.rst index a724052f..4c4497b5 100644 --- a/ament_clang_format/doc/index.rst +++ b/ament_clang_format/doc/index.rst @@ -12,10 +12,23 @@ How to run the check from the command line? .. code:: sh - ament_clang_format [ ...] + ament_clang_format [-h] [--config path] + [--clang-format-version CLANG_FORMAT_VERSION] + [--reformat] [--xunit-file XUNIT_FILE] + [paths [paths ...]] + +``paths`` are directories to recursively search for files to run clang-format +on. If no ``paths`` option is set the current directory will be used. + +The ``--config`` allows you to set the path to the .clang-format file to use. + +The ``--clang-format-version`` enables you to set a different version of +clang-format to use. When using the option ``--reformat`` the proposed changes are applied in place. +The ``--xunit-file`` option is used to generate a xunit output file. + How to run the check from within a CMake ament package as part of the tests? ----------------------------------------------------------------------------