From 3b05fb2053e1ae5e5f6b730d9b130696f23a5dcd Mon Sep 17 00:00:00 2001 From: Ethan Paul <24588726+enpaul@users.noreply.github.com> Date: Mon, 21 Dec 2020 21:08:38 -0500 Subject: [PATCH] Add simple dev server entrypoint --- imagemonk/__main__.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 imagemonk/__main__.py diff --git a/imagemonk/__main__.py b/imagemonk/__main__.py new file mode 100644 index 0000000..d4da854 --- /dev/null +++ b/imagemonk/__main__.py @@ -0,0 +1,43 @@ +"""Development server stub entrypoint + +Flask comes with a built-in development server. This entrypoint allows ``imagemonk`` +to be run directly to run the development server and expose some simple config options for ease of +access. Run the below command to start the server: + +:: + + python -m imagemonk + +In addition to the helpful CLI flags, the Flask development server run by this module will also +load any ``.env`` files in the current working directory when running the application. + +.. warning:: As the development server will tell you on startup, do not use this for production + deployments. +""" +import argparse +import sys + +from imagemonk.application import APPLICATION + + +# pylint: disable=invalid-name +def main(): + parser = argparse.ArgumentParser() + parser.add_argument( + "-b", + "--bind", + help="Address or socket to bind the server to", + default="127.0.0.1", + ) + parser.add_argument( + "-p", "--port", help="Port bind the server to", default=5000, type=int + ) + parser.add_argument( + "-D", "--debug", help="Run Flask in debug mode", action="store_true" + ) + args = parser.parse_args() + APPLICATION.run(host=args.bind, port=args.port, debug=args.debug, load_dotenv=True) + + +if __name__ == "__main__": + sys.exit(main())