mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-04 19:26:52 +00:00
Add check-toml hook
This commit is contained in:
parent
b7abd18ceb
commit
ae70f7e3c7
3 changed files with 36 additions and 0 deletions
28
pre_commit_hooks/check_toml.py
Normal file
28
pre_commit_hooks/check_toml.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
from typing import Optional
|
||||
from typing import Sequence
|
||||
|
||||
import pytoml
|
||||
|
||||
|
||||
def main(argv=None): # type: (Optional[Sequence[str]]) -> int
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('filenames', nargs='*', help='Filenames to check.')
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
retval = 0
|
||||
for filename in args.filenames:
|
||||
try:
|
||||
with open(filename) as f:
|
||||
pytoml.load(f)
|
||||
except pytoml.TomlError as exc:
|
||||
print(exc)
|
||||
retval = 1
|
||||
return retval
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
Loading…
Add table
Add a link
Reference in a new issue