| 
									
										
										
										
											2019-11-04 21:00:20 +11:00
										 |  |  | # frozen_string_literal: true | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "formula" | 
					
						
							| 
									
										
										
										
											2016-04-17 05:33:21 +02:00
										 |  |  | require "erb" | 
					
						
							| 
									
										
										
										
											2016-04-19 19:43:32 +08:00
										 |  |  | require "ostruct" | 
					
						
							| 
									
										
										
										
											2019-04-17 18:25:08 +09:00
										 |  |  | require "cli/parser" | 
					
						
							| 
									
										
										
										
											2014-09-20 15:30:44 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-19 21:46:20 +09:00
										 |  |  |   SOURCE_PATH = (HOMEBREW_LIBRARY_PATH/"manpages").freeze | 
					
						
							|  |  |  |   TARGET_MAN_PATH = (HOMEBREW_REPOSITORY/"manpages").freeze | 
					
						
							|  |  |  |   TARGET_DOC_PATH = (HOMEBREW_REPOSITORY/"docs").freeze | 
					
						
							| 
									
										
										
										
											2014-09-20 15:30:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-30 18:25:38 +05:30
										 |  |  |   def man_args | 
					
						
							|  |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							| 
									
										
										
										
											2019-11-04 21:00:20 +11:00
										 |  |  |       usage_banner <<~EOS | 
					
						
							| 
									
										
										
										
											2018-10-15 15:06:33 -04:00
										 |  |  |         `man` [<options>] | 
					
						
							| 
									
										
										
										
											2018-09-28 21:39:52 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |         Generate Homebrew's manpages. | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  |       switch "--fail-if-changed", | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |              description: "Return a failing status code if changes are detected in the manpage outputs. This "\ | 
					
						
							| 
									
										
										
										
											2019-08-20 00:04:14 -04:00
										 |  |  |                           "can be used to notify CI when the manpages are out of date. Additionally, "\ | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |                           "the date used in new manpages will match those in the existing manpages (to allow "\ | 
					
						
							|  |  |  |                           "comparison without factoring in the date)." | 
					
						
							| 
									
										
										
										
											2018-09-28 21:39:52 +05:30
										 |  |  |       switch "--link", | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |              description: "This is now done automatically by `brew update`." | 
					
						
							| 
									
										
										
										
											2019-12-13 16:50:54 -05:00
										 |  |  |       max_named 0
 | 
					
						
							| 
									
										
										
										
											2018-03-25 17:48:22 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-07-30 18:25:38 +05:30
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def man | 
					
						
							|  |  |  |     man_args.parse | 
					
						
							| 
									
										
										
										
											2018-03-24 21:26:16 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-19 13:11:32 +00:00
										 |  |  |     odie "`brew man --link` is now done automatically by `brew update`." if args.link? | 
					
						
							| 
									
										
										
										
											2016-09-28 03:28:20 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-17 18:03:40 -04:00
										 |  |  |     Commands.rebuild_internal_commands_completion_list | 
					
						
							| 
									
										
										
										
											2017-01-23 18:48:51 +00:00
										 |  |  |     regenerate_man_pages | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-17 18:03:40 -04:00
										 |  |  |     if system "git", "-C", HOMEBREW_REPOSITORY, "diff", "--quiet", "docs/Manpage.md", "manpages", "completions" | 
					
						
							|  |  |  |       puts "No changes to manpage or completions output detected." | 
					
						
							| 
									
										
										
										
											2018-05-05 18:40:01 +05:30
										 |  |  |     elsif args.fail_if_changed? | 
					
						
							| 
									
										
										
										
											2016-09-28 03:28:20 -07:00
										 |  |  |       Homebrew.failed = true | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-04-17 02:28:58 +02:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def regenerate_man_pages | 
					
						
							| 
									
										
										
										
											2019-01-08 15:08:21 +00:00
										 |  |  |     Homebrew.install_bundler_gems! | 
					
						
							| 
									
										
										
										
											2016-04-17 02:28:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-17 03:04:27 +02:00
										 |  |  |     markup = build_man_page | 
					
						
							| 
									
										
										
										
											2017-03-22 21:37:09 +00:00
										 |  |  |     convert_man_page(markup, TARGET_DOC_PATH/"Manpage.md") | 
					
						
							| 
									
										
										
										
											2016-04-17 03:04:27 +02:00
										 |  |  |     convert_man_page(markup, TARGET_MAN_PATH/"brew.1") | 
					
						
							| 
									
										
										
										
											2016-08-20 16:36:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-23 01:22:54 -04:00
										 |  |  |     cask_markup = (SOURCE_PATH/"brew-cask.1.md").read | 
					
						
							| 
									
										
										
										
											2016-08-20 16:36:34 +01:00
										 |  |  |     convert_man_page(cask_markup, TARGET_MAN_PATH/"brew-cask.1") | 
					
						
							| 
									
										
										
										
											2016-04-17 02:28:58 +02:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-05 21:46:40 +01:00
										 |  |  |   def build_man_page | 
					
						
							|  |  |  |     template = (SOURCE_PATH/"brew.1.md.erb").read | 
					
						
							|  |  |  |     variables = OpenStruct.new | 
					
						
							| 
									
										
										
										
											2016-04-17 02:28:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 17:05:45 +01:00
										 |  |  |     variables[:commands] = generate_cmd_manpages(Commands.internal_commands_paths) | 
					
						
							|  |  |  |     variables[:developer_commands] = generate_cmd_manpages(Commands.internal_developer_commands_paths) | 
					
						
							| 
									
										
										
										
											2020-03-11 12:22:46 +00:00
										 |  |  |     variables[:official_external_commands] = generate_cmd_manpages(Commands.official_external_commands_paths) | 
					
						
							| 
									
										
										
										
											2019-01-30 21:33:30 +00:00
										 |  |  |     variables[:global_options] = global_options_manpage | 
					
						
							| 
									
										
										
										
											2020-04-06 10:11:34 +01:00
										 |  |  |     variables[:environment_variables] = env_vars_manpage | 
					
						
							| 
									
										
										
										
											2018-09-28 21:39:52 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-20 09:31:06 +01:00
										 |  |  |     readme = HOMEBREW_REPOSITORY/"README.md" | 
					
						
							| 
									
										
										
										
											2019-02-04 17:09:31 +01:00
										 |  |  |     variables[:lead] = | 
					
						
							| 
									
										
										
										
											2019-02-15 10:54:30 +00:00
										 |  |  |       readme.read[/(Homebrew's \[Project Leader.*\.)/, 1] | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |             .gsub(/\[([^\]]+)\]\([^)]+\)/, '\1') | 
					
						
							| 
									
										
										
										
											2019-02-04 17:09:31 +01:00
										 |  |  |     variables[:plc] = | 
					
						
							| 
									
										
										
										
											2019-02-15 10:54:30 +00:00
										 |  |  |       readme.read[/(Homebrew's \[Project Leadership Committee.*\.)/, 1] | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |             .gsub(/\[([^\]]+)\]\([^)]+\)/, '\1') | 
					
						
							| 
									
										
										
										
											2019-02-04 17:09:31 +01:00
										 |  |  |     variables[:tsc] = | 
					
						
							| 
									
										
										
										
											2019-02-15 10:54:30 +00:00
										 |  |  |       readme.read[/(Homebrew's \[Technical Steering Committee.*\.)/, 1] | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |             .gsub(/\[([^\]]+)\]\([^)]+\)/, '\1') | 
					
						
							| 
									
										
										
										
											2019-02-04 17:09:31 +01:00
										 |  |  |     variables[:linux] = | 
					
						
							| 
									
										
										
										
											2019-03-12 20:13:38 +00:00
										 |  |  |       readme.read[%r{(Homebrew/brew's Linux maintainers .*\.)}, 1] | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |             .gsub(/\[([^\]]+)\]\([^)]+\)/, '\1') | 
					
						
							| 
									
										
										
										
											2019-02-04 17:09:31 +01:00
										 |  |  |     variables[:maintainers] = | 
					
						
							|  |  |  |       readme.read[/(Homebrew's other current maintainers .*\.)/, 1] | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |             .gsub(/\[([^\]]+)\]\([^)]+\)/, '\1') | 
					
						
							| 
									
										
										
										
											2019-02-04 17:09:31 +01:00
										 |  |  |     variables[:alumni] = | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |       readme.read[/(Former maintainers .*\.)/, 1] | 
					
						
							|  |  |  |             .gsub(/\[([^\]]+)\]\([^)]+\)/, '\1') | 
					
						
							| 
									
										
										
										
											2016-06-14 21:01:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-13 10:09:38 +01:00
										 |  |  |     ERB.new(template, trim_mode: ">").result(variables.instance_eval { binding }) | 
					
						
							| 
									
										
										
										
											2016-04-17 02:28:58 +02:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-17 09:36:48 +02:00
										 |  |  |   def sort_key_for_path(path) | 
					
						
							|  |  |  |     # Options after regular commands (`~` comes after `z` in ASCII table). | 
					
						
							|  |  |  |     path.basename.to_s.sub(/\.(rb|sh)$/, "").sub(/^--/, "~~") | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-17 03:04:27 +02:00
										 |  |  |   def convert_man_page(markup, target) | 
					
						
							| 
									
										
										
										
											2016-10-01 11:49:39 +01:00
										 |  |  |     manual = target.basename(".1") | 
					
						
							|  |  |  |     organisation = "Homebrew" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Set the manpage date to the existing one if we're checking for changes. | 
					
						
							|  |  |  |     # This avoids the only change being e.g. a new date. | 
					
						
							| 
									
										
										
										
											2018-05-05 18:40:01 +05:30
										 |  |  |     date = if args.fail_if_changed? && | 
					
						
							| 
									
										
										
										
											2016-10-01 11:49:39 +01:00
										 |  |  |               target.extname == ".1" && target.exist? | 
					
						
							|  |  |  |       /"(\d{1,2})" "([A-Z][a-z]+) (\d{4})" "#{organisation}" "#{manual}"/ =~ target.read | 
					
						
							| 
									
										
										
										
											2017-06-10 20:23:20 +03:00
										 |  |  |       Date.parse("#{Regexp.last_match(1)} #{Regexp.last_match(2)} #{Regexp.last_match(3)}") | 
					
						
							| 
									
										
										
										
											2016-10-01 11:49:39 +01:00
										 |  |  |     else | 
					
						
							|  |  |  |       Date.today | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     date = date.strftime("%Y-%m-%d") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-17 02:28:58 +02:00
										 |  |  |     shared_args = %W[
 | 
					
						
							|  |  |  |       --pipe | 
					
						
							| 
									
										
										
										
											2016-10-01 11:49:39 +01:00
										 |  |  |       --organization=#{organisation} | 
					
						
							| 
									
										
										
										
											2016-08-20 16:36:34 +01:00
										 |  |  |       --manual=#{target.basename(".1")} | 
					
						
							| 
									
										
										
										
											2016-10-01 11:49:39 +01:00
										 |  |  |       --date=#{date} | 
					
						
							| 
									
										
										
										
											2016-04-17 02:28:58 +02:00
										 |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     format_flag, format_desc = target_path_to_format(target) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     puts "Writing #{format_desc} to #{target}" | 
					
						
							| 
									
										
										
										
											2016-04-17 03:04:27 +02:00
										 |  |  |     Utils.popen(["ronn", format_flag] + shared_args, "rb+") do |ronn| | 
					
						
							|  |  |  |       ronn.write markup | 
					
						
							|  |  |  |       ronn.close_write | 
					
						
							| 
									
										
										
										
											2017-04-02 10:13:38 +01:00
										 |  |  |       ronn_output = ronn.read | 
					
						
							| 
									
										
										
										
											2019-10-08 10:49:02 +01:00
										 |  |  |       odie "Got no output from ronn!" if ronn_output.blank? | 
					
						
							| 
									
										
										
										
											2018-10-02 21:56:00 -04:00
										 |  |  |       if format_flag == "--markdown" | 
					
						
							| 
									
										
										
										
											2018-10-06 00:31:10 -04:00
										 |  |  |         ronn_output = ronn_output.gsub(%r{<var>(.*?)</var>}, "*`\\1`*") | 
					
						
							| 
									
										
										
										
											2019-01-30 21:33:30 +00:00
										 |  |  |                                  .gsub(/\n\n\n+/, "\n\n") | 
					
						
							| 
									
										
										
										
											2018-10-02 21:56:00 -04:00
										 |  |  |       elsif format_flag == "--roff" | 
					
						
							| 
									
										
										
										
											2018-10-03 10:19:46 +05:30
										 |  |  |         ronn_output = ronn_output.gsub(%r{<code>(.*?)</code>}, "\\fB\\1\\fR") | 
					
						
							|  |  |  |                                  .gsub(%r{<var>(.*?)</var>}, "\\fI\\1\\fR") | 
					
						
							| 
									
										
										
										
											2018-10-02 21:56:00 -04:00
										 |  |  |                                  .gsub(/(^\[?\\fB.+): /, "\\1\n    ") | 
					
						
							| 
									
										
										
										
											2018-10-02 19:54:22 +05:30
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2017-04-02 10:13:38 +01:00
										 |  |  |       target.atomic_write ronn_output | 
					
						
							| 
									
										
										
										
											2016-04-17 03:04:27 +02:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-04-17 02:28:58 +02:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def target_path_to_format(target) | 
					
						
							|  |  |  |     case target.basename | 
					
						
							| 
									
										
										
										
											2017-03-22 21:37:09 +00:00
										 |  |  |     when /\.md$/    then ["--markdown", "markdown"] | 
					
						
							| 
									
										
										
										
											2016-04-17 02:28:58 +02:00
										 |  |  |     when /\.\d$/    then ["--roff", "man page"] | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       odie "Failed to infer output format from '#{target.basename}'." | 
					
						
							| 
									
										
										
										
											2014-09-20 15:30:44 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2018-09-08 22:21:04 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 17:05:45 +01:00
										 |  |  |   def generate_cmd_manpages(cmd_paths) | 
					
						
							| 
									
										
										
										
											2018-09-28 21:39:52 +05:30
										 |  |  |     man_page_lines = [] | 
					
						
							| 
									
										
										
										
											2018-10-24 01:17:38 +05:30
										 |  |  |     man_args = Homebrew.args | 
					
						
							| 
									
										
										
										
											2019-01-30 21:33:30 +00:00
										 |  |  |     # preserve existing manpage order | 
					
						
							|  |  |  |     cmd_paths.sort_by(&method(:sort_key_for_path)) | 
					
						
							|  |  |  |              .each do |cmd_path| | 
					
						
							| 
									
										
										
										
											2020-02-02 11:32:50 +01:00
										 |  |  |       cmd_man_page_lines = if cmd_parser = CLI::Parser.from_cmd_path(cmd_path) | 
					
						
							| 
									
										
										
										
											2019-01-30 21:33:30 +00:00
										 |  |  |         next if cmd_parser.hide_from_man_page | 
					
						
							| 
									
										
										
										
											2019-02-19 13:12:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-30 21:33:30 +00:00
										 |  |  |         cmd_parser_manpage_lines(cmd_parser).join | 
					
						
							| 
									
										
										
										
											2020-02-02 11:32:50 +01:00
										 |  |  |       else | 
					
						
							|  |  |  |         cmd_comment_manpage_lines(cmd_path) | 
					
						
							| 
									
										
										
										
											2018-09-28 21:39:52 +05:30
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2019-01-30 21:33:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       man_page_lines << cmd_man_page_lines | 
					
						
							| 
									
										
										
										
											2018-09-28 21:39:52 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-10-24 01:17:38 +05:30
										 |  |  |     Homebrew.args = man_args | 
					
						
							| 
									
										
										
										
											2019-01-30 21:33:30 +00:00
										 |  |  |     man_page_lines.compact.join("\n") | 
					
						
							| 
									
										
										
										
											2018-09-28 21:39:52 +05:30
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-30 21:33:30 +00:00
										 |  |  |   def cmd_parser_manpage_lines(cmd_parser) | 
					
						
							| 
									
										
										
										
											2018-10-02 19:54:22 +05:30
										 |  |  |     lines = [format_usage_banner(cmd_parser.usage_banner_text)] | 
					
						
							| 
									
										
										
										
											2018-09-08 22:21:04 +05:30
										 |  |  |     lines += cmd_parser.processed_options.map do |short, long, _, desc| | 
					
						
							| 
									
										
										
										
											2019-08-21 12:42:09 -04:00
										 |  |  |       next if !long.nil? && cmd_parser.global_option?(cmd_parser.option_to_name(long), desc) | 
					
						
							| 
									
										
										
										
											2019-02-19 13:12:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-02 14:44:38 +05:30
										 |  |  |       generate_option_doc(short, long, desc) | 
					
						
							| 
									
										
										
										
											2019-01-30 21:33:30 +00:00
										 |  |  |     end.reject(&:blank?) | 
					
						
							|  |  |  |     lines | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def cmd_comment_manpage_lines(cmd_path) | 
					
						
							|  |  |  |     comment_lines = cmd_path.read.lines.grep(/^#:/) | 
					
						
							|  |  |  |     return if comment_lines.empty? | 
					
						
							|  |  |  |     return if comment_lines.first.include?("@hide_from_man_page") | 
					
						
							| 
									
										
										
										
											2019-02-19 13:12:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-30 21:33:30 +00:00
										 |  |  |     lines = [format_usage_banner(comment_lines.first).chomp] | 
					
						
							|  |  |  |     comment_lines.slice(1..-1) | 
					
						
							|  |  |  |                  .each do |line| | 
					
						
							| 
									
										
										
										
											2019-08-20 12:56:21 -04:00
										 |  |  |       line = line.slice(4..-2) | 
					
						
							|  |  |  |       unless line | 
					
						
							|  |  |  |         lines.last << "\n" | 
					
						
							|  |  |  |         next | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2019-02-19 13:12:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-15 01:15:58 -07:00
										 |  |  |       # Omit the common global_options documented separately in the man page. | 
					
						
							| 
									
										
										
										
											2019-10-13 19:26:39 +01:00
										 |  |  |       next if line.match?(/--(debug|force|help|quiet|verbose) /) | 
					
						
							| 
									
										
										
										
											2019-03-15 01:15:58 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-12 16:50:13 -08:00
										 |  |  |       # Format one option or a comma-separated pair of short and long options. | 
					
						
							|  |  |  |       lines << line.gsub(/^ +(-+[a-z-]+), (-+[a-z-]+) +/, "* `\\1`, `\\2`:\n  ") | 
					
						
							|  |  |  |                    .gsub(/^ +(-+[a-z-]+) +/, "* `\\1`:\n  ") | 
					
						
							| 
									
										
										
										
											2018-10-02 14:44:38 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2019-08-20 12:56:21 -04:00
										 |  |  |     lines.last << "\n" | 
					
						
							| 
									
										
										
										
											2018-10-02 14:44:38 +05:30
										 |  |  |     lines | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-30 21:33:30 +00:00
										 |  |  |   def global_options_manpage | 
					
						
							| 
									
										
										
										
											2020-03-11 12:16:47 +00:00
										 |  |  |     lines = ["These options are applicable across multiple subcommands.\n"] | 
					
						
							| 
									
										
										
										
											2018-10-02 14:44:38 +05:30
										 |  |  |     lines += Homebrew::CLI::Parser.global_options.values.map do |names, _, desc| | 
					
						
							|  |  |  |       short, long = names | 
					
						
							| 
									
										
										
										
											2018-09-08 22:21:04 +05:30
										 |  |  |       generate_option_doc(short, long, desc) | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2019-01-30 21:33:30 +00:00
										 |  |  |     lines.join("\n") | 
					
						
							| 
									
										
										
										
											2018-09-08 22:21:04 +05:30
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-06 10:11:34 +01:00
										 |  |  |   def env_vars_manpage | 
					
						
							|  |  |  |     lines = Homebrew::EnvConfig::ENVS.flat_map do |env, hash| | 
					
						
							|  |  |  |       entry = "  * `#{env}`:\n    #{hash[:description]}\n" | 
					
						
							|  |  |  |       default = hash[:default_text] | 
					
						
							|  |  |  |       default ||= "`#{hash[:default]}`." if hash[:default] | 
					
						
							|  |  |  |       entry += "\n\n    *Default:* #{default}\n" if default | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       entry | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     lines.join("\n") | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-08 22:21:04 +05:30
										 |  |  |   def generate_option_doc(short, long, desc) | 
					
						
							| 
									
										
										
										
											2018-10-15 14:55:58 -04:00
										 |  |  |     comma = (short && long) ? ", " : "" | 
					
						
							| 
									
										
										
										
											2020-04-06 10:11:34 +01:00
										 |  |  |     <<~EOS | 
					
						
							|  |  |  |       * #{format_short_opt(short)}#{comma}#{format_long_opt(long)}: | 
					
						
							|  |  |  |         #{desc} | 
					
						
							|  |  |  |     EOS | 
					
						
							| 
									
										
										
										
											2018-09-08 22:21:04 +05:30
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def format_short_opt(opt) | 
					
						
							| 
									
										
										
										
											2018-10-15 14:55:58 -04:00
										 |  |  |     "`#{opt}`" unless opt.nil? | 
					
						
							| 
									
										
										
										
											2018-09-08 22:21:04 +05:30
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def format_long_opt(opt) | 
					
						
							| 
									
										
										
										
											2018-10-15 14:55:58 -04:00
										 |  |  |     "`#{opt}`" unless opt.nil? | 
					
						
							| 
									
										
										
										
											2018-09-08 22:21:04 +05:30
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2018-10-02 14:44:38 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |   def format_usage_banner(usage_banner) | 
					
						
							| 
									
										
										
										
											2019-01-30 21:33:30 +00:00
										 |  |  |     usage_banner&.sub(/^(#: *\* )?/, "### ") | 
					
						
							| 
									
										
										
										
											2018-10-02 14:44:38 +05:30
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-09-20 15:30:44 +01:00
										 |  |  | end |