summaryrefslogtreecommitdiff
path: root/src/buildstream/_frontend
diff options
context:
space:
mode:
authorBenjamin Schubert <contact@benschubert.me>2019-07-26 16:06:03 +0100
committerBenjamin Schubert <contact@benschubert.me>2019-07-29 10:42:02 +0100
commitb632e471f1ca4764c15534006294f7dc0b842b69 (patch)
tree0b7a1782b8e7054ba2bfb05aeeedb6f0c1e26dd6 /src/buildstream/_frontend
parent0f074dd37524047cb53214be5c0f10436d3abb1d (diff)
downloadbuildstream-b632e471f1ca4764c15534006294f7dc0b842b69.tar.gz
context: Move scheduler actions to an Enum
Also add helpers for the cli to be able to represent 'FastEnum' directly
Diffstat (limited to 'src/buildstream/_frontend')
-rw-r--r--src/buildstream/_frontend/app.py7
-rw-r--r--src/buildstream/_frontend/cli.py17
2 files changed, 20 insertions, 4 deletions
diff --git a/src/buildstream/_frontend/app.py b/src/buildstream/_frontend/app.py
index 76d3b8dde..379ed4b7f 100644
--- a/src/buildstream/_frontend/app.py
+++ b/src/buildstream/_frontend/app.py
@@ -37,6 +37,7 @@ from .._exceptions import BstError, StreamError, LoadError, LoadErrorReason, App
from .._message import Message, MessageType, unconditional_messages
from .._stream import Stream
from .._versions import BST_FORMAT_VERSION
+from ..types import _SchedulerErrorAction
from .. import node
# Import frontend assets
@@ -597,11 +598,11 @@ class App():
# Handle non interactive mode setting of what to do when a job fails.
if not self._interactive_failures:
- if self.context.sched_error_action == 'terminate':
+ if self.context.sched_error_action == _SchedulerErrorAction.TERMINATE:
self.stream.terminate()
- elif self.context.sched_error_action == 'quit':
+ elif self.context.sched_error_action == _SchedulerErrorAction.QUIT:
self.stream.quit()
- elif self.context.sched_error_action == 'continue':
+ elif self.context.sched_error_action == _SchedulerErrorAction.CONTINUE:
pass
return
diff --git a/src/buildstream/_frontend/cli.py b/src/buildstream/_frontend/cli.py
index 12b9439cf..5de02918f 100644
--- a/src/buildstream/_frontend/cli.py
+++ b/src/buildstream/_frontend/cli.py
@@ -10,10 +10,25 @@ from .. import _yaml
from .._exceptions import BstError, LoadError, AppError
from .._versions import BST_FORMAT_VERSION
from .complete import main_bashcomplete, complete_path, CompleteUnhandled
+from ..types import _SchedulerErrorAction
from ..utils import _get_compression, UtilError
##################################################################
+# Helper classes and methods for Click #
+##################################################################
+
+class FastEnumType(click.Choice):
+
+ def __init__(self, enum):
+ self._enum = enum
+ super().__init__(enum.values())
+
+ def convert(self, value, param, ctx):
+ return self._enum(super().convert(value, param, ctx))
+
+
+##################################################################
# Override of click's main entry point #
##################################################################
@@ -234,7 +249,7 @@ def print_version(ctx, param, value):
type=click.Path(file_okay=False, readable=True),
help="Project directory (default: current directory)")
@click.option('--on-error', default=None,
- type=click.Choice(['continue', 'quit', 'terminate']),
+ type=FastEnumType(_SchedulerErrorAction),
help="What to do when an error is encountered")
@click.option('--fetchers', type=click.INT, default=None,
help="Maximum simultaneous download tasks")