2016-04-08 16:28:43 +02:00
|
|
|
#: * `edit`:
|
|
|
|
#: Open all of Homebrew for editing.
|
|
|
|
#:
|
|
|
|
#: * `edit` <formula>:
|
|
|
|
#: Open <formula> in the editor.
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
require "formula"
|
2018-03-24 19:38:34 +05:30
|
|
|
require "cli_parser"
|
2010-09-11 20:22:54 +01:00
|
|
|
|
2014-06-18 22:41:47 -05:00
|
|
|
module Homebrew
|
2016-09-26 01:44:51 +02:00
|
|
|
module_function
|
|
|
|
|
2018-07-30 18:25:38 +05:30
|
|
|
def edit_args
|
|
|
|
Homebrew::CLI::Parser.new do
|
2018-09-28 21:39:52 +05:30
|
|
|
usage_banner <<~EOS
|
2018-10-02 14:44:38 +05:30
|
|
|
`edit` <formula>:
|
|
|
|
Open <formula> in the editor. Open all of Homebrew for editing if
|
|
|
|
no <formula> is provided.
|
2018-09-28 21:39:52 +05:30
|
|
|
EOS
|
2018-04-01 16:47:30 +05:30
|
|
|
switch :force
|
|
|
|
switch :verbose
|
|
|
|
switch :debug
|
2018-03-25 17:48:22 +05:30
|
|
|
end
|
2018-07-30 18:25:38 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
edit_args.parse
|
2018-03-24 19:38:34 +05:30
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
unless (HOMEBREW_REPOSITORY/".git").directory?
|
2017-10-15 02:28:32 +02:00
|
|
|
raise <<~EOS
|
2012-08-01 15:56:52 -04:00
|
|
|
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
|
2012-08-01 15:56:52 -04:00
|
|
|
end
|
|
|
|
|
2011-12-16 14:27:58 -08:00
|
|
|
# If no brews are listed, open the project root in an editor.
|
2018-09-06 12:31:29 +01:00
|
|
|
paths = [HOMEBREW_REPOSITORY] if ARGV.named.empty?
|
2016-09-23 11:01:40 +02:00
|
|
|
|
2018-09-06 12:31:29 +01: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
|
|
|
|
2018-09-06 12:31:29 +01:00
|
|
|
path
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
2011-08-24 14:45:01 +01:00
|
|
|
|
2018-09-06 12:31:29 +01:00
|
|
|
exec_editor(*paths)
|
2011-08-24 14:45:01 +01:00
|
|
|
end
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|