41 lines
896 B
Ruby
Raw Normal View History

# frozen_string_literal: true
require "formula"
2019-04-17 18:25:08 +09:00
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` [<formula>]
2019-08-06 14:20:27 -04:00
Open <formula> in the editor set by `EDITOR` or `HOMEBREW_EDITOR`, or open the
Homebrew repository for editing if no formula is provided.
2018-09-28 21:39:52 +05:30
EOS
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!
2019-04-05 12:24:10 -04:00
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
paths = args.formulae_paths.presence
2018-09-17 02:45:00 +02:00
# If no brews are listed, open the project root in an editor.
paths ||= [HOMEBREW_REPOSITORY]
exec_editor(*paths)
end
end