-
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI: Re-add command line interface (2024)
Install: pip install 'responder[cli]' The CLI is an optional subsystem from now on.
- Loading branch information
1 parent
2595568
commit a6d048e
Showing
5 changed files
with
73 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""Responder. | ||
Usage: | ||
responder | ||
responder run [--build] <module> | ||
responder build | ||
responder --version | ||
Options: | ||
-h --help Show this screen. | ||
-v --version Show version. | ||
""" | ||
|
||
import subprocess | ||
|
||
import docopt | ||
|
||
from .__version__ import __version__ | ||
|
||
|
||
def cli(): | ||
""" | ||
CLI interface handler of the Responder package. | ||
""" | ||
args = docopt.docopt(__doc__, argv=None, version=__version__, options_first=False) | ||
|
||
module = args["<module>"] | ||
build = args["build"] or args["--build"] | ||
run = args["run"] | ||
|
||
if build: | ||
# S603, S607 are suppressed as we're using fixed arguments, not user input | ||
subprocess.check_call(["npm", "run", "build"]) # noqa: S603, 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import subprocess | ||
|
||
import pytest | ||
|
||
from responder.__version__ import __version__ | ||
|
||
pytest.importorskip("docopt", reason="docopt-ng package not installed") | ||
|
||
|
||
def test_cli_version(capfd): | ||
# S603, S607 are suppressed as we're using fixed arguments, not user input | ||
try: | ||
subprocess.check_call(["responder", "--version"]) # noqa: S603, S607 | ||
except subprocess.CalledProcessError as ex: | ||
pytest.fail(f"CLI command failed with exit code {ex.returncode}") | ||
|
||
stdout = capfd.readouterr().out.strip() | ||
assert stdout == __version__ |