#!python

"""
Command-line script for docx2everything.
"""

import sys
import os

# Add the package directory to Python path if not installed
# Get the directory containing this script
script_dir = os.path.dirname(os.path.abspath(__file__))
# Get the project root (parent of bin/)
project_root = os.path.dirname(script_dir)
# Add to path if not already there
if project_root not in sys.path:
    sys.path.insert(0, project_root)

# Try to import, if fails, the error will be clear
try:
    from docx2everything.cli import main
except ImportError:
    import docx2everything
    # Fallback to old method if main() doesn't exist
    def main():
        args = docx2everything.process_args()
        if args.markdown:
            text = docx2everything.process_to_markdown(args.docx, args.img_dir)
        else:
            text = docx2everything.process(args.docx, args.img_dir)
        output = getattr(sys.stdout, 'buffer', sys.stdout)
        output.write(text.encode('utf-8'))

if __name__ == '__main__':
    main()
