diff options
Diffstat (limited to 'lib/python/qmk/cli/format/text.py')
| -rw-r--r-- | lib/python/qmk/cli/format/text.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/python/qmk/cli/format/text.py b/lib/python/qmk/cli/format/text.py new file mode 100644 index 000000000..e7e07b729 --- /dev/null +++ b/lib/python/qmk/cli/format/text.py | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | """Ensure text files have the proper line endings. | ||
| 2 | """ | ||
| 3 | from subprocess import CalledProcessError | ||
| 4 | |||
| 5 | from milc import cli | ||
| 6 | |||
| 7 | |||
| 8 | @cli.subcommand("Ensure text files have the proper line endings.", hidden=True) | ||
| 9 | def format_text(cli): | ||
| 10 | """Ensure text files have the proper line endings. | ||
| 11 | """ | ||
| 12 | try: | ||
| 13 | file_list_cmd = cli.run(['git', 'ls-files', '-z'], check=True) | ||
| 14 | except CalledProcessError as e: | ||
| 15 | cli.log.error('Could not get file list: %s', e) | ||
| 16 | exit(1) | ||
| 17 | except Exception as e: | ||
| 18 | cli.log.error('Unhandled exception: %s: %s', e.__class__.__name__, e) | ||
| 19 | cli.log.exception(e) | ||
| 20 | exit(1) | ||
| 21 | |||
| 22 | dos2unix = cli.run(['xargs', '-0', 'dos2unix'], stdin=None, input=file_list_cmd.stdout) | ||
| 23 | |||
| 24 | if dos2unix.returncode != 0: | ||
| 25 | print(dos2unix.stderr) | ||
| 26 | |||
| 27 | return dos2unix.returncode | ||
