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.
This commit is contained in:
Ilkka Laukkanen
2011-04-27 21:01:29 +03:00
parent 06846afa77
commit c870bfe442

View File

@@ -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,13 +109,10 @@ 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
inside_each_castle do |castle|
say_status castle.relative_path_from(repos_dir), `git config remote.origin.url`.chomp, :cyan
end
end
end
desc "generate PATH", "generate a homesick-ready git repo at PATH"
def generate(castle)
@@ -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