mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-03-31 02:36:52 +00:00
Add check-yaml-filename-extension hook
This commit is contained in:
parent
5420c705a4
commit
1ea1ff2061
5 changed files with 66 additions and 0 deletions
29
pre_commit_hooks/check_yaml_filename_extension.py
Normal file
29
pre_commit_hooks/check_yaml_filename_extension.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import os
|
||||
from typing import Sequence
|
||||
|
||||
from pre_commit_hooks.util import cmd_output
|
||||
|
||||
|
||||
def main(argv: Sequence[str] | None = None) -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--extension', choices=['yaml', 'yml'], default='yaml')
|
||||
parser.add_argument('filenames', nargs='*', help='Filenames to check.')
|
||||
|
||||
args = parser.parse_args(argv)
|
||||
extension = f'.{args.extension}'
|
||||
|
||||
retval = 0
|
||||
for filename in args.filenames:
|
||||
if not filename.endswith(extension):
|
||||
new_filename = f'{os.path.splitext(filename)[0]}{extension}'
|
||||
cmd_output('git', 'mv', filename, new_filename)
|
||||
retval = 1
|
||||
|
||||
return retval
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
raise SystemExit(main())
|
||||
Loading…
Add table
Add a link
Reference in a new issue