Skip to content
Snippets Groups Projects
Commit e2efc8c0 authored by Angelos Evripiotis's avatar Angelos Evripiotis
Browse files

BREAK: make destructive action scripts consistent

Make sure that BuildStream doesn't behave differently about destructive
things just because it's in non-interactive mode, e.g. being run from a
misconfigured workflow helper script.

By default, assume that users opt-out of destructive actions if we
are unable to ask them. For the currently affected commands, this means
aborting completely.

This seems less surprising than doing the destructive action instead.
Also, for folks that find the new behaviour surprising, at least they
don't lose work.

Introduce an '--assume-yes' option to affected commands to override this
behaviour.

If a command aborts for this reason, print a message suggesting the use
of '--assume-yes'. Don't mention the corresponding 'prompt.*' options
that also control this behaviour - this would hinder portability of
scripts between users with different settings.

This affects:

- bst workspace close --remove-dir
- bst workspace reset

Closes #744, #726.
parent 84317251
No related branches found
No related tags found
No related merge requests found
Pipeline #36888188 failed
......@@ -713,10 +713,12 @@ def workspace_open(app, no_checkout, force, track_, element, directory):
help="Remove the path that contains the closed workspace")
@click.option('--all', '-a', 'all_', default=False, is_flag=True,
help="Close all open workspaces")
@click.option('--assume-yes', '-y', default=False, is_flag=True,
help="Assume 'yes' to confirmation of destructive changes")
@click.argument('elements', nargs=-1,
type=click.Path(readable=False))
@click.pass_obj
def workspace_close(app, remove_dir, all_, elements):
def workspace_close(app, remove_dir, all_, assume_yes, elements):
"""Close a workspace"""
if not (all_ or elements):
......@@ -743,9 +745,15 @@ 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 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)
if remove_dir and not assume_yes and app.context.prompt_workspace_close_remove_dir:
if app.interactive:
if not click.confirm('This will remove all your changes, are you sure?'):
click.echo('Aborting', err=True)
sys.exit(-1)
else:
click.echo(
"Aborting since non-interactive and destructive action requested.", err=True)
click.echo("Please use the '--assume-yes' option to override.", err=True)
sys.exit(-1)
for element_name in elements:
......@@ -762,10 +770,12 @@ def workspace_close(app, remove_dir, all_, elements):
help="Track and fetch the latest source before resetting")
@click.option('--all', '-a', 'all_', default=False, is_flag=True,
help="Reset all open workspaces")
@click.option('--assume-yes', '-y', default=False, is_flag=True,
help="Assume 'yes' to confirmation of destructive changes")
@click.argument('elements', nargs=-1,
type=click.Path(readable=False))
@click.pass_obj
def workspace_reset(app, soft, track_, all_, elements):
def workspace_reset(app, soft, track_, all_, assume_yes, elements):
"""Reset a workspace to its original state"""
# Check that the workspaces in question exist
......@@ -777,9 +787,15 @@ 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 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)
if not soft and not assume_yes and app.context.prompt_workspace_reset_hard:
if app.interactive:
if not click.confirm('This will remove all your changes, are you sure?'):
click.echo('Aborting', err=True)
sys.exit(-1)
else:
click.echo(
"Aborting since non-interactive and destructive action requested.", err=True)
click.echo("Please use the '--assume-yes' option to override.", err=True)
sys.exit(-1)
if all_:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment