53 lines
1.1 KiB
Ruby
Raw Normal View History

2016-04-08 16:28:43 +02:00
#: * `edit`:
#: Open all of Homebrew for editing.
#:
#: * `edit` <formula>:
#: Open <formula> in the editor.
require "formula"
2018-03-24 19:38:34 +05:30
require "cli_parser"
module Homebrew
2016-09-26 01:44:51 +02:00
module_function
def edit_args
Homebrew::CLI::Parser.new do
2018-09-28 21:39:52 +05:30
usage_banner <<~EOS
* `edit`:
Open all of Homebrew for editing.
* `edit` <formula>:
Open <formula> in the editor.
EOS
switch :force
switch :verbose
switch :debug
end
end
def edit
edit_args.parse
2018-03-24 19:38:34 +05:30
unless (HOMEBREW_REPOSITORY/".git").directory?
2017-10-15 02:28:32 +02:00
raise <<~EOS
Changes will be lost!
The first time you `brew update', all local changes will be lost, you should
thus `brew update' before you `brew edit'!
2018-06-06 23:34:19 -04:00
EOS
end
# If no brews are listed, open the project root in an editor.
paths = [HOMEBREW_REPOSITORY] if ARGV.named.empty?
2016-09-23 11:01:40 +02:00
# Don't use ARGV.formulae as that will throw if the file doesn't parse
paths ||= ARGV.named.map do |name|
path = Formulary.path(name)
raise FormulaUnavailableError, name if !path.file? && !args.force?
2018-09-17 02:45:00 +02:00
path
end
exec_editor(*paths)
end
end