From c870bfe442bd81f2c5787a3ba4117b4931fedc5e Mon Sep 17 00:00:00 2001 From: Ilkka Laukkanen Date: Wed, 27 Apr 2011 21:01:29 +0300 Subject: [PATCH] Add --all option to pull to update all castles Abstracted the logic for doing some operation for all castles into Homesick.inside_each_castle() which takes a block argument. Homesick.list() is also reimplemented to use this new method, because that's where the logic was stolen from. The actual updating is also moved to the private method update_castle() to make pull() shorter. --- lib/homesick.rb | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/lib/homesick.rb b/lib/homesick.rb index f12ebca..9733d37 100644 --- a/lib/homesick.rb +++ b/lib/homesick.rb @@ -60,14 +60,16 @@ class Homesick < Thor end desc "pull NAME", "Update the specified castle" - def pull(name) - check_castle_existance(name, "pull") - - inside repos_dir.join(name) do - git_pull - git_submodule_init - git_submodule_update + method_option :all, :type => :boolean, :default => false, :required => false, :desc => "Update all cloned castles" + def pull(name="") + if options[:all] + inside_each_castle do |castle| + update_castle castle + end + else + update_castle name end + end desc "symlink NAME", "Symlinks all dotfiles from the specified castle" @@ -107,11 +109,8 @@ class Homesick < Thor desc "list", "List cloned castles" def list - Pathname.glob("#{repos_dir}/**/*/.git") do |git_dir| - castle = git_dir.dirname - Dir.chdir castle do # so we can call git config from the right contxt - say_status castle.relative_path_from(repos_dir), `git config remote.origin.url`.chomp, :cyan - end + inside_each_castle do |castle| + say_status castle.relative_path_from(repos_dir), `git config remote.origin.url`.chomp, :cyan end end @@ -158,4 +157,21 @@ class Homesick < Thor end end + def inside_each_castle(&block) + Pathname.glob("#{repos_dir}/**/*/.git") do |git_dir| + castle = git_dir.dirname + Dir.chdir castle do # so we can call git config from the right contxt + yield castle + end + end + end + + def update_castle(castle) + check_castle_existance(castle, "pull") + inside repos_dir.join(castle) do + git_pull + git_submodule_init + git_submodule_update + end + end end