Commit 0980dca4 authored by Samuel E. Giddins's avatar Samuel E. Giddins

[Command::Repo::List] Extract logic into helper methods

parent b2c84dcd
...@@ -196,11 +196,11 @@ module Pod ...@@ -196,11 +196,11 @@ module Pod
DESC DESC
def self.options def self.options
[["--count", "Show the total number of repos"]].concat(super) [["--count-only", "Show the total number of repos"]].concat(super)
end end
def initialize(argv) def initialize(argv)
@should_count_number_of_repos = argv.flag?('count') @count_only = argv.flag?('count-only')
super super
end end
...@@ -217,9 +217,20 @@ module Pod ...@@ -217,9 +217,20 @@ module Pod
# #
def run def run
sources = SourcesManager.all sources = SourcesManager.all
sources.each do |source| print_sources(sources) unless @count_only
path = source.data_provider.repo print_count_of_sources(sources)
UI.title source.name do end
private
# Pretty-prints the source at the given path.
#
# @param [String,Pathname] path
# The path of the source to be printed.
#
# @return [void]
#
def print_source_at_path(path)
Dir.chdir(path) do Dir.chdir(path) do
if SourcesManager.git_repo?(path) if SourcesManager.git_repo?(path)
branch_name = get_branch_name branch_name = get_branch_name
...@@ -237,15 +248,39 @@ module Pod ...@@ -237,15 +248,39 @@ module Pod
UI.puts "- Path: #{path}" UI.puts "- Path: #{path}"
end end
end end
# Pretty-prints the given sources.
#
# @param [Array<Source>] sources
# The sources that should be printed.
#
# @return [void]
#
def print_sources(sources)
sources.each do |source|
UI.title source.name do
print_source_at_path source.data_provider.repo
end
end
UI.puts "\n"
end end
if @should_count_number_of_repos
# Pretty-prints the number of sources.
#
# @param [Array<Source>] sources
# The sources whose count should be printed.
#
# @return [void]
#
def print_count_of_sources(sources)
number_of_repos = sources.length number_of_repos = sources.length
repo_string = number_of_repos != 1 ? 'repos' : 'repo' repo_string = number_of_repos != 1 ? 'repos' : 'repo'
UI.puts "\n#{number_of_repos} #{repo_string}".green UI.puts "#{number_of_repos} #{repo_string}".green
end
end end
end end
#-----------------------------------------------------------------------#
extend Executable extend Executable
executable :git executable :git
...@@ -253,26 +288,33 @@ module Pod ...@@ -253,26 +288,33 @@ module Pod
config.repos_dir + @name config.repos_dir + @name
end end
# Returns the branch name (i.e. master) # Returns the branch name (i.e. master).
#
# @return [String] The name of the current branch.
# #
def get_branch_name def get_branch_name
`git name-rev --name-only HEAD`.strip `git name-rev --name-only HEAD`.strip
end end
# Returns the branch remote name (i.e. origin) # Returns the branch remote name (i.e. origin).
# #
# @param [BranchName] branch_name # @param [#to_s] branch_name
# The branch name to look for the remote name. # The branch name to look for the remote name.
# #
# @return [String] The given branch's remote name.
#
def get_branch_remote_name(branch_name) def get_branch_remote_name(branch_name)
`git config branch.#{branch_name}.remote`.strip `git config branch.#{branch_name}.remote`.strip
end end
# Returns the url of the given remote name (i.e. git@github.com:CocoaPods/Specs.git) # Returns the url of the given remote name
# (i.e. git@github.com:CocoaPods/Specs.git).
# #
# @param [RemoteName] remote_name # @param [#to_s] remote_name
# The branch remote name to look for the url. # The branch remote name to look for the url.
# #
# @return [String] The URL of the given remote.
#
def get_url_of_git_repo(remote_name) def get_url_of_git_repo(remote_name)
`git config remote.#{remote_name}.url`.strip `git config remote.#{remote_name}.url`.strip
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment