import pyaxml
import click

try:
    from lxml import etree
except ImportError:
    import xml.etree.ElementTree as etree


@click.command()
@click.argument("input_file")
@click.argument("output_file")
def copy_axml(input_file, output_file):
    filename = input_file
    with open(filename, "rb") as f:
        # Read AXML
        axml = pyaxml.AXML.from_axml(f.read())
        xml = axml.to_xml()
    # Rewrite the file
    with open(output_file, "w") as f:
        f.write(etree.tostring(xml, encoding='unicode', pretty_print=True))


if __name__ == "__main__":
    copy_axml()
