import pyaxml
import click


@click.command()
@click.argument("input_file")
@click.argument("output_file")
def replace_debuggable(input_file, output_file):
    filename = input_file
    with open(filename, "rb") as f:
        # Read AXML and get XML object
        axml = pyaxml.AXML.from_axml(f.read())
        xml = axml.to_xml()
        debuggable = "{http://schemas.android.com/apk/res/android}debuggable"
        application = xml.find(f"./application")
        application.attrib[debuggable] = 'true'

        # Reencode XML to AXML
        axml_object = pyaxml.AXML()
        axml_object.from_xml(xml)
    # Rewrite the file
    with open(output_file, "wb") as f:
        f.write(axml_object.pack())


if __name__ == "__main__":
    replace_debuggable()
