From 98f70e5aa48ad0a78d47b053a682718746f25c88 Mon Sep 17 00:00:00 2001 From: Adam Collard Date: Wed, 29 May 2019 10:56:03 +0100 Subject: [PATCH] cli: Add --destructive-mode to clean Allow wrapper scripts to pass --destructive-mode to lifecycle commands --- snapcraft/cli/lifecycle.py | 12 ++++++++++-- tests/unit/commands/test_clean.py | 7 +++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/snapcraft/cli/lifecycle.py b/snapcraft/cli/lifecycle.py index a5154c8a8b..ff8b90e297 100644 --- a/snapcraft/cli/lifecycle.py +++ b/snapcraft/cli/lifecycle.py @@ -298,8 +298,14 @@ def pack(directory, output, **kwargs): required=False, help="Forces snapcraft to use LXD for this clean command.", ) +@click.option( + "--destructive-mode", + is_flag=True, + required=False, + help="Forces snapcraft to try and use the current host to clean.", +) @click.option("--unprime", is_flag=True, required=False, cls=HiddenOption) -def clean(parts, use_lxd, unprime): +def clean(parts, use_lxd, destructive_mode, unprime): """Remove a part's assets. \b @@ -307,7 +313,9 @@ def clean(parts, use_lxd, unprime): snapcraft clean snapcraft clean my-part """ - build_environment = get_build_environment(use_lxd=use_lxd) + build_environment = get_build_environment( + use_lxd=use_lxd, destructive_mode=destructive_mode + ) project = get_project(is_managed_host=build_environment.is_managed_host) if unprime and not build_environment.is_managed_host: diff --git a/tests/unit/commands/test_clean.py b/tests/unit/commands/test_clean.py index 8fc887e24f..f554785094 100644 --- a/tests/unit/commands/test_clean.py +++ b/tests/unit/commands/test_clean.py @@ -108,6 +108,13 @@ def test_unprime_fails(self): self.assertThat(result.exit_code, Equals(2)) + def test_destructive_mode(self): + self.make_snapcraft_yaml() + + result = self.run_command(["clean", "--destructive-mode"]) + + self.assertThat(result.exit_code, Equals(0)) + class CleanCommandPartsTestCase(CleanCommandBaseTestCase): def test_local_plugin_not_removed(self):