summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngelos Evripiotis <jevripiotis@bloomberg.net>2018-10-19 18:48:38 +0100
committerAngelos Evripiotis <jevripiotis@bloomberg.net>2018-11-20 11:43:49 +0000
commit7ae3a3d2433f0909a6c4d43655b8fff95fb8c318 (patch)
tree4ae64f1775a4f82de378bb4d87e85ac025a4cea4
parent27ca65931d3cf6cf897b623f21ba2363f3c54029 (diff)
downloadbuildstream-7ae3a3d2433f0909a6c4d43655b8fff95fb8c318.tar.gz
Add prompt.workspace-... options
Provide options in project.conf to disable the 'Are you sure ...' prompts when making destructive changes: - Add prompt.really-workspace-close-remove-dir - Add prompt.really-workspace-reset-hard Add a NEWS item for these.
-rw-r--r--NEWS8
-rw-r--r--buildstream/_context.py17
-rw-r--r--buildstream/_frontend/cli.py4
-rw-r--r--buildstream/data/userconfig.yaml16
4 files changed, 39 insertions, 6 deletions
diff --git a/NEWS b/NEWS
index 584f1d6d8..544435dc7 100644
--- a/NEWS
+++ b/NEWS
@@ -45,9 +45,11 @@ 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 The buildstream.conf file learned new 'prompt.auto-init',
+ 'prompt.really-workspace-close-remove-dir', and
+ 'prompt.really-workspace-reset-hard' options. These allow users to suppress
+ certain confirmation prompts, e.g. double-checking that the user meant to
+ run the command as typed.
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
diff --git a/buildstream/_context.py b/buildstream/_context.py
index 9bb261b62..7a47a30d3 100644
--- a/buildstream/_context.py
+++ b/buildstream/_context.py
@@ -114,6 +114,14 @@ class Context():
# invoked outside of a directory where we can resolve the project.
self.prompt_auto_init = None
+ # Boolean, whether we double-check with the user that they meant to
+ # remove a workspace directory.
+ self.prompt_workspace_close_remove_dir = None
+
+ # Boolean, whether we double-check with the user that they meant to do
+ # a hard reset of a workspace, potentially losing changes.
+ self.prompt_workspace_reset_hard = None
+
# Whether elements must be rebuilt when their dependencies have changed
self._strict_build_plan = None
@@ -235,9 +243,16 @@ class Context():
#
prompt = _yaml.node_get(
defaults, Mapping, 'prompt')
- _yaml.node_validate(prompt, ['auto-init'])
+ _yaml.node_validate(prompt, [
+ 'auto-init', 'really-workspace-close-remove-dir',
+ 'really-workspace-reset-hard',
+ ])
self.prompt_auto_init = _node_get_option_str(
prompt, 'auto-init', ['ask', 'no']) == 'ask'
+ self.prompt_workspace_close_remove_dir = _node_get_option_str(
+ prompt, 'really-workspace-close-remove-dir', ['ask', 'yes']) == 'ask'
+ self.prompt_workspace_reset_hard = _node_get_option_str(
+ prompt, 'really-workspace-reset-hard', ['ask', 'yes']) == 'ask'
# Load per-projects overrides
self._project_overrides = _yaml.node_get(defaults, Mapping, 'projects', default_value={})
diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index 725dc8c1d..92abd96e8 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -772,7 +772,7 @@ def workspace_close(app, remove_dir, all_, elements):
if nonexisting:
raise AppError("Workspace does not exist", detail="\n".join(nonexisting))
- if app.interactive and remove_dir:
+ if app.interactive and remove_dir and app.context.prompt_workspace_close_remove_dir:
if not click.confirm('This will remove all your changes, are you sure?'):
click.echo('Aborting', err=True)
sys.exit(-1)
@@ -806,7 +806,7 @@ def workspace_reset(app, soft, track_, all_, elements):
if all_ and not app.stream.workspace_exists():
raise AppError("No open workspaces to reset")
- if app.interactive and not soft:
+ if app.interactive and not soft and app.context.prompt_workspace_reset_hard:
if not click.confirm('This will remove all your changes, are you sure?'):
click.echo('Aborting', err=True)
sys.exit(-1)
diff --git a/buildstream/data/userconfig.yaml b/buildstream/data/userconfig.yaml
index 0e6581cb7..dfc18545e 100644
--- a/buildstream/data/userconfig.yaml
+++ b/buildstream/data/userconfig.yaml
@@ -116,3 +116,19 @@ prompt:
# no - Never create the project.
#
auto-init: ask
+
+ # Whether to really proceed with 'bst workspace close --remove-dir' removing
+ # a workspace directory, potentially losing changes.
+ #
+ # ask - Ask the user if they are sure.
+ # yes - Always remove, without asking.
+ #
+ really-workspace-close-remove-dir: ask
+
+ # Whether to really proceed with 'bst workspace reset' doing a hard reset of
+ # a workspace, potentially losing changes.
+ #
+ # ask - Ask the user if they are sure.
+ # yes - Always hard reset, without asking.
+ #
+ really-workspace-reset-hard: ask