lib/makit/cli/pull.rb



# frozen_string_literal: true


require "clamp"
#require "git"


module Makit
  module Cli
    # Define the 'pull' subcommand

    class PullCommand < Clamp::Command
      parameter "GIT_REPOSITORY", "The git repository url", attribute_name: :git_repository, required: true
      option "--ignore-errors", :flag, "Ignore errors and present warnings instead of exiting"

      def execute
        puts "pulling latest changes for repository: #{git_repository}"
        begin
          Makit::pull(git_repository)
        rescue Git::GitExecuteError => e
          $stderr.puts "failed to pull repository: #{git_repository}"
          puts "Please check the URL and your network connection."
          exit 1
        rescue => e
          $stderr.puts "failed to pull repository: #{git_repository}"
          puts e.message
          exit 1
        end
        clone_dir = Directories::get_clone_directory(git_repository)
        puts "size of clone directory: #{clone_dir} is #{Humanize::get_humanized_size(Directory::get_size(clone_dir))}"
      end
    end
  end
end