import argparse
import pkg_resources

from squeegee import formatter
from squeegee import harvester


def main():
    parser = argparse.ArgumentParser(description=
        'collect all the route endpoint docstrings for a flask app')
    parser.add_argument('app', help='the flask app to harvest')
    parser.add_argument('-o', '--out', dest='out', help=
        'an optional file to store output.')
    args = parser.parse_args()
    app = pkg_resources.EntryPoint.parse("x=%s" % args.app).load(False)()
    docs = formatter.markdown(args.app, harvester.collect(app))
    if args.out:
        with open(args.out, 'w') as out:
            out.write(docs)
    else:
        print(docs)
