diff options
author | skullY <skullydazed@gmail.com> | 2019-08-22 10:18:52 -0700 |
---|---|---|
committer | skullydazed <skullydazed@users.noreply.github.com> | 2019-08-31 08:50:25 -0700 |
commit | 95477749629407e2a9e33c6ccf26ecc8b24ab07a (patch) | |
tree | 77749d8b0a0aaa6e7045aa2f12138f005886b463 /lib/python/qmk/cli/cformat.py | |
parent | d076234fd115ca7a3e5c0f9418e2b28b80c7ec20 (diff) | |
download | qmk_firmware-95477749629407e2a9e33c6ccf26ecc8b24ab07a.tar.gz qmk_firmware-95477749629407e2a9e33c6ccf26ecc8b24ab07a.zip |
CLI command to format C code
Diffstat (limited to 'lib/python/qmk/cli/cformat.py')
-rw-r--r-- | lib/python/qmk/cli/cformat.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/python/qmk/cli/cformat.py b/lib/python/qmk/cli/cformat.py new file mode 100644 index 000000000..f7020f4c5 --- /dev/null +++ b/lib/python/qmk/cli/cformat.py | |||
@@ -0,0 +1,27 @@ | |||
1 | """Format C code according to QMK's style. | ||
2 | """ | ||
3 | import os | ||
4 | import subprocess | ||
5 | |||
6 | from milc import cli | ||
7 | |||
8 | |||
9 | @cli.entrypoint("Format C code according to QMK's style.") | ||
10 | def main(cli): | ||
11 | """Format C code according to QMK's style. | ||
12 | """ | ||
13 | clang_format = ['clang-format', '-i'] | ||
14 | code_files = [] | ||
15 | for dir in ['drivers', 'quantum', 'tests', 'tmk_core']: | ||
16 | for dirpath, dirnames, filenames in os.walk(dir): | ||
17 | if 'tmk_core/protocol/usb_hid' in dirpath: | ||
18 | continue | ||
19 | for name in filenames: | ||
20 | if name.endswith('.c') or name.endswith('.h') or name.endswith('.cpp'): | ||
21 | code_files.append(os.path.join(dirpath, name)) | ||
22 | |||
23 | try: | ||
24 | subprocess.run(clang_format + code_files, check=True) | ||
25 | cli.log.info('Successfully formatted the C code.') | ||
26 | except subprocess.CalledProcessError: | ||
27 | cli.log.error('Error formatting C code!') | ||