diff options
-rw-r--r-- | NEWS | 8 | ||||
-rw-r--r-- | buildstream/_context.py | 17 | ||||
-rw-r--r-- | buildstream/_frontend/cli.py | 4 | ||||
-rw-r--r-- | buildstream/data/userconfig.yaml | 16 |
4 files changed, 39 insertions, 6 deletions
@@ -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. ================= diff --git a/buildstream/_context.py b/buildstream/_context.py index a8195782f..b63b17e80 100644 --- a/buildstream/_context.py +++ b/buildstream/_context.py @@ -108,6 +108,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 @@ -227,9 +235,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 85632959f..a195bdaec 100644 --- a/buildstream/_frontend/cli.py +++ b/buildstream/_frontend/cli.py @@ -743,7 +743,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) @@ -777,7 +777,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 b52b4a0e0..10f539b15 100644 --- a/buildstream/data/userconfig.yaml +++ b/buildstream/data/userconfig.yaml @@ -113,3 +113,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 |