Module: Homebrew::Manpages Private
- Defined in:
- manpages.rb,
manpages/parser/ronn.rb,
manpages/converter/roff.rb,
manpages/converter/kramdown.rb
Overview
This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.
Helper functions for generating homebrew manual.
Defined Under Namespace
Modules: Converter, Parser Classes: Variables
Constant Summary collapse
- SOURCE_PATH =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
T.let((HOMEBREW_LIBRARY_PATH/"manpages").freeze, Pathname)
- TARGET_MAN_PATH =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
T.let((HOMEBREW_REPOSITORY/"manpages").freeze, Pathname)
- TARGET_DOC_PATH =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
T.let((HOMEBREW_REPOSITORY/"docs").freeze, Pathname)
Class Method Summary collapse
- .build_man_page(quiet:) ⇒ String private
- .cmd_comment_manpage_lines(cmd_path) ⇒ Array<String>? private
- .cmd_parser_manpage_lines(cmd_parser) ⇒ Array<String> private
- .env_vars_manpage ⇒ String private
- .format_opt(opt) ⇒ String? private
- .format_usage_banner(usage_banner) ⇒ String private
- .generate_cmd_manpages(cmd_paths) ⇒ String private
- .generate_option_doc(short, long, desc) ⇒ String private
- .global_cask_options_manpage ⇒ String private
- .global_options_manpage ⇒ String private
- .regenerate_man_pages(quiet:) ⇒ void private
- .sort_key_for_path(path) ⇒ String private
Class Method Details
.build_man_page(quiet:) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'manpages.rb', line 46 def self.build_man_page(quiet:) template = (SOURCE_PATH/"brew.1.md.erb").read readme = HOMEBREW_REPOSITORY/"README.md" variables = Variables.new( commands: generate_cmd_manpages(Commands.internal_commands_paths), developer_commands: generate_cmd_manpages(Commands.internal_developer_commands_paths), global_cask_options: , global_options: , environment_variables: env_vars_manpage, project_leader: readme.read[/(Homebrew's \[Project Leader.*\.)/, 1] .gsub(/\[([^\]]+)\]\([^)]+\)/, '\1'), lead_maintainers: readme.read[/(Homebrew's \[Lead Maintainers.*\.)/, 1] .gsub(/\[([^\]]+)\]\([^)]+\)/, '\1'), maintainers: readme.read[/(Homebrew's other Maintainers .*\.)/, 1] .gsub(/\[([^\]]+)\]\([^)]+\)/, '\1'), ) ERB.new(template, trim_mode: ">").result(variables.instance_eval { binding }) end |
.cmd_comment_manpage_lines(cmd_path) ⇒ Array<String>?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'manpages.rb', line 143 def self.cmd_comment_manpage_lines(cmd_path) comment_lines = cmd_path.read.lines.grep(/^#:/) return if comment_lines.empty? first_comment_line = comment_lines.first return unless first_comment_line return if first_comment_line.include?("@hide_from_man_page") lines = [(first_comment_line).chomp] all_but_first_comment_lines = comment_lines.slice(1..-1) return unless all_but_first_comment_lines return if all_but_first_comment_lines.empty? all_but_first_comment_lines.each do |line| line = line.slice(4..-2) unless line lines.last << "\n" next end # Omit the common global_options documented separately in the man page. next if line.match?(/--(debug|help|quiet|verbose) /) # Format one option or a comma-separated pair of short and long options. line.gsub!(/^ +(-+[a-z-]+), (-+[a-z-]+) +(.*)$/, "`\\1`, `\\2`\n\n: \\3\n") line.gsub!(/^ +(-+[a-z-]+) +(.*)$/, "`\\1`\n\n: \\2\n") lines << line end lines.last << "\n" lines end |
.cmd_parser_manpage_lines(cmd_parser) ⇒ Array<String>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'manpages.rb', line 96 def self.cmd_parser_manpage_lines(cmd_parser) lines = [] if cmd_parser.subcommands.present? = cmd_parser. lines << "#{()}\n\n" if if (description = cmd_parser.description).present? lines << "#{description}\n\n" end = cmd_parser. lines += option_manpage_lines() cmd_parser.subcommands.each do |subcommand| next if subcommand.hidden = subcommand. next if .blank? lines << "#{format_usage_text()}\n\n" lines += option_manpage_lines(cmd_parser.(subcommand.name) - ) end else = cmd_parser. lines << () if lines += option_manpage_lines(cmd_parser.) end lines end |
.env_vars_manpage ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'manpages.rb', line 196 def self.env_vars_manpage lines = Homebrew::EnvConfig::ENVS.filter_map do |env, hash| next if Homebrew::EnvConfig.hidden?(hash) entry = "`#{env}`\n\n: #{hash[:description]}\n" default = Homebrew::EnvConfig.default_description(env) entry += "\n\n *Default:* #{default}\n" if default entry end lines.join("\n") end |
.format_opt(opt) ⇒ String?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
210 211 212 |
# File 'manpages.rb', line 210 def self.format_opt(opt) "`#{opt}`" unless opt.nil? end |
.format_usage_banner(usage_banner) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
236 237 238 |
# File 'manpages.rb', line 236 def self.() format_usage_text().sub(/^(?:#: *\* )?/, "### ") end |
.generate_cmd_manpages(cmd_paths) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'manpages.rb', line 73 def self.generate_cmd_manpages(cmd_paths) man_page_lines = [] # preserve existing manpage order cmd_paths.sort_by { sort_key_for_path(it) } .each do |cmd_path| cmd_man_page_lines = if (cmd_parser = Homebrew::CLI::Parser.from_cmd_path(cmd_path)) next if cmd_parser.hide_from_man_page cmd_parser_manpage_lines(cmd_parser).join else cmd_comment_manpage_lines(cmd_path)&.join("\n") end # Convert subcommands to definition lists cmd_man_page_lines&.gsub!(/(?<=\n\n)([\\?\[`].+):\n/, "\\1\n\n: ") man_page_lines << cmd_man_page_lines end man_page_lines.compact.join("\n") end |
.generate_option_doc(short, long, desc) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'manpages.rb', line 221 def self.generate_option_doc(short, long, desc) comma = if short && long ", " else "" end <<~EOS #{format_opt(short)}#{comma}#{format_opt(long)} : #{desc} EOS end |
.global_cask_options_manpage ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
177 178 179 180 181 182 183 184 |
# File 'manpages.rb', line 177 def self. lines = ["These options are applicable to the `install`, `reinstall` and `upgrade` " \ "subcommands with the `--cask` switch.\n"] lines += Homebrew::CLI::Parser..map do |_, long, kwargs| generate_option_doc(nil, long.chomp("="), kwargs.fetch(:description)) end lines.join("\n") end |
.global_options_manpage ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
187 188 189 190 191 192 193 |
# File 'manpages.rb', line 187 def self. lines = ["These options are applicable across multiple subcommands.\n"] lines += Homebrew::CLI::Parser..map do |short, long, desc| generate_option_doc(short, long, desc) end lines.join("\n") end |
.regenerate_man_pages(quiet:) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'manpages.rb', line 26 def self.regenerate_man_pages(quiet:) require "kramdown" require "manpages/parser/ronn" require "manpages/converter/kramdown" require "manpages/converter/roff" markup = build_man_page(quiet:) root, warnings = Parser::Ronn.parse(markup) $stderr.puts(warnings) roff, warnings = Converter::Kramdown.convert(root) $stderr.puts(warnings) File.write(TARGET_DOC_PATH/"Manpage.md", roff) roff, warnings = Converter::Roff.convert(root) $stderr.puts(warnings) File.write(TARGET_MAN_PATH/"brew.1", roff) end |
.sort_key_for_path(path) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
67 68 69 70 |
# File 'manpages.rb', line 67 def self.sort_key_for_path(path) # Options after regular commands (`~` comes after `z` in ASCII table). path.basename.to_s.sub(/\.(?:rb|sh)$/, "").sub(/^--/, "~~") end |