2015-08-03 13:09:07 +01:00
|
|
|
require "ostruct"
|
2018-07-26 10:49:55 +01:00
|
|
|
require "caveats"
|
2019-04-17 18:25:08 +09:00
|
|
|
require "cli/parser"
|
2012-10-20 20:54:11 -05:00
|
|
|
|
2014-06-18 22:41:47 -05:00
|
|
|
module Homebrew
|
2016-09-26 01:44:51 +02:00
|
|
|
module_function
|
|
|
|
|
2018-11-05 12:20:10 +05:30
|
|
|
def link_args
|
|
|
|
Homebrew::CLI::Parser.new do
|
|
|
|
usage_banner <<~EOS
|
2019-01-30 21:32:35 +00:00
|
|
|
`ln`, `link` [<options>] <formula>
|
2018-11-05 12:20:10 +05:30
|
|
|
|
|
|
|
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.
|
|
|
|
EOS
|
|
|
|
switch "--overwrite",
|
|
|
|
description: "Delete files already existing in the prefix while linking."
|
|
|
|
switch "-n", "--dry-run",
|
|
|
|
description: "List all files which would be linked or deleted by "\
|
|
|
|
"`brew link --overwrite`, but will not actually link or delete any files."
|
|
|
|
switch :force,
|
|
|
|
description: "Allow only key-only formulae to be linked."
|
|
|
|
switch :verbose
|
|
|
|
switch :debug
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-09-11 20:22:54 +01:00
|
|
|
def link
|
2018-11-05 12:20:10 +05:30
|
|
|
link_args.parse
|
|
|
|
|
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
|
|
|
|
|
2018-11-05 12:20:10 +05:30
|
|
|
mode.overwrite = true if args.overwrite?
|
|
|
|
mode.dry_run = true if args.dry_run?
|
2012-06-17 16:54:20 -05:00
|
|
|
|
2010-09-11 20:22:54 +01:00
|
|
|
ARGV.kegs.each do |keg|
|
2018-06-05 23:19:18 -04:00
|
|
|
keg_only = Formulary.keg_only?(keg.rack)
|
2018-07-10 09:32:42 +01:00
|
|
|
|
|
|
|
if keg.linked?
|
2012-03-19 12:24:13 +00:00
|
|
|
opoo "Already linked: #{keg}"
|
2018-07-10 09:32:42 +01:00
|
|
|
name_and_flag = if keg_only
|
|
|
|
"--force #{keg.name}"
|
|
|
|
else
|
|
|
|
keg.name
|
|
|
|
end
|
|
|
|
puts "To relink: brew unlink #{keg.name} && brew link #{name_and_flag}"
|
2013-05-20 21:55:01 -05:00
|
|
|
next
|
2018-07-10 09:32:42 +01:00
|
|
|
end
|
2012-06-17 16:54:20 -05:00
|
|
|
|
2018-07-10 09:32:42 +01:00
|
|
|
if mode.dry_run
|
|
|
|
if mode.overwrite
|
|
|
|
puts "Would remove:"
|
|
|
|
else
|
|
|
|
puts "Would link:"
|
|
|
|
end
|
2014-03-27 15:50:06 -05:00
|
|
|
keg.link(mode)
|
2017-03-23 08:42:27 +00:00
|
|
|
puts_keg_only_path_message(keg) if keg_only
|
2012-06-17 16:54:20 -05:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2018-07-10 09:32:42 +01:00
|
|
|
if keg_only
|
2018-09-06 16:58:17 -07:00
|
|
|
if Homebrew.default_prefix?
|
2018-07-26 10:49:55 +01:00
|
|
|
f = keg.to_formula
|
2018-12-06 13:59:28 +00:00
|
|
|
if f.keg_only_reason.reason == :provided_by_macos
|
|
|
|
caveats = Caveats.new(f)
|
2018-07-10 09:32:42 +01:00
|
|
|
opoo <<~EOS
|
|
|
|
Refusing to link macOS-provided software: #{keg.name}
|
2018-07-26 10:49:55 +01:00
|
|
|
#{caveats.keg_only_text(skip_reason: true).strip}
|
2018-07-10 09:32:42 +01:00
|
|
|
EOS
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-05 12:20:10 +05:30
|
|
|
unless args.force?
|
2018-07-10 09:32:42 +01:00
|
|
|
opoo "#{keg.name} is keg-only and must be linked with --force"
|
|
|
|
puts_keg_only_path_message(keg)
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-23 00:26:25 -06:00
|
|
|
keg.lock do
|
2014-04-21 09:40:24 -05:00
|
|
|
print "Linking #{keg}... "
|
2018-11-05 12:20:10 +05:30
|
|
|
puts if args.verbose?
|
2014-04-21 09:40:24 -05:00
|
|
|
|
|
|
|
begin
|
|
|
|
n = keg.link(mode)
|
|
|
|
rescue Keg::LinkError
|
|
|
|
puts
|
|
|
|
raise
|
|
|
|
else
|
|
|
|
puts "#{n} symlinks created"
|
2013-01-23 00:26:25 -06:00
|
|
|
end
|
2017-03-23 08:42:27 +00:00
|
|
|
|
2017-05-29 18:24:52 +01:00
|
|
|
puts_keg_only_path_message(keg) if keg_only && !ARGV.homebrew_developer?
|
2012-03-19 00:15:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-23 08:42:27 +00:00
|
|
|
def puts_keg_only_path_message(keg)
|
|
|
|
bin = keg/"bin"
|
|
|
|
sbin = keg/"sbin"
|
|
|
|
return if !bin.directory? && !sbin.directory?
|
|
|
|
|
|
|
|
opt = HOMEBREW_PREFIX/"opt/#{keg.name}"
|
|
|
|
puts "\nIf you need to have this software first in your PATH instead consider running:"
|
2017-04-22 16:28:07 +01:00
|
|
|
puts " #{Utils::Shell.prepend_path_in_profile(opt/"bin")}" if bin.directory?
|
|
|
|
puts " #{Utils::Shell.prepend_path_in_profile(opt/"sbin")}" if sbin.directory?
|
2017-03-23 08:42:27 +00:00
|
|
|
end
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|