diff options
| author | skullY <skullydazed@gmail.com> | 2019-08-22 13:30:50 -0700 |
|---|---|---|
| committer | skullydazed <skullydazed@users.noreply.github.com> | 2019-08-31 08:50:25 -0700 |
| commit | 1784d1bfac44a63bf343b6e2098f0cba81d58cb2 (patch) | |
| tree | 4c6410809c9fd54b064b7f5c79726a4558d119f2 /lib | |
| parent | 95477749629407e2a9e33c6ccf26ecc8b24ab07a (diff) | |
| download | qmk_firmware-1784d1bfac44a63bf343b6e2098f0cba81d58cb2.tar.gz qmk_firmware-1784d1bfac44a63bf343b6e2098f0cba81d58cb2.zip | |
Add support for passing files at the command line
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/python/qmk/cli/cformat.py | 20 |
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 | |||
| 6 | from milc import cli | 6 | from 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.") |
| 10 | def main(cli): | 11 | def 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 | ||
