ask user before start destroying

This commit is contained in:
thilko
2013-11-23 21:01:53 +01:00
parent 44527850f6
commit 69c38774fe
2 changed files with 11 additions and 7 deletions

View File

@@ -232,6 +232,7 @@ class Homesick < Thor
def destroy(name) def destroy(name)
check_castle_existance name, "destroy" check_castle_existance name, "destroy"
if shell.yes?("This will destroy your castle irreversible! Are you sure?")
inside castle_dir(name) do inside castle_dir(name) do
files = Pathname.glob('{.*,*}').reject{|a| [".",".."].include?(a.to_s)} files = Pathname.glob('{.*,*}').reject{|a| [".",".."].include?(a.to_s)}
files.each do |path| files.each do |path|
@@ -241,7 +242,8 @@ class Homesick < Thor
rm adjusted_path rm adjusted_path
end end
end end
rm_rf repos_dir + name rm_r castle_dir(name)
end
end end
end end

View File

@@ -494,6 +494,7 @@ describe 'homesick' do
describe "destroy" do describe "destroy" do
it "removes the symlink files" do it "removes the symlink files" do
expect_any_instance_of(Thor::Shell::Basic).to receive(:yes?).and_return('y')
given_castle("stronghold") given_castle("stronghold")
some_rc_file = home.file '.some_rc_file' some_rc_file = home.file '.some_rc_file'
homesick.track(some_rc_file.to_s, "stronghold") homesick.track(some_rc_file.to_s, "stronghold")
@@ -503,6 +504,7 @@ describe 'homesick' do
end end
it "deletes the cloned repository" do it "deletes the cloned repository" do
expect_any_instance_of(Thor::Shell::Basic).to receive(:yes?).and_return('y')
castle = given_castle("stronghold") castle = given_castle("stronghold")
some_rc_file = home.file '.some_rc_file' some_rc_file = home.file '.some_rc_file'
homesick.track(some_rc_file.to_s, "stronghold") homesick.track(some_rc_file.to_s, "stronghold")