Skip to content

Commit f210f64

Browse files
authored
Merge pull request #269 from Oxid15/artifact_rm_confirmation
Add simple confirmation before removing artifacts
2 parents 4c07de0 + ec7de28 commit f210f64

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

cascade/cli/artifact.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class RemoveResult:
3535
3636
FAIL - something went wrong when removing a file
3737
"""
38+
3839
status: Literal["OKAY", "MISS", "FAIL"]
3940
path: Optional[str] = None
4041
traceback: Optional[str] = None
@@ -101,11 +102,16 @@ def artifact(ctx):
101102

102103

103104
@artifact.command("rm")
105+
@click.option("-y", is_flag=True, expose_value=True, help="Confirm")
104106
@click.pass_context
105-
def artifact_rm(ctx):
107+
def artifact_rm(ctx, y):
106108
"""
107109
Remove artifacts from the whole container recursively
108110
"""
111+
112+
if not y:
113+
click.confirm("Confirm?", abort=True)
114+
109115
results_list = []
110116
flat_results = []
111117
if ctx.obj["type"] == "model":

cascade/tests/cli/test_artifact.py

+7-15
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,12 @@ def test_rm_model(tmp_path_str):
4242
model.save_artifact(artifact_path)
4343
MetaHandler.write_dir(td, model.get_meta())
4444

45-
assert os.path.exists(
46-
os.path.join(td, "artifacts", "artifact.txt")
47-
)
45+
assert os.path.exists(os.path.join(td, "artifacts", "artifact.txt"))
4846

49-
result = runner.invoke(cli, args=["artifact", "rm"])
47+
result = runner.invoke(cli, args=["artifact", "rm", "-y"])
5048
assert result.exit_code == 0
5149

52-
assert not os.path.exists(
53-
os.path.join(td, "artifacts", "artifact.txt")
54-
)
50+
assert not os.path.exists(os.path.join(td, "artifacts", "artifact.txt"))
5551

5652

5753
def test_rm_model_error(tmp_path_str):
@@ -63,18 +59,14 @@ def test_rm_model_error(tmp_path_str):
6359
model.save_artifact(artifact_path)
6460
MetaHandler.write_dir(td, model.get_meta())
6561

66-
assert os.path.exists(
67-
os.path.join(td, "artifacts", "artifact.txt")
68-
)
62+
assert os.path.exists(os.path.join(td, "artifacts", "artifact.txt"))
6963

70-
with patch('os.remove') as mocked_remove:
64+
with patch("os.remove") as mocked_remove:
7165
mocked_remove.side_effect = OSError()
7266

73-
result = runner.invoke(cli, args=["artifact", "rm"])
67+
result = runner.invoke(cli, args=["artifact", "rm", "-y"])
7468
assert result.exit_code == 0
7569

7670
mocked_remove.assert_called_once_with(os.path.join(td, "artifacts", "artifact.txt"))
7771

78-
assert os.path.exists(
79-
os.path.join(td, "artifacts", "artifact.txt")
80-
)
72+
assert os.path.exists(os.path.join(td, "artifacts", "artifact.txt"))

0 commit comments

Comments
 (0)