From 59803dba2bce1eada4470d5c64f5e089c6210059 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 22 Dec 2022 16:34:01 +0100 Subject: [PATCH 1/3] Support restyling only the specified files Signed-off-by: Gilles Peskine --- scripts/code_style.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/scripts/code_style.py b/scripts/code_style.py index 8e82b93fb0..77f6a1b6a4 100755 --- a/scripts/code_style.py +++ b/scripts/code_style.py @@ -163,14 +163,26 @@ def main() -> int: + uncrustify_version + "' (Note: The only supported version" \ "is " + UNCRUSTIFY_SUPPORTED_VERSION + ")", file=STDOUT_UTF8) - src_files = get_src_files() - parser = argparse.ArgumentParser() - parser.add_argument('-f', '--fix', action='store_true', \ - help='modify source files to fix the code style') + parser.add_argument('-f', '--fix', action='store_true', + help='modify source files to fix the code style') + # --files is almost useless: it only matters if there are no files + # ('code_style.py' without arguments checks all files known to Git, + # 'code_style.py --files' does nothing). 'code_style.py --files ...' is + # intended as a stable ("porcelain") way to restyle a possibly empty + # set of files. + parser.add_argument('--files', action='store_true', + help='only check the specified files (default with non-option arguments)') + parser.add_argument('operands', nargs='*', metavar='FILE', + help='files to check (if none: check files that are known to git)') args = parser.parse_args() + if args.files or args.operands: + src_files = args.operands + else: + src_files = get_src_files() + if args.fix: # Fix mode return fix_style(src_files) From 9d34cf3f0b2d60fa25308649522a24fa53c5bf37 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Fri, 23 Dec 2022 18:15:19 +0100 Subject: [PATCH 2/3] Documentation improvements Signed-off-by: Gilles Peskine --- scripts/code_style.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/scripts/code_style.py b/scripts/code_style.py index 77f6a1b6a4..23bb21b3a1 100755 --- a/scripts/code_style.py +++ b/scripts/code_style.py @@ -159,18 +159,20 @@ def main() -> int: """ uncrustify_version = get_uncrustify_version().strip() if UNCRUSTIFY_SUPPORTED_VERSION not in uncrustify_version: - print("Warning: Using unsupported Uncrustify version '" \ - + uncrustify_version + "' (Note: The only supported version" \ - "is " + UNCRUSTIFY_SUPPORTED_VERSION + ")", file=STDOUT_UTF8) + print("Warning: Using unsupported Uncrustify version '" + + uncrustify_version + "'", file=STDOUT_UTF8) + print("Note: The only supported version is " + + UNCRUSTIFY_SUPPORTED_VERSION, file=STDOUT_UTF8) parser = argparse.ArgumentParser() parser.add_argument('-f', '--fix', action='store_true', - help='modify source files to fix the code style') + help=('modify source files to fix the code style ' + '(default: print diff, do not modify files)')) # --files is almost useless: it only matters if there are no files # ('code_style.py' without arguments checks all files known to Git, - # 'code_style.py --files' does nothing). 'code_style.py --files ...' is - # intended as a stable ("porcelain") way to restyle a possibly empty - # set of files. + # 'code_style.py --files' does nothing). In particular, + # 'code_style.py --files ...' is intended as a stable ("porcelain") way + # to restyle a possibly empty set of files. parser.add_argument('--files', action='store_true', help='only check the specified files (default with non-option arguments)') parser.add_argument('operands', nargs='*', metavar='FILE', From d449cedd3a9e261e68eb3cd0e4810786b01ab39e Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 12 Jan 2023 15:45:32 +0100 Subject: [PATCH 3/3] Fix example command Signed-off-by: Gilles Peskine --- scripts/code_style.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/code_style.py b/scripts/code_style.py index 23bb21b3a1..a0f35c7c2d 100755 --- a/scripts/code_style.py +++ b/scripts/code_style.py @@ -171,8 +171,8 @@ def main() -> int: # --files is almost useless: it only matters if there are no files # ('code_style.py' without arguments checks all files known to Git, # 'code_style.py --files' does nothing). In particular, - # 'code_style.py --files ...' is intended as a stable ("porcelain") way - # to restyle a possibly empty set of files. + # 'code_style.py --fix --files ...' is intended as a stable ("porcelain") + # way to restyle a possibly empty set of files. parser.add_argument('--files', action='store_true', help='only check the specified files (default with non-option arguments)') parser.add_argument('operands', nargs='*', metavar='FILE',