Commit 27ca6593 authored by Angelos Evripiotis's avatar Angelos Evripiotis

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.
parent b81c4333
......@@ -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.
o Due to the element `build tree` being cached in the respective artifact their
size in some cases has significantly increased. In *most* cases the build trees
are not utilised when building targets, as such by default bst 'pull' & 'build'
......
......@@ -110,6 +110,10 @@ class Context():
# Whether or not to attempt to pull build trees globally
self.pull_buildtrees = None
# 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
......@@ -165,7 +169,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']:
......@@ -221,6 +225,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={})
......
......@@ -222,9 +222,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")
......
......@@ -100,3 +100,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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment