diff options
| author | Jack Nagel | 2013-05-20 21:55:01 -0500 |
|---|---|---|
| committer | Jack Nagel | 2013-05-20 21:55:01 -0500 |
| commit | dbe6134a0a921ddb1e25e62aa184d3db0138b81c (patch) | |
| tree | 3a59c76480635ffbdf19cd4304af87f542460030 /Library | |
| parent | 92a033411a976e91c79e5a7fb7e01373c5c7726b (diff) | |
| download | homebrew-dbe6134a0a921ddb1e25e62aa184d3db0138b81c.tar.bz2 | |
link: extract keg-only check into a helper method
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/cmd/link.rb | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/Library/Homebrew/cmd/link.rb b/Library/Homebrew/cmd/link.rb index e07bd2bc7..0184febaf 100644 --- a/Library/Homebrew/cmd/link.rb +++ b/Library/Homebrew/cmd/link.rb @@ -19,9 +19,11 @@ module Homebrew extend self opoo "Already linked: #{keg}" puts "To relink: brew unlink #{keg.fname} && brew link #{keg.fname}" next - end - - if mode.dry_run and mode.overwrite + elsif keg_only?(keg.fname) && !ARGV.force? + opoo "#{keg.fname} is keg-only and must be linked with --force" + puts "Note that doing so can interfere with building software." + next + elsif mode.dry_run && mode.overwrite print "Would remove:\n" do keg.link(mode) end @@ -35,16 +37,6 @@ module Homebrew extend self next end - begin - f = Formula.factory(keg.fname) - if f.keg_only? and not ARGV.force? - opoo "#{keg.fname} is keg-only and must be linked with --force" - puts "Note that doing so can interfere with building software." - next - end - rescue FormulaUnavailableError - end - keg.lock do print "Linking #{keg}... " do puts "#{keg.link(mode)} symlinks created" @@ -55,6 +47,12 @@ module Homebrew extend self private + def keg_only?(name) + Formula.factory(name).keg_only? + rescue FormulaUnavailableError + false + end + # Allows us to ensure a puts happens before the block exits so that if say, # an exception is thrown, its output starts on a new line. def print str, &block |
