aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/python/qmk/cli/cformat.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/python/qmk/cli/cformat.py b/lib/python/qmk/cli/cformat.py
index f7020f4c5..0c209247d 100644
--- a/lib/python/qmk/cli/cformat.py
+++ b/lib/python/qmk/cli/cformat.py
@@ -6,22 +6,24 @@ import subprocess
6from milc import cli 6from milc import cli
7 7
8 8
9@cli.argument('files', nargs='*', help='Filename(s) to format.')
9@cli.entrypoint("Format C code according to QMK's style.") 10@cli.entrypoint("Format C code according to QMK's style.")
10def main(cli): 11def main(cli):
11 """Format C code according to QMK's style. 12 """Format C code according to QMK's style.
12 """ 13 """
13 clang_format = ['clang-format', '-i'] 14 clang_format = ['clang-format', '-i']
14 code_files = [] 15 if not cli.args.files:
15 for dir in ['drivers', 'quantum', 'tests', 'tmk_core']: 16 for dir in ['drivers', 'quantum', 'tests', 'tmk_core']:
16 for dirpath, dirnames, filenames in os.walk(dir): 17 for dirpath, dirnames, filenames in os.walk(dir):
17 if 'tmk_core/protocol/usb_hid' in dirpath: 18 if 'tmk_core/protocol/usb_hid' in dirpath:
18 continue 19 continue
19 for name in filenames: 20 for name in filenames:
20 if name.endswith('.c') or name.endswith('.h') or name.endswith('.cpp'): 21 if name.endswith('.c') or name.endswith('.h') or name.endswith('.cpp'):
21 code_files.append(os.path.join(dirpath, name)) 22 cli.args.files.append(os.path.join(dirpath, name))
22 23
23 try: 24 try:
24 subprocess.run(clang_format + code_files, check=True) 25 subprocess.run(clang_format + cli.args.files, check=True)
25 cli.log.info('Successfully formatted the C code.') 26 cli.log.info('Successfully formatted the C code.')
26 except subprocess.CalledProcessError: 27 except subprocess.CalledProcessError:
27 cli.log.error('Error formatting C code!') 28 cli.log.error('Error formatting C code!')
29 return False