optimising the code, removing begin block
This commit is contained in:
		
							parent
							
								
									f3c2d27cd0
								
							
						
					
					
						commit
						be1a4c03af
					
				@ -120,7 +120,7 @@ module Homebrew
 | 
				
			|||||||
          [:switch, "--overwrite", {
 | 
					          [:switch, "--overwrite", {
 | 
				
			||||||
            description: "Delete files that already exist in the prefix while linking.",
 | 
					            description: "Delete files that already exist in the prefix while linking.",
 | 
				
			||||||
          }],
 | 
					          }],
 | 
				
			||||||
          [:switch, "--ask", {
 | 
					          [:switch, "--install-ask", {
 | 
				
			||||||
            description: "Ask for confirmation before downloading and installing formulae. " \
 | 
					            description: "Ask for confirmation before downloading and installing formulae. " \
 | 
				
			||||||
                         "Print bottles and dependencies download size and install size.",
 | 
					                         "Print bottles and dependencies download size and install size.",
 | 
				
			||||||
            env: :install_ask,
 | 
					            env: :install_ask,
 | 
				
			||||||
@ -308,48 +308,31 @@ module Homebrew
 | 
				
			|||||||
        Install.check_cc_argv(args.cc)
 | 
					        Install.check_cc_argv(args.cc)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Showing dependencies and required size to install
 | 
					        # Showing dependencies and required size to install
 | 
				
			||||||
        if args.ask? || Homebrew::EnvConfig.ask?
 | 
					        if args.install_ask?
 | 
				
			||||||
          ohai "Looking for bottle sizes..."
 | 
					          ohai "Looking for bottle sizes..."
 | 
				
			||||||
          sized_formulae = []
 | 
					          sized_formulae = []
 | 
				
			||||||
          total_download_size = 0
 | 
					          total_download_size = 0
 | 
				
			||||||
          total_installed_size = 0
 | 
					          total_installed_size = 0
 | 
				
			||||||
          installed_formulae.each do |f|
 | 
					          installed_formulae.each do |f|
 | 
				
			||||||
            next unless (bottle = f.bottle)
 | 
					            next unless (bottle = f.bottle)
 | 
				
			||||||
 | 
					            # keep it quiet as there could be a lot of json fetch, it’s not intuitive to show them all.
 | 
				
			||||||
            begin
 | 
					            bottle.fetch_tab(quiet: !args.debug?)
 | 
				
			||||||
              bottle.fetch_tab(quiet: !args.debug?)
 | 
					            total_download_size += T.must(bottle.bottle_size) if bottle.bottle_size
 | 
				
			||||||
              bottle_size += T.must(bottle.bottle_size) if bottle.bottle_size
 | 
					            total_installed_size += T.must(bottle.installed_size) if bottle.installed_size
 | 
				
			||||||
              installed_size += T.must(bottle.installed_size) if bottle.installed_size
 | 
					            sized_formulae.push(f, f.recursive_dependencies)
 | 
				
			||||||
              package.push(f, f.recursive_dependencies)
 | 
					            unless f.deps.empty?
 | 
				
			||||||
              unless f.deps.empty?
 | 
					              f.recursive_dependencies.each do |dep|
 | 
				
			||||||
                f.recursive_dependencies.each do |dep|
 | 
					                bottle_dep = dep.to_formula.bottle
 | 
				
			||||||
                  bottle_dep = dep.to_formula.bottle
 | 
					                bottle_dep.fetch_tab(quiet: !args.debug?)
 | 
				
			||||||
                  bottle_dep.fetch_tab(quiet: !args.debug?)
 | 
					                total_download_size += bottle_dep.bottle_size if bottle_dep.bottle_size
 | 
				
			||||||
                  bottle_size += bottle_dep.bottle_size if bottle_dep.bottle_size
 | 
					                total_installed_size += bottle_dep.installed_size if bottle_dep.installed_size
 | 
				
			||||||
                  installed_size += bottle_dep.installed_size if bottle_dep.installed_size
 | 
					 | 
				
			||||||
                end
 | 
					 | 
				
			||||||
              end
 | 
					              end
 | 
				
			||||||
            rescue RuntimeError => e
 | 
					 | 
				
			||||||
              odebug e
 | 
					 | 
				
			||||||
            end
 | 
					 | 
				
			||||||
          end
 | 
					 | 
				
			||||||
          puts "Formulae: #{sized_formulae(", ")}\n\n"
 | 
					 | 
				
			||||||
          puts "Download Size: #{disk_usage_readable(total_download_size)}" if bottle_size
 | 
					 | 
				
			||||||
          puts "Install Size: #{disk_usage_readable(total_installed_size)}\n" if installed_size
 | 
					 | 
				
			||||||
          ohai "Do you want to proceed with the installation? [Y/y/yes/N/n]"
 | 
					 | 
				
			||||||
          accepted_inputs = %w[y yes]
 | 
					 | 
				
			||||||
          declined_inputs = %w[n no]
 | 
					 | 
				
			||||||
          loop do
 | 
					 | 
				
			||||||
            result = $stdin.gets.chomp.strip.downcase
 | 
					 | 
				
			||||||
            if accepted_inputs.include?(result)
 | 
					 | 
				
			||||||
              puts "Proceeding with installation..."
 | 
					 | 
				
			||||||
              break
 | 
					 | 
				
			||||||
            elsif declined_inputs.include?(result)
 | 
					 | 
				
			||||||
              return
 | 
					 | 
				
			||||||
            else
 | 
					 | 
				
			||||||
              puts "Invalid input. Please enter 'Y', 'y', or 'yes' to proceed, or 'N' to abort."
 | 
					 | 
				
			||||||
            end
 | 
					            end
 | 
				
			||||||
          end
 | 
					          end
 | 
				
			||||||
 | 
					          puts "Formulae: #{sized_formulae.join(", ")}\n\n"
 | 
				
			||||||
 | 
					          puts "Download Size: #{disk_usage_readable(total_download_size)}" if total_download_size
 | 
				
			||||||
 | 
					          puts "Install Size: #{disk_usage_readable(total_installed_size)}\n" if total_installed_size
 | 
				
			||||||
 | 
					          ask_input
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Install.install_formulae(
 | 
					        Install.install_formulae(
 | 
				
			||||||
@ -466,6 +449,25 @@ module Homebrew
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        odie "No #{package_types.join(" or ")} found for #{name}."
 | 
					        odie "No #{package_types.join(" or ")} found for #{name}."
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      private
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      def ask_input
 | 
				
			||||||
 | 
					        ohai "Do you want to proceed with the installation? [Y/y/yes/N/n]"
 | 
				
			||||||
 | 
					        accepted_inputs = %w[y yes]
 | 
				
			||||||
 | 
					        declined_inputs = %w[n no]
 | 
				
			||||||
 | 
					        loop do
 | 
				
			||||||
 | 
					          result = $stdin.gets.chomp.strip.downcase
 | 
				
			||||||
 | 
					          if accepted_inputs.include?(result)
 | 
				
			||||||
 | 
					            puts "Proceeding with installation..."
 | 
				
			||||||
 | 
					            break
 | 
				
			||||||
 | 
					          elsif declined_inputs.include?(result)
 | 
				
			||||||
 | 
					            return
 | 
				
			||||||
 | 
					          else
 | 
				
			||||||
 | 
					            puts "Invalid input. Please enter 'Y', 'y', or 'yes' to proceed, or 'N' to abort."
 | 
				
			||||||
 | 
					          end
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user