diff options
author | Angelos Evripiotis <jevripiotis@bloomberg.net> | 2018-10-19 17:55:51 +0100 |
---|---|---|
committer | Angelos Evripiotis <jevripiotis@bloomberg.net> | 2018-11-16 14:08:15 +0000 |
commit | d1ed960a6cc6ce31cb055ece5d49f949dfd47a97 (patch) | |
tree | 6014ceac39bab3b4a463b39e89a5152d36ac587e | |
parent | d2cfcbcd394efa92a330e9aa108ec12e71f4408e (diff) | |
download | buildstream-d1ed960a6cc6ce31cb055ece5d49f949dfd47a97.tar.gz |
Add prompt.auto-init buildstream.conf option
Provide an option in buildstream.conf to disable the 'Would you like to
...' prompt when we cannot resolve a project.
Some users prefer not to be interrupted by such prompts, so pave the way
to creating options to disable all those that might get in the way.
Follow the example of the advice.* options 'git-config', and create a
namespace for these UI options grouped by behaviour, rather than an
over-reaching 'ui.*' namespace. In later work perhaps we'll also add
'advice.*' options.
Add a NEWS item for this.
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | buildstream/_context.py | 20 | ||||
-rw-r--r-- | buildstream/_frontend/app.py | 7 | ||||
-rw-r--r-- | buildstream/data/userconfig.yaml | 16 |
4 files changed, 43 insertions, 4 deletions
@@ -45,6 +45,10 @@ buildstream 1.3.1 instead of just a specially-formatted build-root with a `root` and `scratch` subdirectory. + o The buildstream.conf file learned a new 'prompt.auto-init' option. This + allows users to suppress prompts for automatically running 'bst init' if we + were unable to resolve the project. + ================= buildstream 1.1.5 diff --git a/buildstream/_context.py b/buildstream/_context.py index f5c4e1f94..a8195782f 100644 --- a/buildstream/_context.py +++ b/buildstream/_context.py @@ -104,6 +104,10 @@ class Context(): # What to do when a build fails in non interactive mode self.sched_error_action = 'continue' + # Boolean, whether to offer to create a project for the user, if we are + # invoked outside of a directory where we can resolve the project. + self.prompt_auto_init = None + # Whether elements must be rebuilt when their dependencies have changed self._strict_build_plan = None @@ -160,7 +164,7 @@ class Context(): _yaml.node_validate(defaults, [ 'sourcedir', 'builddir', 'artifactdir', 'logdir', 'scheduler', 'artifacts', 'logging', 'projects', - 'cache' + 'cache', 'prompt' ]) for directory in ['sourcedir', 'builddir', 'artifactdir', 'logdir']: @@ -213,6 +217,20 @@ class Context(): self.sched_pushers = _yaml.node_get(scheduler, int, 'pushers') self.sched_network_retries = _yaml.node_get(scheduler, int, 'network-retries') + # Load prompt preferences + # + # We convert string options to booleans here, so we can be both user + # and coder-friendly. The string options are worded to match the + # responses the user would give at the cli, for least surprise. The + # booleans are converted here because it's easiest to eyeball that the + # strings are right. + # + prompt = _yaml.node_get( + defaults, Mapping, 'prompt') + _yaml.node_validate(prompt, ['auto-init']) + self.prompt_auto_init = _node_get_option_str( + prompt, 'auto-init', ['ask', 'no']) == 'ask' + # Load per-projects overrides self._project_overrides = _yaml.node_get(defaults, Mapping, 'projects', default_value={}) diff --git a/buildstream/_frontend/app.py b/buildstream/_frontend/app.py index 6b292a44a..874fecc07 100644 --- a/buildstream/_frontend/app.py +++ b/buildstream/_frontend/app.py @@ -221,9 +221,10 @@ class App(): # 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) + if self.context.prompt_auto_init: + click.echo("", err=True) + if click.confirm("Would you like to create a new project here?"): + self.init_project(None) self._error_exit(e, "Error loading project") diff --git a/buildstream/data/userconfig.yaml b/buildstream/data/userconfig.yaml index efe419cfc..b52b4a0e0 100644 --- a/buildstream/data/userconfig.yaml +++ b/buildstream/data/userconfig.yaml @@ -97,3 +97,19 @@ logging: [%{elapsed}][%{key}][%{element}] %{action} %{message} +# +# Prompt overrides +# +# Here you can suppress 'are you sure?' and other kinds of prompts by supplying +# override values. Note that e.g. 'yes' and 'no' have the same meaning here as +# they do in the actual cli prompt. +# +prompt: + + # Whether to create a project with 'bst init' if we are invoked outside of a + # directory where we can resolve the project. + # + # ask - Prompt the user to choose. + # no - Never create the project. + # + auto-init: ask |