From 30b4961dde355b03fc9d53f494c7a9a8910df333 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sat, 15 Mar 2014 12:55:14 -0500 Subject: Modernize `brew diy` --- Library/Contributions/manpages/brew.1.md | 7 ++++--- Library/Homebrew/cmd/diy.rb | 26 +++++++++++++++----------- 2 files changed, 19 insertions(+), 14 deletions(-) (limited to 'Library') diff --git a/Library/Contributions/manpages/brew.1.md b/Library/Contributions/manpages/brew.1.md index 644fe99c9..e27fa8f27 100644 --- a/Library/Contributions/manpages/brew.1.md +++ b/Library/Contributions/manpages/brew.1.md @@ -98,14 +98,15 @@ Note that these flags should only appear after a command. If `--installed` is passed, show dependencies for all installed formulae. - * `diy [--set-name ] [--set-version ]`: + * `diy [--name=] [--version=]`: Automatically determine the installation prefix for non-Homebrew software. Using the output from this command, you can install your own software into the Cellar and then link it into Homebrew's prefix with `brew link`. - The options `--set-name` and `--set-version` each take an argument and allow - you to explicitly set the name and version of the package you are installing. + The options `--name=` and `--version=` each take an argument + and allow you to explicitly set the name and version of the package you are + installing. * `doctor`: Check your system for potential problems. Doctor exits with a non-zero status diff --git a/Library/Homebrew/cmd/diy.rb b/Library/Homebrew/cmd/diy.rb index 174626afc..fa1822c0e 100644 --- a/Library/Homebrew/cmd/diy.rb +++ b/Library/Homebrew/cmd/diy.rb @@ -1,31 +1,35 @@ module Homebrew extend self def diy + %w[name version].each do |opt| + if ARGV.include? "--set-#{opt}" + opoo "--set-#{opt} is deprecated, please use --#{opt}=<#{opt}> instead" + end + end + path = Pathname.getwd - version = if ARGV.include? '--set-version' + version = ARGV.value "version" + version ||= if ARGV.include? "--set-version" ARGV.next elsif path.version.to_s.empty? - raise "Couldn't determine version, try --set-version" + raise "Couldn't determine version, set it with --version=" else path.version end - name = if ARGV.include? '--set-name' + name = ARGV.value "name" + name ||= if ARGV.include? "--set-name" ARGV.next else - path.basename.to_s =~ /(.*?)-?#{version}/ - if $1.to_s.empty? - path.basename - else - $1 - end + basename = path.basename.to_s + basename[/(.*?)-?#{Regexp.escape(version)}/, 1] || basename end prefix = HOMEBREW_CELLAR/name/version - if File.file? 'CMakeLists.txt' + if File.file? "CMakeLists.txt" puts "-DCMAKE_INSTALL_PREFIX=#{prefix}" - elsif File.file? 'Makefile.am' + elsif File.file? "Makefile.am" puts "--prefix=#{prefix}" else raise "Couldn't determine build system" -- cgit v1.2.3