1- # typed: true # rubocop:todo Sorbet/StrictSigil
1+ # typed: strict
22# frozen_string_literal: true
33
44require "abstract_command"
@@ -18,7 +18,7 @@ module Cmd
1818 class Info < AbstractCommand
1919 VALID_DAYS = %w[ 30 90 365 ] . freeze
2020 VALID_FORMULA_CATEGORIES = %w[ install install-on-request build-error ] . freeze
21- VALID_CATEGORIES = ( VALID_FORMULA_CATEGORIES + %w[ cask-install os-version ] ) . freeze
21+ VALID_CATEGORIES = T . let ( ( VALID_FORMULA_CATEGORIES + %w[ cask-install os-version ] ) . freeze , T :: Array [ String ] )
2222
2323 cmd_args do
2424 description <<~EOS
@@ -96,21 +96,25 @@ def run
9696 end
9797
9898 print_analytics
99- elsif args . json
99+ elsif ( json = args . json )
100100 all = args . eval_all?
101101
102- print_json ( all )
102+ print_json ( json , all )
103103 elsif args . github?
104104 raise FormulaOrCaskUnspecifiedError if args . no_named?
105105
106- exec_browser ( *args . named . to_formulae_and_casks . map { |f | github_info ( f ) } )
106+ exec_browser ( *args . named . to_formulae_and_casks . map do |formula_keg_or_cask |
107+ formula_or_cask = T . cast ( formula_keg_or_cask , T . any ( Formula , Cask ::Cask ) )
108+ github_info ( formula_or_cask )
109+ end )
107110 elsif args . no_named?
108111 print_statistics
109112 else
110113 print_info
111114 end
112115 end
113116
117+ sig { params ( remote : String , path : String ) . returns ( String ) }
114118 def github_remote_path ( remote , path )
115119 if remote =~ %r{^(?:https?://|git(?:@|://))github\. com[:/](.+)/(.+?)(?:\. git)?$}
116120 "https://github.com/#{ Regexp . last_match ( 1 ) } /#{ Regexp . last_match ( 2 ) } /blob/HEAD/#{ path } "
@@ -175,6 +179,7 @@ def print_info
175179 end
176180 end
177181
182+ sig { params ( version : T . any ( T ::Boolean , String ) ) . returns ( Symbol ) }
178183 def json_version ( version )
179184 version_hash = {
180185 true => :default ,
@@ -187,11 +192,11 @@ def json_version(version)
187192 version_hash [ version ]
188193 end
189194
190- sig { params ( all : T ::Boolean ) . void }
191- def print_json ( all )
195+ sig { params ( json : T . any ( T :: Boolean , String ) , all : T ::Boolean ) . void }
196+ def print_json ( json , all )
192197 raise FormulaOrCaskUnspecifiedError if !( all || args . installed? ) && args . no_named?
193198
194- json = case json_version ( args . json )
199+ json = case json_version ( json )
195200 when :v1 , :default
196201 raise UsageError , "Cannot specify `--cask` when using `--json=v1`!" if args . cask?
197202
@@ -240,25 +245,31 @@ def print_json(all)
240245 puts JSON . pretty_generate ( json )
241246 end
242247
248+ sig { params ( formula_or_cask : T . any ( Formula , Cask ::Cask ) ) . returns ( String ) }
243249 def github_info ( formula_or_cask )
244- return formula_or_cask . path if formula_or_cask . tap . blank? || formula_or_cask . tap . remote . blank?
245-
246250 path = case formula_or_cask
247251 when Formula
248252 formula = formula_or_cask
249- formula . path . relative_path_from ( T . must ( formula . tap ) . path )
253+ tap = formula . tap
254+ return formula . path . to_s if tap . blank? || tap . remote . blank?
255+
256+ formula . path . relative_path_from ( tap . path )
250257 when Cask ::Cask
251258 cask = formula_or_cask
259+ tap = cask . tap
260+ return cask . sourcefile_path . to_s if tap . blank? || tap . remote . blank?
261+
252262 if cask . sourcefile_path . blank? || cask . sourcefile_path . extname != ".rb"
253- return "#{ cask . tap . default_remote } /blob/HEAD/#{ cask . tap . relative_cask_path ( cask . token ) } "
263+ return "#{ tap . default_remote } /blob/HEAD/#{ tap . relative_cask_path ( cask . token ) } "
254264 end
255265
256- cask . sourcefile_path . relative_path_from ( cask . tap . path )
266+ cask . sourcefile_path . relative_path_from ( tap . path )
257267 end
258268
259- github_remote_path ( formula_or_cask . tap . remote , path )
269+ github_remote_path ( tap . remote , path )
260270 end
261271
272+ sig { params ( formula : Formula ) . void }
262273 def info_formula ( formula )
263274 specs = [ ]
264275
@@ -356,6 +367,7 @@ def info_formula(formula)
356367 Utils ::Analytics . formula_output ( formula , args :)
357368 end
358369
370+ sig { params ( dependencies : T ::Array [ Dependency ] ) . returns ( String ) }
359371 def decorate_dependencies ( dependencies )
360372 deps_status = dependencies . map do |dep |
361373 if dep . satisfied? ( [ ] )
@@ -367,6 +379,7 @@ def decorate_dependencies(dependencies)
367379 deps_status . join ( ", " )
368380 end
369381
382+ sig { params ( requirements : T ::Array [ Requirement ] ) . returns ( String ) }
370383 def decorate_requirements ( requirements )
371384 req_status = requirements . map do |req |
372385 req_s = req . display_s
@@ -375,12 +388,14 @@ def decorate_requirements(requirements)
375388 req_status . join ( ", " )
376389 end
377390
391+ sig { params ( dep : Dependency ) . returns ( String ) }
378392 def dep_display_s ( dep )
379393 return dep . name if dep . option_tags . empty?
380394
381395 "#{ dep . name } #{ dep . option_tags . map { |o | "--#{ o } " } . join ( " " ) } "
382396 end
383397
398+ sig { params ( cask : Cask ::Cask ) . void }
384399 def info_cask ( cask )
385400 require "cask/info"
386401
0 commit comments