-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
shell
command to Protean CLI (#402)
The `shell` command accepts a domain path as an argument. A domain context is activated, and the domain instance is imported. The shell also preloads all domain elements to allow free-form domain exploration.
- Loading branch information
Showing
13 changed files
with
456 additions
and
98 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,26 @@ | ||
import subprocess | ||
|
||
import typer | ||
|
||
app = typer.Typer(no_args_is_help=True) | ||
|
||
|
||
@app.callback() | ||
def callback(): | ||
""" | ||
If we want to create a CLI app with one single command but | ||
still want it to be a command/subcommand, we need to add a callback. | ||
This can be removed when we have more than one command/subcommand. | ||
https://typer.tiangolo.com/tutorial/commands/one-or-multiple/#one-command-and-one-callback | ||
""" | ||
|
||
|
||
@app.command() | ||
def preview(): | ||
"""Run a live preview server""" | ||
try: | ||
subprocess.call(["mkdocs", "serve"]) | ||
except KeyboardInterrupt: | ||
pass |
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,10 @@ | ||
from typer.testing import CliRunner | ||
|
||
from protean.cli.docs import app | ||
|
||
|
||
def test_main(): | ||
runner = CliRunner() | ||
result = runner.invoke(app) | ||
|
||
assert result.exit_code == 0 |
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,48 @@ | ||
import os | ||
import sys | ||
|
||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from typer.testing import CliRunner | ||
|
||
from protean.cli import app | ||
from protean.exceptions import NoDomainException | ||
from tests.shared import change_working_directory_to | ||
|
||
runner = CliRunner() | ||
|
||
|
||
class TestShellCommand: | ||
@pytest.fixture(autouse=True) | ||
def reset_path(self): | ||
"""Reset sys.path after every test run""" | ||
original_path = sys.path[:] | ||
cwd = Path.cwd() | ||
|
||
yield | ||
|
||
sys.path[:] = original_path | ||
os.chdir(cwd) | ||
|
||
def test_shell_command_success(self): | ||
change_working_directory_to("test7") | ||
|
||
args = ["shell", "publishing.py"] | ||
|
||
# Run the shell command | ||
result = runner.invoke(app, args) | ||
|
||
# Assertions | ||
print(result.output) | ||
assert result.exit_code == 0 | ||
|
||
def test_shell_command_raises_no_domain_exception_when_no_domain_is_found(self): | ||
change_working_directory_to("test7") | ||
|
||
args = ["shell", "foobar"] | ||
|
||
# Run the shell command and expect it to raise an exception | ||
with pytest.raises(NoDomainException): | ||
runner.invoke(app, args, catch_exceptions=False) |
Oops, something went wrong.