diff --git a/pre_commit_hooks/xml_format.py b/pre_commit_hooks/xml_format.py index 44f6442..855f4cf 100644 --- a/pre_commit_hooks/xml_format.py +++ b/pre_commit_hooks/xml_format.py @@ -1,11 +1,12 @@ #!C:/miniconda/envs/plc-pre-commit/python.exe import argparse - from lxml import etree +TAB_WIDTH = 2 + -def fix_file(filename): +def fix_file(filename, tab_width=TAB_WIDTH): # lxml throws encoding errors unless we work in binary mode with open(filename, 'rb') as fd: original_xml = fd.read() @@ -14,6 +15,7 @@ def fix_file(filename): # xmllint is cross-platform but pre-commit does not help us set it up xml_parser = etree.XMLParser(remove_blank_text=True) parse_tree = etree.XML(original_xml, parser=xml_parser).getroottree() + etree.indent(parse_tree, space=" " * tab_width) new_xml = etree.tostring(parse_tree, pretty_print=True, xml_declaration=True, @@ -34,6 +36,7 @@ def main(args=None): if args is None: parser = argparse.ArgumentParser() parser.add_argument('filenames', nargs='*') + parser.add_argument('--tab-width', type=int, default=TAB_WIDTH) args = parser.parse_args() try: for filename in args.filenames: