aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cmd/edit.rb
blob: 5436dc975383b1617e4b77debd7881c907e0c445 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
require 'formula'

module Homebrew extend self
  def edit
    if ARGV.named.empty?
      # EDITOR isn't a good fit here, we need a GUI client that actually has
      # a UI for projects, so apologies if this wasn't what you expected,
      # please improve it! :)
      exec 'mate', HOMEBREW_REPOSITORY+"bin/brew",
                   HOMEBREW_REPOSITORY+'README.md',
                   HOMEBREW_REPOSITORY+".gitignore",
              *Dir[HOMEBREW_REPOSITORY+"Library/*"]
    else
      # Don't use ARGV.formulae as that will throw if the file doesn't parse
      paths = ARGV.named.map do |name|
        HOMEBREW_REPOSITORY+"Library/Formula/#{Formula.canonical_name name}.rb"
      end
      unless ARGV.force?
        paths.each do |path|
          raise FormulaUnavailableError, path.basename('.rb').to_s unless path.file?
        end
      end
      exec_editor *paths
    end
  end
end