Class: Homebrew::DevCmd::Sh Private

Inherits:
AbstractCommand show all
Defined in:
dev-cmd/sh.rb,
sorbet/rbi/dsl/homebrew/dev_cmd/sh.rbi

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Defined Under Namespace

Classes: Args

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?

Methods included from Utils::Output::Mixin

#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_incompatible, #pretty_install_status, #pretty_installed, #pretty_removed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#args ⇒ Homebrew::DevCmd::Sh::Args

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



10
# File 'sorbet/rbi/dsl/homebrew/dev_cmd/sh.rbi', line 10

def args; end

#run ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'dev-cmd/sh.rb', line 43

def run
  if args.ruby?
    Utils::GemSetup.install_bundler_gems!(setup_path: true)

    prompt = "brew ruby"
    notice = unless Homebrew::EnvConfig.no_env_hints?
      <<~EOS
        Your shell has been configured to use Homebrew's Ruby environment.
        This includes the correct Ruby version, GEM_HOME, and bundle configuration.
        Tools like RuboCop, Sorbet, and RSpec are available via `bundle exec`.
        Hide these hints with `HOMEBREW_NO_ENV_HINTS=1` (see `man brew`).
        When done, type `exit`.
      EOS
    end
  else
    ENV.activate_extensions!(env: args.env)

    if Superenv.enabled_for?(args.env)
      ENV.deps = Formula.installed.select do |f|
        f.keg_only? && f.opt_prefix.directory?
      end
    end
    ENV.setup_build_environment
    if Superenv.enabled_for?(args.env)
      # superenv stopped adding brew's bin but generally users will want it
      ENV["PATH"] = PATH.new(ENV.fetch("PATH")).insert(1, HOMEBREW_PREFIX/"bin").to_s
    end

    ENV["VERBOSE"] = "1" if args.verbose?

    prompt = "brew"
    notice = unless Homebrew::EnvConfig.no_env_hints?
      <<~EOS
        Your shell has been configured to use Homebrew's build environment;
        this should help you build stuff. Notably though, the system versions of
        gem and pip will ignore our configuration and insist on using the
        environment they were built under (mostly). Sadly, scons will also
        ignore our configuration.
        Hide these hints with `HOMEBREW_NO_ENV_HINTS=1` (see `man brew`).
        When done, type `exit`.
      EOS
    end
  end

  preferred_path = Utils::Shell.preferred_path(default: "/bin/bash")

  if args.cmd.present?
    SystemCommand.safe_system(preferred_path, "-c", args.cmd)
  elsif args.named.present?
    SystemCommand.safe_system(preferred_path, args.named.first)
  else
    system Utils::Shell.shell_with_prompt(prompt, preferred_path:, notice:)
  end
end