| 
									
										
										
										
											2024-08-10 22:26:32 +01:00
										 |  |  | # typed: strict | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  | require "abstract_command" | 
					
						
							| 
									
										
										
										
											2014-06-07 17:49:07 -05:00
										 |  |  | require "metafiles" | 
					
						
							| 
									
										
										
										
											2015-06-20 22:48:45 +08:00
										 |  |  | require "formula" | 
					
						
							| 
									
										
										
										
											2019-04-17 18:25:08 +09:00
										 |  |  | require "cli/parser" | 
					
						
							| 
									
										
										
										
											2023-03-01 21:22:11 +09:00
										 |  |  | require "cask/list" | 
					
						
							| 
									
										
										
										
											2024-01-31 20:00:54 -08:00
										 |  |  | require "system_command" | 
					
						
							| 
									
										
										
										
											2024-04-22 11:58:07 +08:00
										 |  |  | require "tab" | 
					
						
							| 
									
										
										
										
											2014-06-07 17:49:07 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |   module Cmd | 
					
						
							|  |  |  |     class List < AbstractCommand | 
					
						
							|  |  |  |       include SystemCommand::Mixin | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-05 10:40:02 -08:00
										 |  |  |       cmd_args do | 
					
						
							|  |  |  |         description <<~EOS | 
					
						
							|  |  |  |           List all installed formulae and casks. | 
					
						
							|  |  |  |           If <formula> is provided, summarise the paths within its current keg. | 
					
						
							|  |  |  |           If <cask> is provided, list its artifacts. | 
					
						
							|  |  |  |         EOS | 
					
						
							|  |  |  |         switch "--formula", "--formulae", | 
					
						
							|  |  |  |                description: "List only formulae, or treat all named arguments as formulae." | 
					
						
							|  |  |  |         switch "--cask", "--casks", | 
					
						
							|  |  |  |                description: "List only casks, or treat all named arguments as casks." | 
					
						
							|  |  |  |         switch "--full-name", | 
					
						
							|  |  |  |                description: "Print formulae with fully-qualified names. Unless `--full-name`, `--versions` " \ | 
					
						
							|  |  |  |                             "or `--pinned` are passed, other options (i.e. `-1`, `-l`, `-r` and `-t`) are " \ | 
					
						
							|  |  |  |                             "passed to `ls`(1) which produces the actual output." | 
					
						
							|  |  |  |         switch "--versions", | 
					
						
							|  |  |  |                description: "Show the version number for installed formulae, or only the specified " \ | 
					
						
							|  |  |  |                             "formulae if <formula> are provided." | 
					
						
							|  |  |  |         switch "--multiple", | 
					
						
							|  |  |  |                depends_on:  "--versions", | 
					
						
							|  |  |  |                description: "Only show formulae with multiple versions installed." | 
					
						
							|  |  |  |         switch "--pinned", | 
					
						
							|  |  |  |                description: "List only pinned formulae, or only the specified (pinned) " \ | 
					
						
							|  |  |  |                             "formulae if <formula> are provided. See also `pin`, `unpin`." | 
					
						
							| 
									
										
										
										
											2024-04-23 08:35:10 +01:00
										 |  |  |         switch "--installed-on-request", | 
					
						
							| 
									
										
										
										
											2024-04-22 11:58:07 +08:00
										 |  |  |                description: "List the formulae installed on request." | 
					
						
							| 
									
										
										
										
											2024-04-23 08:35:10 +01:00
										 |  |  |         switch "--installed-as-dependency", | 
					
						
							| 
									
										
										
										
											2024-04-23 15:44:02 +08:00
										 |  |  |                description: "List the formulae installed as dependencies." | 
					
						
							| 
									
										
										
										
											2024-08-22 21:22:33 -07:00
										 |  |  |         switch "--poured-from-bottle", | 
					
						
							|  |  |  |                description: "List the formulae installed from a bottle." | 
					
						
							|  |  |  |         switch "--built-from-source", | 
					
						
							|  |  |  |                description: "List the formulae compiled from source." | 
					
						
							| 
									
										
										
										
											2024-04-22 11:58:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-05 10:40:02 -08:00
										 |  |  |         # passed through to ls | 
					
						
							|  |  |  |         switch "-1", | 
					
						
							|  |  |  |                description: "Force output to be one entry per line. " \ | 
					
						
							|  |  |  |                             "This is the default when output is not to a terminal." | 
					
						
							|  |  |  |         switch "-l", | 
					
						
							|  |  |  |                description: "List formulae and/or casks in long format. " \ | 
					
						
							|  |  |  |                             "Has no effect when a formula or cask name is passed as an argument." | 
					
						
							|  |  |  |         switch "-r", | 
					
						
							|  |  |  |                description: "Reverse the order of the formulae and/or casks sort to list the oldest entries first. " \ | 
					
						
							|  |  |  |                             "Has no effect when a formula or cask name is passed as an argument." | 
					
						
							|  |  |  |         switch "-t", | 
					
						
							|  |  |  |                description: "Sort formulae and/or casks by time modified, listing most recently modified first. " \ | 
					
						
							|  |  |  |                             "Has no effect when a formula or cask name is passed as an argument." | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-05 10:40:02 -08:00
										 |  |  |         conflicts "--formula", "--cask" | 
					
						
							|  |  |  |         conflicts "--pinned", "--cask" | 
					
						
							|  |  |  |         conflicts "--multiple", "--cask" | 
					
						
							|  |  |  |         conflicts "--pinned", "--multiple" | 
					
						
							| 
									
										
										
										
											2024-08-22 21:22:33 -07:00
										 |  |  |         ["--installed-on-request", "--installed-as-dependency", | 
					
						
							|  |  |  |          "--poured-from-bottle", "--built-from-source"].each do |flag| | 
					
						
							| 
									
										
										
										
											2024-04-22 11:58:07 +08:00
										 |  |  |           conflicts "--cask", flag | 
					
						
							|  |  |  |           conflicts "--versions", flag | 
					
						
							|  |  |  |           conflicts "--pinned", flag | 
					
						
							| 
									
										
										
										
											2024-09-26 11:58:33 -04:00
										 |  |  |           conflicts "-l", flag | 
					
						
							| 
									
										
										
										
											2024-04-22 11:58:07 +08:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2024-03-05 10:40:02 -08:00
										 |  |  |         ["-1", "-l", "-r", "-t"].each do |flag| | 
					
						
							|  |  |  |           conflicts "--versions", flag | 
					
						
							|  |  |  |           conflicts "--pinned", flag | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2024-04-23 15:45:00 +08:00
										 |  |  |         ["--versions", "--pinned", | 
					
						
							| 
									
										
										
										
											2024-09-26 11:58:33 -04:00
										 |  |  |          "--installed-on-request", "--installed-as-dependency", | 
					
						
							| 
									
										
										
										
											2024-08-22 21:22:33 -07:00
										 |  |  |          "--poured-from-bottle", "--built-from-source", | 
					
						
							| 
									
										
										
										
											2024-04-22 11:58:07 +08:00
										 |  |  |          "-l", "-r", "-t"].each do |flag| | 
					
						
							| 
									
										
										
										
											2024-03-05 10:40:02 -08:00
										 |  |  |           conflicts "--full-name", flag | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         named_args [:installed_formula, :installed_cask] | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2018-11-11 19:56:53 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |       sig { override.void } | 
					
						
							|  |  |  |       def run | 
					
						
							|  |  |  |         if args.full_name? | 
					
						
							|  |  |  |           unless args.cask? | 
					
						
							|  |  |  |             formula_names = args.no_named? ? Formula.installed : args.named.to_resolved_formulae | 
					
						
							|  |  |  |             full_formula_names = formula_names.map(&:full_name).sort(&tap_and_name_comparison) | 
					
						
							| 
									
										
										
										
											2024-03-15 12:51:03 -07:00
										 |  |  |             full_formula_names = Formatter.columns(full_formula_names) unless args.public_send(:"1?") | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |             puts full_formula_names if full_formula_names.present? | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |           if args.cask? || (!args.formula? && args.no_named?) | 
					
						
							|  |  |  |             cask_names = if args.no_named? | 
					
						
							|  |  |  |               Cask::Caskroom.casks | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |               args.named.to_formulae_and_casks(only: :cask, method: :resolve) | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  |             # The cast is because `Keg`` does not define `full_name` | 
					
						
							|  |  |  |             full_cask_names = T.cast(cask_names, T::Array[T.any(Formula, Cask::Cask)]) | 
					
						
							|  |  |  |                                .map(&:full_name).sort(&tap_and_name_comparison) | 
					
						
							| 
									
										
										
										
											2024-03-15 12:51:03 -07:00
										 |  |  |             full_cask_names = Formatter.columns(full_cask_names) unless args.public_send(:"1?") | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |             puts full_cask_names if full_cask_names.present? | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2024-03-15 12:51:03 -07:00
										 |  |  |         elsif args.pinned? | 
					
						
							| 
									
										
										
										
											2024-03-09 21:45:10 -08:00
										 |  |  |           filtered_list | 
					
						
							| 
									
										
										
										
											2024-03-15 12:51:03 -07:00
										 |  |  |         elsif args.versions? | 
					
						
							| 
									
										
										
										
											2024-03-09 21:45:10 -08:00
										 |  |  |           filtered_list unless args.cask? | 
					
						
							| 
									
										
										
										
											2024-03-15 12:51:03 -07:00
										 |  |  |           list_casks if args.cask? || (!args.formula? && !args.multiple? && args.no_named?) | 
					
						
							| 
									
										
										
										
											2024-08-22 21:22:33 -07:00
										 |  |  |         elsif args.installed_on_request? || | 
					
						
							|  |  |  |               args.installed_as_dependency? || | 
					
						
							|  |  |  |               args.poured_from_bottle? || | 
					
						
							|  |  |  |               args.built_from_source? | 
					
						
							|  |  |  |           flags = [] | 
					
						
							|  |  |  |           flags << "`--installed-on-request`" if args.installed_on_request? | 
					
						
							|  |  |  |           flags << "`--installed-as-dependency`" if args.installed_as_dependency? | 
					
						
							|  |  |  |           flags << "`--poured-from-bottle`" if args.poured_from_bottle? | 
					
						
							|  |  |  |           flags << "`--built-from-source`" if args.built_from_source? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           raise UsageError, "Cannot use #{flags.join(", ")} with formula arguments." unless args.no_named? | 
					
						
							| 
									
										
										
										
											2024-04-22 11:58:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-26 11:58:33 -04:00
										 |  |  |           formulae = if args.t? | 
					
						
							|  |  |  |             Formula.installed.sort_by { |formula| test("M", formula.rack) }.reverse! | 
					
						
							|  |  |  |           else | 
					
						
							|  |  |  |             Formula.installed.sort | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |           formulae.reverse! if args.r? | 
					
						
							|  |  |  |           formulae.each do |formula| | 
					
						
							| 
									
										
										
										
											2024-04-22 11:58:07 +08:00
										 |  |  |             tab = Tab.for_formula(formula) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-22 21:22:33 -07:00
										 |  |  |             statuses = [] | 
					
						
							|  |  |  |             statuses << "installed on request" if args.installed_on_request? && tab.installed_on_request | 
					
						
							|  |  |  |             statuses << "installed as dependency" if args.installed_as_dependency? && tab.installed_as_dependency | 
					
						
							|  |  |  |             statuses << "poured from bottle" if args.poured_from_bottle? && tab.poured_from_bottle | 
					
						
							|  |  |  |             statuses << "built from source" if args.built_from_source? && !tab.poured_from_bottle | 
					
						
							|  |  |  |             next if statuses.empty? | 
					
						
							| 
									
										
										
										
											2024-04-23 15:45:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-22 21:22:33 -07:00
										 |  |  |             if flags.count > 1
 | 
					
						
							| 
									
										
										
										
											2024-04-23 15:45:00 +08:00
										 |  |  |               puts "#{formula.name}: #{statuses.join(", ")}" | 
					
						
							| 
									
										
										
										
											2024-08-22 21:22:33 -07:00
										 |  |  |             else | 
					
						
							| 
									
										
										
										
											2024-04-22 11:58:07 +08:00
										 |  |  |               puts formula.name | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |         elsif args.no_named? | 
					
						
							|  |  |  |           ENV["CLICOLOR"] = nil | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           ls_args = [] | 
					
						
							| 
									
										
										
										
											2024-03-15 12:51:03 -07:00
										 |  |  |           ls_args << "-1" if args.public_send(:"1?") | 
					
						
							|  |  |  |           ls_args << "-l" if args.l? | 
					
						
							|  |  |  |           ls_args << "-r" if args.r? | 
					
						
							|  |  |  |           ls_args << "-t" if args.t? | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |           if !args.cask? && HOMEBREW_CELLAR.exist? && HOMEBREW_CELLAR.children.any? | 
					
						
							|  |  |  |             ohai "Formulae" if $stdout.tty? && !args.formula? | 
					
						
							|  |  |  |             safe_system "ls", *ls_args, HOMEBREW_CELLAR | 
					
						
							|  |  |  |             puts if $stdout.tty? && !args.formula? | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |           if !args.formula? && Cask::Caskroom.any_casks_installed? | 
					
						
							|  |  |  |             ohai "Casks" if $stdout.tty? && !args.cask? | 
					
						
							|  |  |  |             safe_system "ls", *ls_args, Cask::Caskroom.path | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           kegs, casks = args.named.to_kegs_to_casks | 
					
						
							| 
									
										
										
										
											2018-04-13 03:02:47 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |           if args.verbose? || !$stdout.tty? | 
					
						
							|  |  |  |             find_args = %w[-not -type d -not -name .DS_Store -print] | 
					
						
							|  |  |  |             system_command! "find", args: kegs.map(&:to_s) + find_args, print_stdout: true if kegs.present? | 
					
						
							|  |  |  |             system_command! "find", args: casks.map(&:caskroom_path) + find_args, print_stdout: true if casks.present? | 
					
						
							|  |  |  |           else | 
					
						
							|  |  |  |             kegs.each { |keg| PrettyListing.new keg } if kegs.present? | 
					
						
							| 
									
										
										
										
											2024-06-11 03:31:05 +01:00
										 |  |  |             Cask::List.list_casks(*casks, one: args.public_send(:"1?")) if casks.present? | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2020-11-23 20:21:03 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       private | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-10 22:26:32 +01:00
										 |  |  |       sig { void } | 
					
						
							| 
									
										
										
										
											2024-03-09 21:45:10 -08:00
										 |  |  |       def filtered_list | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |         names = if args.no_named? | 
					
						
							|  |  |  |           Formula.racks | 
					
						
							| 
									
										
										
										
											2020-11-23 20:21:03 -05:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |           racks = args.named.map { |n| Formulary.to_rack(n) } | 
					
						
							| 
									
										
										
										
											2024-06-11 03:20:09 +01:00
										 |  |  |           racks.select do |rack| | 
					
						
							|  |  |  |             Homebrew.failed = true unless rack.exist? | 
					
						
							|  |  |  |             rack.exist? | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2020-11-23 20:21:03 -05:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2024-03-15 12:51:03 -07:00
										 |  |  |         if args.pinned? | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |           pinned_versions = {} | 
					
						
							|  |  |  |           names.sort.each do |d| | 
					
						
							|  |  |  |             keg_pin = (HOMEBREW_PINNED_KEGS/d.basename.to_s) | 
					
						
							|  |  |  |             pinned_versions[d] = keg_pin.readlink.basename.to_s if keg_pin.exist? || keg_pin.symlink? | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |           pinned_versions.each do |d, version| | 
					
						
							| 
									
										
										
										
											2024-03-15 12:51:03 -07:00
										 |  |  |             puts d.basename.to_s.concat(args.versions? ? " #{version}" : "") | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |           end | 
					
						
							|  |  |  |         else # --versions without --pinned | 
					
						
							|  |  |  |           names.sort.each do |d| | 
					
						
							|  |  |  |             versions = d.subdirs.map { |pn| pn.basename.to_s } | 
					
						
							| 
									
										
										
										
											2024-03-15 12:51:03 -07:00
										 |  |  |             next if args.multiple? && versions.length < 2
 | 
					
						
							| 
									
										
										
										
											2012-08-28 10:59:46 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |             puts "#{d.basename} #{versions * " "}" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2014-09-06 19:12:03 -07:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-10 22:26:32 +01:00
										 |  |  |       sig { void } | 
					
						
							| 
									
										
										
										
											2024-03-09 21:45:10 -08:00
										 |  |  |       def list_casks | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |         casks = if args.no_named? | 
					
						
							|  |  |  |           Cask::Caskroom.casks | 
					
						
							|  |  |  |         else | 
					
						
							| 
									
										
										
										
											2024-03-09 21:45:10 -08:00
										 |  |  |           filtered_args = args.named.dup.delete_if do |n| | 
					
						
							| 
									
										
										
										
											2024-06-11 03:20:09 +01:00
										 |  |  |             Homebrew.failed = true unless Cask::Caskroom.path.join(n).exist? | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |             !Cask::Caskroom.path.join(n).exist? | 
					
						
							| 
									
										
										
										
											2024-03-09 21:45:10 -08:00
										 |  |  |           end | 
					
						
							|  |  |  |           # NamedAargs subclasses array | 
					
						
							|  |  |  |           T.cast(filtered_args, Homebrew::CLI::NamedArgs).to_formulae_and_casks(only: :cask) | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |         end | 
					
						
							|  |  |  |         return if casks.blank? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Cask::List.list_casks( | 
					
						
							|  |  |  |           *casks, | 
					
						
							| 
									
										
										
										
											2024-03-15 12:51:03 -07:00
										 |  |  |           one:       args.public_send(:"1?"), | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |           full_name: args.full_name?, | 
					
						
							| 
									
										
										
										
											2024-03-15 12:51:03 -07:00
										 |  |  |           versions:  args.versions?, | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2014-09-06 19:12:03 -07:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2013-03-11 16:41:08 +01:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |     class PrettyListing | 
					
						
							| 
									
										
										
										
											2024-08-10 22:26:32 +01:00
										 |  |  |       sig { params(path: T.any(String, Pathname, Keg)).void } | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |       def initialize(path) | 
					
						
							|  |  |  |         Pathname.new(path).children.sort_by { |p| p.to_s.downcase }.each do |pn| | 
					
						
							|  |  |  |           case pn.basename.to_s | 
					
						
							|  |  |  |           when "bin", "sbin" | 
					
						
							|  |  |  |             pn.find { |pnn| puts pnn unless pnn.directory? } | 
					
						
							|  |  |  |           when "lib" | 
					
						
							|  |  |  |             print_dir pn do |pnn| | 
					
						
							|  |  |  |               # dylibs have multiple symlinks and we don't care about them | 
					
						
							|  |  |  |               (pnn.extname == ".dylib" || pnn.extname == ".pc") && !pnn.symlink? | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  |           when ".brew" | 
					
						
							|  |  |  |             next # Ignore .brew | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |           else | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |             if pn.directory? | 
					
						
							|  |  |  |               if pn.symlink? | 
					
						
							|  |  |  |                 puts "#{pn} -> #{pn.readlink}" | 
					
						
							|  |  |  |               else | 
					
						
							|  |  |  |                 print_dir pn | 
					
						
							|  |  |  |               end | 
					
						
							|  |  |  |             elsif Metafiles.list?(pn.basename.to_s) | 
					
						
							|  |  |  |               puts pn | 
					
						
							|  |  |  |             end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-09 21:45:10 -08:00
										 |  |  |       private | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-10 22:26:32 +01:00
										 |  |  |       sig { params(root: Pathname, block: T.nilable(T.proc.params(arg0: Pathname).returns(T::Boolean))).void } | 
					
						
							|  |  |  |       def print_dir(root, &block) | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |         dirs = [] | 
					
						
							|  |  |  |         remaining_root_files = [] | 
					
						
							|  |  |  |         other = "" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         root.children.sort.each do |pn| | 
					
						
							|  |  |  |           if pn.directory? | 
					
						
							|  |  |  |             dirs << pn | 
					
						
							| 
									
										
										
										
											2024-08-10 22:26:32 +01:00
										 |  |  |           elsif block && yield(pn) | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |             puts pn | 
					
						
							|  |  |  |             other = "other " | 
					
						
							|  |  |  |           elsif pn.basename.to_s != ".DS_Store" | 
					
						
							|  |  |  |             remaining_root_files << pn | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |         dirs.each do |d| | 
					
						
							|  |  |  |           files = [] | 
					
						
							|  |  |  |           d.find { |pn| files << pn unless pn.directory? } | 
					
						
							|  |  |  |           print_remaining_files files, d | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |         print_remaining_files remaining_root_files, root, other | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-10 22:26:32 +01:00
										 |  |  |       sig { params(files: T::Array[Pathname], root: Pathname, other: String).void } | 
					
						
							| 
									
										
										
										
											2024-03-03 15:32:30 -08:00
										 |  |  |       def print_remaining_files(files, root, other = "") | 
					
						
							|  |  |  |         if files.length == 1
 | 
					
						
							|  |  |  |           puts files | 
					
						
							|  |  |  |         elsif files.length > 1
 | 
					
						
							|  |  |  |           puts "#{root}/ (#{files.length} #{other}files)" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |