#!python
import argparse
from danger_decompyler.core import decompile_file

def main():
    parser = argparse.ArgumentParser(description="Decompile .pyc files to .py")
    parser.add_argument("pyc_file", help="Path to the .pyc file")
    parser.add_argument("-o", "--output", help="Output .py file (default: stdout)")
    args = parser.parse_args()

    try:
        source = decompile_file(args.pyc_file, args.output)
        if not args.output:
            print(source)
    except Exception as e:
        print(f"Error: {e}", file=sys.stderr)
        sys.exit(1)

if __name__ == "__main__":
    main()