Class: Homebrew::DevCmd::Cat

Inherits:
AbstractCommand show all
Includes:
FileUtils
Defined in:
dev-cmd/cat.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.



28
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
# File 'dev-cmd/cat.rb', line 28

def run
  cd HOMEBREW_REPOSITORY do
    pager = if Homebrew::EnvConfig.bat?
      ENV["BAT_CONFIG_PATH"] = Homebrew::EnvConfig.bat_config_path
      ENV["BAT_THEME"] = Homebrew::EnvConfig.bat_theme
      ensure_formula_installed!(
        "bat",
        reason:           "displaying <formula>/<cask> source",
        # The user might want to capture the output of `brew cat ...`
        # Redirect stdout to stderr
        output_to_stderr: true,
      ).opt_bin/"bat"
    else
      "cat"
    end

    args.named.to_paths.each do |path|
      next path if path.exist?

      path = path.basename(".rb") if args.cask?

      ofail "#{path}'s source doesn't exist on disk."
    end

    if Homebrew.failed?
      $stderr.puts "The name may be wrong, or the tap hasn't been tapped. Instead try:"
      treat_as = "--cask " if args.cask?
      treat_as = "--formula " if args.formula?
      $stderr.puts "  brew info --github #{treat_as}#{args.named.join(" ")}"
      return
    end

    safe_system pager, *args.named.to_paths
  end
end