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