1 """Format C code according to QMK's style.
9 @cli.argument('files', nargs
='*', arg_only
=True, help='Filename(s) to format.')
10 @cli.subcommand("Format C code according to QMK's style.")
12 """Format C code according to QMK's style.
14 clang_format
= ['clang-format', '-i']
16 # Find the list of files to format
17 if not cli
.args
.files
:
18 for dir in ['drivers', 'quantum', 'tests', 'tmk_core']:
19 for dirpath
, dirnames
, filenames
in os
.walk(dir):
20 if 'tmk_core/protocol/usb_hid' in dirpath
:
23 for name
in filenames
:
24 if name
.endswith('.c') or name
.endswith('.h') or name
.endswith('.cpp'):
25 cli
.args
.files
.append(os
.path
.join(dirpath
, name
))
27 # Run clang-format on the files we've found
29 subprocess
.run(clang_format
+ cli
.args
.files
, check
=True)
30 cli
.log
.info('Successfully formatted the C code.')
32 except subprocess
.CalledProcessError
:
33 cli
.log
.error('Error formatting C code!')