diff --git a/README.md b/README.md index 9d773c5..aaaff6a 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ pytest mapshader/tests -sv #### Run Flask Server ```bash conda activate mapshader -python mapshader/flask_app.py +mapshader serve >>> * Serving Flask app "flask_app" (lazy loading) >>> * Environment: production @@ -96,7 +96,7 @@ This configuration file can then be passed to the flask server upon startup: ```bash conda activate mapshader -python mapshader/flask_app.py -f my_services.yaml +mapshader serve my_services.yaml >>> * Serving Flask app "flask_app" (lazy loading) >>> * Environment: production diff --git a/mapshader/commands/serve.py b/mapshader/commands/serve.py new file mode 100644 index 0000000..2e3c451 --- /dev/null +++ b/mapshader/commands/serve.py @@ -0,0 +1,54 @@ +import click + +from ..flask_app import create_app + + +@click.command( + context_settings=dict(help_option_names=['-h', '--help']), + short_help='Start default mapshader server using Flask', + help=( + 'Start default mapshader server using Flask' + ), +) +@click.argument( + 'config_yaml', + type=str, + required=False, +) +@click.option( + '--host', + 'host', + default='0.0.0.0', + type=str, + help='Host of Flask server', +) +@click.option( + '--port', + 'port', + default=5000, + type=int, + help='Port number of Flask server', +) +@click.option( + '--glob', + 'glob', + required=False, + type=str, + help='Filter services to start based on glob', +) +@click.option( + '--debug', + 'debug', + is_flag=True, + default=False, + help='Run server in debug mode', +) +def serve(config_yaml=None, host='0.0.0.0', port=5000, glob=None, debug=False): + + from os import path + + if config_yaml: + config_yaml = path.abspath(path.expanduser(config_yaml)) + + create_app(config_yaml, contains=glob).run( + host=host, port=port, debug=debug) diff --git a/setup.py b/setup.py index 840f70f..e9dacd0 100644 --- a/setup.py +++ b/setup.py @@ -59,6 +59,7 @@ build_raster_overviews=mapshader.commands.build_raster_overviews:build_raster_overviews examples=mapshader.commands.examples:examples tif_to_netcdf=mapshader.commands.tif_to_netcdf:tif_to_netcdf + serve=mapshader.commands.serve:serve ''', )