Merge pull request #24 from thilko/master

Destroy your castles
This commit is contained in:
Thilko Richter
2013-11-25 11:26:29 -08:00
3 changed files with 66 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
# -*- encoding : utf-8 -*-
require 'thor'
class Homesick < Thor
@@ -227,6 +228,16 @@ class Homesick < Thor
end
end
desc "destroy CASTLE", "Delete all symlinks and remove the cloned repository"
def destroy(name)
check_castle_existance name, "destroy"
if shell.yes?("This will destroy your castle irreversible! Are you sure?")
unlink(name)
rm_rf repos_dir.join(name)
end
end
protected

View File

@@ -1,3 +1,4 @@
# -*- encoding : utf-8 -*-
class Homesick
module Actions
# TODO move this to be more like thor's template, empty_directory, etc
@@ -108,6 +109,37 @@ class Homesick
end
end
def rm(file)
say_status "rm #{file}", '', :green unless options[:quiet]
system "rm #{file}" if File.exists?(file)
end
def rm_rf(dir)
say_status "rm -rf #{dir}", '', :green unless options[:quiet]
system "rm -rf #{dir}"
end
def rm_link(target)
target = Pathname.new(target)
if target.symlink?
say_status :unlink, "#{target.expand_path}", :green unless options[:quiet]
FileUtils.rm_rf target
else
say_status :conflict, "#{target} is not a symlink", :red unless options[:quiet]
end
end
def rm(file)
say_status "rm #{file}", '', :green unless options[:quiet]
system "rm #{file}"
end
def rm_r(dir)
say_status "rm -r #{dir}", '', :green unless options[:quiet]
system "rm -r #{dir}"
end
def ln_s(source, destination, config = {})
source = Pathname.new(source)
destination = Pathname.new(destination)

View File

@@ -1,3 +1,4 @@
# -*- encoding : utf-8 -*-
require 'spec_helper'
describe 'homesick' do
@@ -490,4 +491,26 @@ describe 'homesick' do
end
end
end
describe "destroy" do
it "removes the symlink files" do
expect_any_instance_of(Thor::Shell::Basic).to receive(:yes?).and_return('y')
given_castle("stronghold")
some_rc_file = home.file '.some_rc_file'
homesick.track(some_rc_file.to_s, "stronghold")
homesick.destroy('stronghold')
some_rc_file.should_not be_exist
end
it "deletes the cloned repository" do
expect_any_instance_of(Thor::Shell::Basic).to receive(:yes?).and_return('y')
castle = given_castle("stronghold")
some_rc_file = home.file '.some_rc_file'
homesick.track(some_rc_file.to_s, "stronghold")
homesick.destroy('stronghold')
castle.should_not be_exist
end
end
end