Class: Homebrew::DevCmd::Edit

Inherits:
AbstractCommand show all
Defined in:
dev-cmd/edit.rb

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, #initialize, parser

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#runvoid

This method returns an undefined value.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'dev-cmd/edit.rb', line 29

def run
  ENV["COLORTERM"] = ENV.fetch("HOMEBREW_COLORTERM", nil)

  unless (HOMEBREW_REPOSITORY/".git").directory?
    odie <<~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`!
    EOS
  end

  paths = if args.named.empty?
    # Sublime requires opting into the project editing path,
    # as opposed to VS Code which will infer from the .vscode path
    if which_editor(silent: true) == "subl"
      ["--project", "#{HOMEBREW_REPOSITORY}/.sublime/homebrew.sublime-project"]
    else
      # If no formulae are listed, open the project root in an editor.
      [HOMEBREW_REPOSITORY]
    end
  else
    expanded_paths = args.named.to_paths
    expanded_paths.each do |path|
      raise_with_message!(path, args.cask?) unless path.exist?
    end

    if expanded_paths.any? do |path|
         !Homebrew::EnvConfig.no_install_from_api? &&
         !Homebrew::EnvConfig.no_env_hints? &&
         (core_formula_path?(path) || core_cask_path?(path) || core_formula_tap?(path) || core_cask_tap?(path))
       end
      opoo <<~EOS
        `brew install` ignores locally edited casks and formulae if
        HOMEBREW_NO_INSTALL_FROM_API is not set.
      EOS
    end
    expanded_paths
  end

  if args.print_path?
    paths.each { puts _1 }
    return
  end

  exec_editor(*paths)
end