summaryrefslogtreecommitdiffstats
path: root/pre_commit_hooks/check_toml.py
diff options
context:
space:
mode:
Diffstat (limited to 'pre_commit_hooks/check_toml.py')
-rw-r--r--pre_commit_hooks/check_toml.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/pre_commit_hooks/check_toml.py b/pre_commit_hooks/check_toml.py
new file mode 100644
index 0000000..f623e68
--- /dev/null
+++ b/pre_commit_hooks/check_toml.py
@@ -0,0 +1,24 @@
+import argparse
+from typing import Optional
+from typing import Sequence
+
+import toml
+
+
+def main(argv: Optional[Sequence[str]] = None) -> 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:
+ toml.load(filename)
+ except toml.TomlDecodeError as exc:
+ print(f'{filename}: {exc}')
+ retval = 1
+ return retval
+
+
+if __name__ == '__main__':
+ raise SystemExit(main())