2020-10-10 14:16:11 +02:00
|
|
|
# typed: false
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-04-17 18:25:08 +09:00
|
|
|
require "cli/parser"
|
2019-01-18 22:17:46 +05:30
|
|
|
|
2014-06-18 22:41:47 -05:00
|
|
|
module Homebrew
|
2020-10-20 12:03:48 +02:00
|
|
|
extend T::Sig
|
|
|
|
|
2016-09-26 01:44:51 +02:00
|
|
|
module_function
|
|
|
|
|
2020-10-20 12:03:48 +02:00
|
|
|
sig { returns(CLI::Parser) }
|
2019-01-18 22:17:46 +05:30
|
|
|
def cat_args
|
|
|
|
Homebrew::CLI::Parser.new do
|
|
|
|
usage_banner <<~EOS
|
2020-11-19 16:01:04 +01:00
|
|
|
`cat` <formula>|<cask>
|
2019-01-18 22:17:46 +05:30
|
|
|
|
2020-11-19 16:01:04 +01:00
|
|
|
Display the source of a <formula> or <cask>.
|
2019-01-18 22:17:46 +05:30
|
|
|
EOS
|
2020-11-12 10:40:41 -05:00
|
|
|
|
2020-11-19 16:01:04 +01:00
|
|
|
switch "--formula", "--formulae",
|
|
|
|
description: "Treat all named arguments as formulae."
|
|
|
|
switch "--cask", "--casks",
|
|
|
|
description: "Treat all named arguments as casks."
|
|
|
|
conflicts "--formula", "--cask"
|
|
|
|
|
|
|
|
named :formula_or_cask
|
2019-01-18 22:17:46 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-09-11 20:22:54 +01:00
|
|
|
def cat
|
2020-07-30 18:40:10 +02:00
|
|
|
args = cat_args.parse
|
2010-09-11 20:22:54 +01:00
|
|
|
|
|
|
|
cd HOMEBREW_REPOSITORY
|
2020-04-05 15:44:50 +01:00
|
|
|
pager = if Homebrew::EnvConfig.bat?
|
2020-05-02 18:21:36 +01:00
|
|
|
ENV["BAT_CONFIG_PATH"] = Homebrew::EnvConfig.bat_config_path
|
2019-09-30 15:40:20 +02:00
|
|
|
"#{HOMEBREW_PREFIX}/bin/bat"
|
2020-04-05 15:44:50 +01:00
|
|
|
else
|
|
|
|
"cat"
|
2019-09-30 15:40:20 +02:00
|
|
|
end
|
2020-11-19 16:01:04 +01:00
|
|
|
|
2020-12-17 21:14:18 +09:00
|
|
|
safe_system pager, args.named.to_paths.first
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
end
|