| 
									
										
										
										
											2016-04-08 16:28:43 +02:00
										 |  |  | #:  * `ln`, `link` [`--overwrite`] [`--dry-run`] [`--force`] <formula>: | 
					
						
							|  |  |  | #:    Symlink all of <formula>'s installed files into the Homebrew prefix. This | 
					
						
							|  |  |  | #:    is done automatically when you install formulae but can be useful for DIY | 
					
						
							|  |  |  | #:    installations. | 
					
						
							|  |  |  | #: | 
					
						
							|  |  |  | #:    If `--overwrite` is passed, Homebrew will delete files which already exist in | 
					
						
							|  |  |  | #:    the prefix while linking. | 
					
						
							|  |  |  | #: | 
					
						
							|  |  |  | #:    If `--dry-run` or `-n` is passed, Homebrew will list all files which would | 
					
						
							|  |  |  | #:    be linked or which would be deleted by `brew link --overwrite`, but will not | 
					
						
							|  |  |  | #:    actually link or delete any files. | 
					
						
							|  |  |  | #: | 
					
						
							|  |  |  | #:    If `--force` is passed, Homebrew will allow keg-only formulae to be linked. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "ostruct" | 
					
						
							| 
									
										
										
										
											2012-10-20 20:54:11 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   def link | 
					
						
							| 
									
										
										
										
											2012-02-04 00:01:29 -06:00
										 |  |  |     raise KegUnspecifiedError if ARGV.named.empty? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-20 20:54:11 -05:00
										 |  |  |     mode = OpenStruct.new | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     mode.overwrite = true if ARGV.include? "--overwrite" | 
					
						
							| 
									
										
										
										
											2012-10-20 20:54:11 -05:00
										 |  |  |     mode.dry_run = true if ARGV.dry_run? | 
					
						
							| 
									
										
										
										
											2012-06-17 16:54:20 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     ARGV.kegs.each do |keg| | 
					
						
							| 
									
										
										
										
											2012-07-11 20:13:46 -07:00
										 |  |  |       if keg.linked? | 
					
						
							| 
									
										
										
										
											2012-03-19 12:24:13 +00:00
										 |  |  |         opoo "Already linked: #{keg}" | 
					
						
							| 
									
										
										
										
											2014-06-24 19:04:52 -05:00
										 |  |  |         puts "To relink: brew unlink #{keg.name} && brew link #{keg.name}" | 
					
						
							| 
									
										
										
										
											2012-03-19 12:24:13 +00:00
										 |  |  |         next | 
					
						
							| 
									
										
										
										
											2015-05-17 20:35:32 +08:00
										 |  |  |       elsif keg_only?(keg.rack) && !ARGV.force? | 
					
						
							| 
									
										
										
										
											2014-06-24 19:04:52 -05:00
										 |  |  |         opoo "#{keg.name} is keg-only and must be linked with --force" | 
					
						
							| 
									
										
										
										
											2013-05-20 21:55:01 -05:00
										 |  |  |         puts "Note that doing so can interfere with building software." | 
					
						
							|  |  |  |         next | 
					
						
							|  |  |  |       elsif mode.dry_run && mode.overwrite | 
					
						
							| 
									
										
										
										
											2014-03-27 15:50:06 -05:00
										 |  |  |         puts "Would remove:" | 
					
						
							|  |  |  |         keg.link(mode) | 
					
						
							| 
									
										
										
										
											2012-06-17 16:54:20 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-20 20:54:11 -05:00
										 |  |  |         next | 
					
						
							|  |  |  |       elsif mode.dry_run | 
					
						
							| 
									
										
										
										
											2014-03-27 15:50:06 -05:00
										 |  |  |         puts "Would link:" | 
					
						
							|  |  |  |         keg.link(mode) | 
					
						
							| 
									
										
										
										
											2012-10-20 20:54:11 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-17 16:54:20 -05:00
										 |  |  |         next | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:25 -06:00
										 |  |  |       keg.lock do | 
					
						
							| 
									
										
										
										
											2014-04-21 09:40:24 -05:00
										 |  |  |         print "Linking #{keg}... " | 
					
						
							|  |  |  |         puts if ARGV.verbose? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         begin | 
					
						
							|  |  |  |           n = keg.link(mode) | 
					
						
							|  |  |  |         rescue Keg::LinkError | 
					
						
							|  |  |  |           puts | 
					
						
							|  |  |  |           raise | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           puts "#{n} symlinks created" | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:25 -06:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2012-03-19 00:15:40 +00:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-17 20:35:32 +08:00
										 |  |  |   def keg_only?(rack) | 
					
						
							|  |  |  |     Formulary.from_rack(rack).keg_only? | 
					
						
							| 
									
										
										
										
											2015-10-07 17:34:29 +08:00
										 |  |  |   rescue FormulaUnavailableError, TapFormulaAmbiguityError, TapFormulaWithOldnameAmbiguityError | 
					
						
							| 
									
										
										
										
											2013-05-20 21:55:01 -05:00
										 |  |  |     false | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | end |