From 14bd48959b433efb0134ceae1f333abd096c209d Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Tue, 16 Oct 2018 05:14:48 -0700 Subject: [PATCH] CLI build command --- responder/__init__.py | 3 ++- responder/cli.py | 42 ++++++++++++++++++++++++++++++++++++++++++ responder/core.py | 2 ++ setup.py | 3 +++ 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 responder/cli.py diff --git a/responder/__init__.py b/responder/__init__.py index c573a7ae..6ae3bdfc 100644 --- a/responder/__init__.py +++ b/responder/__init__.py @@ -1,7 +1,8 @@ from . import ext -from .core import API, Request, Response +from .core import API, Request, Response, cli __all__ = [ + "cli", "API", "Request", "Response", diff --git a/responder/cli.py b/responder/cli.py new file mode 100644 index 00000000..3ed7da88 --- /dev/null +++ b/responder/cli.py @@ -0,0 +1,42 @@ +"""Responder. + +Usage: + responder + responder run [--build] [--debug] + responder build + responder --version + +Options: + -h --help Show this screen. + -v --version Show version. + +""" + +import os + +import docopt + +from .__version__ import __version__ + + +def cli(): + args = docopt.docopt(__doc__, argv=None, version=__version__, options_first=False) + + module = args[""] + build = args["build"] or args["--build"] + run = args["run"] + + if build: + os.system("npm run build") # noqa: S605, S607 + + if run: + split_module = module.split(":") + + if len(split_module) > 1: + module = split_module[0] + prop = split_module[1] + else: + prop = "api" + + app = __import__(module) + getattr(app, prop).run() diff --git a/responder/core.py b/responder/core.py index 8cbed856..054df029 100644 --- a/responder/core.py +++ b/responder/core.py @@ -1,7 +1,9 @@ from .api import API +from .cli import cli from .models import Request, Response __all__ = [ + "cli", "API", "Request", "Response", diff --git a/setup.py b/setup.py index c22d3b5d..cf112361 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,9 @@ required = [ "aiofiles", "apispec>=1.0.0b1", + "asgiref", "chardet", + "docopt-ng", "marshmallow", "requests", "requests-toolbelt", @@ -75,6 +77,7 @@ def run(self): url="https://github.com/kennethreitz/responder", packages=find_packages(exclude=["tests"]), package_data={}, + entry_points={"console_scripts": ["responder=responder.cli:cli"]}, python_requires=">=3.6", setup_requires=[], install_requires=required,