Skip to content

Commit

Permalink
Remove StopReason (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
cariad authored Nov 28, 2021
1 parent 11c4eeb commit ab88c87
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ By default, Asking will -- naturally -- ask users for input.

To test your script without human interaction, you can pass directions into the state. This is a dictionary containing the value to respond with for each question key.

Note that is a flat dictionary, so keys should contain periods and not sub dictionaries.
Note that this is a flat dictionary, so keys should contain periods and not sub dictionaries.

## Actions

Expand Down
16 changes: 14 additions & 2 deletions asking/ask.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
from typing import Any

from asking.loaders import Loader
from asking.models import Script
from asking.protocols import StateProtocol
from asking.types import StopReason


def ask(loader: Loader, state: StateProtocol) -> StopReason:
def ask(loader: Loader, state: StateProtocol) -> Any:
"""
Loads and performs a script.
Arguments:
loader: Script loader.
state: Runtime state.
Returns:
Stop reason.
"""

script = Script(loader=loader, state=state)
return script.start()
17 changes: 14 additions & 3 deletions asking/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
from asking.types import StopReason
from typing import Any


class Stop(Exception):
def __init__(self, reason: StopReason) -> None:
"""
Raised to stop script execution.
Arguments:
reason: Reason for stopping.
"""

def __init__(self, reason: Any) -> None:
self._reason = reason
super().__init__(repr(reason))

@property
def reason(self) -> StopReason:
def reason(self) -> Any:
"""
Reason for stopping.
"""

return self._reason


Expand Down
12 changes: 10 additions & 2 deletions asking/models/script.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from typing import Any

from asking.exceptions import StageNotFoundError, Stop
from asking.loaders import Loader
from asking.models.stage import Stage
from asking.protocols import StateProtocol
from asking.types import StopReason


class Script:
Expand All @@ -16,7 +17,14 @@ def _get_stage(self, key: str) -> Stage:
raise StageNotFoundError(key)
return Stage(stage=stage, state=self._state)

def start(self) -> StopReason:
def start(self) -> Any:
"""
Performs the script.
Returns:
Reason for stopping.
"""

stage = self._get_stage("start")

try:
Expand Down
2 changes: 0 additions & 2 deletions asking/types.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from dataclasses import dataclass
from typing import Any, Dict, List, TypedDict, Union

StopReason = Any

AnyDict = Dict[Any, Any]

StageKey = str
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ <h3>Performing a script<a id="performing-a-script"></a></h3>
<h3>Unit testing<a id="unit-testing"></a></h3>
<p>By default, Asking will -- naturally -- ask users for input.</p>
<p>To test your script without human interaction, you can pass directions into the state. This is a dictionary containing the value to respond with for each question key.</p>
<p>Note that is a flat dictionary, so keys should contain periods and not sub dictionaries.</p>
<p>Note that this is a flat dictionary, so keys should contain periods and not sub dictionaries.</p>
<h2>Actions<a id="actions"></a></h2>
<h3>ask<a id="ask"></a></h3>
<div class="highlight"><pre><span></span><span class="nt">ask</span><span class="p">:</span>
Expand Down

0 comments on commit ab88c87

Please sign in to comment.