lib/teapot/command/fetch.rb in teapot-3.0.0 vs lib/teapot/command/fetch.rb in teapot-3.1.0

- old
+ new

@@ -16,12 +16,11 @@ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -require 'samovar' - +require_relative 'selection' require 'rugged' module Teapot module Command class FetchError < StandardError @@ -46,22 +45,25 @@ option '--local', "Don't update from source, assume updated local packages." end many :packages, "Only update the specified packages, or all packages if none specified." - def invoke(parent) - logger = parent.logger - context = parent.context - + def context + parent.context + end + + def invoke selection = context.select packages = selection.configuration.packages - if @packages.any? - packages = packages.slice(@packages) + if specified_packages = self.packages + packages = packages.slice(specified_packages) end + logger = parent.logger + # If no additional packages were resolved, we have reached a fixed point: while packages.any? packages.each do |package| fetch_package(context, selection.configuration, package, logger, **@options) end @@ -75,16 +77,19 @@ packages = selection.unresolved end if selection.unresolved.count > 0 - logger.error "Could not fetch all packages!".color(:red) - selection.unresolved.each do |package| - logger.error "\t#{package}".color(:red) + logger.error(self) do |buffer| + buffer.puts "Could not fetch all packages!" + + selection.unresolved.each do |package| + buffer.puts "\t#{package}" + end end else - logger.info "Completed fetch successfully.".color(:green) + logger.info "Completed fetch successfully." end end private @@ -96,11 +101,11 @@ branch: repository.head.name.sub(/^refs\/heads\//, '') } end def link_local_package(context, configuration, package, logger) - logger.info "Linking local #{package}...".color(:cyan) + logger.info "Linking local #{package}..." #.color(:cyan) local_path = context.root + package.options[:local] # Where we are going to put the package: destination_path = package.path @@ -117,11 +122,11 @@ # We should prompt for username/password if required... return Rugged::Credentials::SshKeyFromAgent.new(username: username) end def clone_or_pull_package(context, configuration, package, package_lock, logger) - logger.info "Processing #{package}...".color(:cyan) + logger.info "Processing #{package}..." #.color(:cyan) # Where we are going to put the package: destination_path = package.path base_uri = URI(package.options[:source].to_s) @@ -138,11 +143,11 @@ branch_name = package_lock[:branch] commit_id = package_lock[:commit] end if destination_path.exist? - logger.info "Updating package at path #{destination_path}...".color(:cyan) + logger.info "Updating package at path #{destination_path}..." #.color(:cyan) repository = Rugged::Repository.new(destination_path.to_s) # Are there uncommitted changes in the work tree? if repository.to_enum(:status).any? @@ -163,10 +168,10 @@ end # Reset it to the requested commit if required: repository.reset(commit_id, :hard) else - logger.info "Cloning package at path #{destination_path}...".color(:cyan) + logger.info "Cloning package at path #{destination_path}..." #.color(:cyan) external_url = package.external_url(context.root) # Clone the repository with the specified branch: repository = Rugged::Repository.clone_at(external_url.to_s, destination_path.to_s, checkout_branch: branch_name, credentials: self.method(:credentials))