destroy action implemented
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
# -*- encoding : utf-8 -*-
|
||||||
require 'thor'
|
require 'thor'
|
||||||
|
|
||||||
class Homesick < Thor
|
class Homesick < Thor
|
||||||
@@ -102,7 +103,7 @@ class Homesick < Thor
|
|||||||
castle = Pathname.new(castle)
|
castle = Pathname.new(castle)
|
||||||
file = Pathname.new(file)
|
file = Pathname.new(file)
|
||||||
check_castle_existance(castle, 'track')
|
check_castle_existance(castle, 'track')
|
||||||
|
|
||||||
absolute_path = file.expand_path
|
absolute_path = file.expand_path
|
||||||
castle_path = castle_dir(castle)
|
castle_path = castle_dir(castle)
|
||||||
mv absolute_path, castle_path
|
mv absolute_path, castle_path
|
||||||
@@ -141,6 +142,23 @@ class Homesick < Thor
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc "destroy CASTLE", "Delete all symlnks and remove the cloned repository"
|
||||||
|
def destroy(name)
|
||||||
|
check_castle_existance name, "destroy"
|
||||||
|
|
||||||
|
inside castle_dir(name) do
|
||||||
|
files = Pathname.glob('{.*,*}').reject{|a| [".",".."].include?(a.to_s)}
|
||||||
|
files.each do |path|
|
||||||
|
|
||||||
|
inside home_dir do
|
||||||
|
adjusted_path = (home_dir + path).basename
|
||||||
|
rm adjusted_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
rm_r castle_dir(name)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
# -*- encoding : utf-8 -*-
|
||||||
class Homesick
|
class Homesick
|
||||||
module Actions
|
module Actions
|
||||||
# TODO move this to be more like thor's template, empty_directory, etc
|
# TODO move this to be more like thor's template, empty_directory, etc
|
||||||
@@ -75,6 +76,16 @@ class Homesick
|
|||||||
end
|
end
|
||||||
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 = {})
|
def ln_s(source, destination, config = {})
|
||||||
source = Pathname.new(source)
|
source = Pathname.new(source)
|
||||||
destination = Pathname.new(destination)
|
destination = Pathname.new(destination)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
require 'spec_helper'
|
# -*- encoding : utf-8 -*-
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
describe "homesick" do
|
describe "homesick" do
|
||||||
let(:home) { create_construct }
|
let(:home) { create_construct }
|
||||||
@@ -158,4 +159,24 @@ describe "homesick" do
|
|||||||
some_rc_file.readlink.should == tracked_file
|
some_rc_file.readlink.should == tracked_file
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "destroy" do
|
||||||
|
it "removes the symlink files" do
|
||||||
|
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
|
||||||
|
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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user