| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-06 15:25:36 +08:00
										 |  |  | require "ostruct" | 
					
						
							| 
									
										
										
										
											2019-04-17 18:25:08 +09:00
										 |  |  | require "cli/parser" | 
					
						
							| 
									
										
										
										
											2015-09-06 15:25:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-11 17:48:28 +05:30
										 |  |  |   def unlink_args | 
					
						
							|  |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							|  |  |  |       usage_banner <<~EOS | 
					
						
							|  |  |  |         `unlink` [<options>] <formula> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Remove symlinks for <formula> from the Homebrew prefix. This can be useful | 
					
						
							|  |  |  |         for temporarily disabling a formula: | 
					
						
							|  |  |  |         `brew unlink` <formula> `&&` <commands> `&& brew link` <formula> | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  |       switch "-n", "--dry-run", | 
					
						
							| 
									
										
										
										
											2019-03-09 13:00:15 -05:00
										 |  |  |         description: "List all files which would be unlinked, but will not actually unlink or "\ | 
					
						
							| 
									
										
										
										
											2018-11-11 17:48:28 +05:30
										 |  |  |                      "delete any files." | 
					
						
							|  |  |  |       switch :verbose | 
					
						
							|  |  |  |       switch :debug | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   def unlink | 
					
						
							| 
									
										
										
										
											2018-11-11 17:48:28 +05:30
										 |  |  |     unlink_args.parse | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     raise KegUnspecifiedError if args.remaining.empty? | 
					
						
							| 
									
										
										
										
											2012-02-04 00:01:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-06 15:25:36 +08:00
										 |  |  |     mode = OpenStruct.new | 
					
						
							| 
									
										
										
										
											2018-11-11 17:48:28 +05:30
										 |  |  |     mode.dry_run = true if args.dry_run? | 
					
						
							| 
									
										
										
										
											2015-09-06 15:25:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     ARGV.kegs.each do |keg| | 
					
						
							| 
									
										
										
										
											2015-09-06 15:25:36 +08:00
										 |  |  |       if mode.dry_run | 
					
						
							|  |  |  |         puts "Would remove:" | 
					
						
							|  |  |  |         keg.unlink(mode) | 
					
						
							|  |  |  |         next | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:25 -06:00
										 |  |  |       keg.lock do | 
					
						
							|  |  |  |         print "Unlinking #{keg}... " | 
					
						
							| 
									
										
										
										
											2018-11-11 17:48:28 +05:30
										 |  |  |         puts if args.verbose? | 
					
						
							| 
									
										
										
										
											2015-09-06 15:25:36 +08:00
										 |  |  |         puts "#{keg.unlink(mode)} symlinks removed" | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:25 -06:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |