diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-04-08 21:54:08 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-04-08 21:57:01 +0900 |
commit | 1f57e598a3f286716f197fb4a10f2515ce562ed8 (patch) | |
tree | 496526820fc493df9bc1b90add5363ad4e41b916 | |
parent | 96af6dd5ae9743c7405cbfd99c929701c023f3e5 (diff) | |
download | buildstream-1f57e598a3f286716f197fb4a10f2515ce562ed8.tar.gz |
_frontend/app.py: Automatically launch interactive `bst init` when project.conf is absent
When running a command where a project.conf does not exist, ask the
user if they would like to interactively create a project in the
said directory.
This is a part of issue #342
-rw-r--r-- | buildstream/_frontend/app.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/buildstream/_frontend/app.py b/buildstream/_frontend/app.py index e9e5f5eeb..d5c98564a 100644 --- a/buildstream/_frontend/app.py +++ b/buildstream/_frontend/app.py @@ -36,7 +36,7 @@ from .. import Scope, Consistency # Import various buildstream internals from .._context import Context from .._project import Project -from .._exceptions import BstError, PipelineError, LoadError, AppError +from .._exceptions import BstError, PipelineError, LoadError, LoadErrorReason, AppError from .._message import Message, MessageType, unconditional_messages from .._pipeline import Pipeline from .._scheduler import Scheduler @@ -185,6 +185,18 @@ class App(): try: self.project = Project(directory, self.context, cli_options=self.main_options['option']) + except LoadError as e: + + # Let's automatically start a `bst init` session in this case + if e.reason == LoadErrorReason.MISSING_PROJECT_CONF and self.interactive: + click.echo("A project was not detected in the directory: {}".format(directory), err=True) + click.echo("", err=True) + if click.confirm("Would you like to create a new project here ?"): + self.init_project(None) + + self.print_error(e, "Error loading project") + sys.exit(-1) + except BstError as e: self.print_error(e, "Error loading project") sys.exit(-1) |