Merge pull request #101 from nicolasmccurdy/use-libraries

Use stdlib methods to replace most non-git shell calls. Looks good.
This commit is contained in:
Jeremy Cook
2014-04-13 17:17:30 -04:00
2 changed files with 11 additions and 10 deletions

View File

@@ -96,16 +96,16 @@ class Homesick
if destination.exist? if destination.exist?
say_status :conflict, "#{destination} exists", :red unless options[:quiet] say_status :conflict, "#{destination} exists", :red unless options[:quiet]
system "mv '#{source}' '#{destination}'" if (options[:force] || shell.file_collision(destination) { source }) && !options[:pretend] FileUtils.mv source, destination if (options[:force] || shell.file_collision(destination) { source }) && !options[:pretend]
else else
# this needs some sort of message here. # this needs some sort of message here.
system "mv '#{source}' '#{destination}'" unless options[:pretend] FileUtils.mv source, destination unless options[:pretend]
end end
end end
def rm_rf(dir) def rm_rf(dir)
say_status "rm -rf #{dir}", '', :green unless options[:quiet] say_status "rm -rf #{dir}", '', :green unless options[:quiet]
system "rm -rf #{dir}" FileUtils.rm_r dir, force: true
end end
def rm_link(target) def rm_link(target)
@@ -121,12 +121,12 @@ class Homesick
def rm(file) def rm(file)
say_status "rm #{file}", '', :green unless options[:quiet] say_status "rm #{file}", '', :green unless options[:quiet]
system "rm #{file}" if File.exists?(file) FileUtils.rm file, force: true
end end
def rm_r(dir) def rm_r(dir)
say_status "rm -r #{dir}", '', :green unless options[:quiet] say_status "rm -r #{dir}", '', :green unless options[:quiet]
system "rm -r #{dir}" FileUtils.rm_r dir
end end
def ln_s(source, destination, config = {}) def ln_s(source, destination, config = {})
@@ -156,19 +156,20 @@ class Homesick
"#{destination} exists and points to #{destination.readlink}", "#{destination} exists and points to #{destination.readlink}",
:red unless options[:quiet] :red unless options[:quiet]
system "ln -nsf '#{source}' '#{destination}'" if collision_accepted? FileUtils.rm destination
FileUtils.ln_s source, destination, force: true unless options[:pretend]
when :conflict when :conflict
say_status :conflict, "#{destination} exists", :red unless options[:quiet] say_status :conflict, "#{destination} exists", :red unless options[:quiet]
if collision_accepted? if collision_accepted?
system "rm -rf '#{destination}'" unless options[:pretend] FileUtils.rm_r destination, force: true unless options[:pretend]
system "ln -sf '#{source}' '#{destination}'" unless options[:pretend] FileUtils.ln_s source, destination, force: true unless options[:pretend]
end end
else else
say_status :symlink, say_status :symlink,
"#{source.expand_path} to #{destination.expand_path}", "#{source.expand_path} to #{destination.expand_path}",
:green unless options[:quiet] :green unless options[:quiet]
system "ln -s '#{source}' '#{destination}'" unless options[:pretend] FileUtils.ln_s source, destination unless options[:pretend]
end end
end end
end end

View File

@@ -33,7 +33,7 @@ RSpec.configure do |config|
if subdirs if subdirs
subdir_file = castle.join(Homesick::SUBDIR_FILENAME) subdir_file = castle.join(Homesick::SUBDIR_FILENAME)
subdirs.each do |subdir| subdirs.each do |subdir|
system "echo #{subdir} >> #{subdir_file}" File.open(subdir_file, 'a') { |file| file.write "\n#{subdir}\n" }
end end
end end
return castle.directory('home') return castle.directory('home')