2015-08-03 13:09:07 +01:00
|
|
|
require "formula"
|
2014-09-20 15:30:44 +01:00
|
|
|
|
|
|
|
module Homebrew
|
|
|
|
SOURCE_PATH=HOMEBREW_REPOSITORY/"Library/Homebrew/manpages"
|
|
|
|
TARGET_PATH=HOMEBREW_REPOSITORY/"share/man/man1"
|
2015-08-29 10:56:24 +01:00
|
|
|
DOC_PATH=HOMEBREW_REPOSITORY/"share/doc/homebrew"
|
2014-09-20 15:30:44 +01:00
|
|
|
LINKED_PATH=HOMEBREW_PREFIX/"share/man/man1"
|
|
|
|
|
|
|
|
def man
|
2015-06-15 12:41:12 +02:00
|
|
|
abort <<-EOS.undent unless ARGV.named.empty?
|
|
|
|
This command updates the brew manpage and does not take formula names.
|
|
|
|
EOS
|
|
|
|
|
|
|
|
if ARGV.flag? "--link"
|
|
|
|
abort <<-EOS.undent if TARGET_PATH == LINKED_PATH
|
|
|
|
The target path is the same as the linked one, aborting.
|
|
|
|
EOS
|
2014-09-20 15:30:44 +01:00
|
|
|
Dir["#{TARGET_PATH}/*.1"].each do |page|
|
|
|
|
FileUtils.ln_s page, LINKED_PATH
|
|
|
|
return
|
|
|
|
end
|
2015-06-15 12:41:12 +02:00
|
|
|
else
|
|
|
|
Homebrew.install_gem_setup_path! "ronn"
|
2014-09-20 15:30:44 +01:00
|
|
|
|
2015-08-29 10:56:24 +01:00
|
|
|
puts "Writing HTML fragments to #{DOC_PATH}"
|
2015-06-15 12:41:12 +02:00
|
|
|
puts "Writing manpages to #{TARGET_PATH}"
|
2014-09-20 15:30:44 +01:00
|
|
|
|
2016-04-03 20:17:01 +02:00
|
|
|
header = (SOURCE_PATH/"header.1.md").read
|
|
|
|
footer = (SOURCE_PATH/"footer.1.md").read
|
|
|
|
sub_commands = Pathname.glob("#{HOMEBREW_LIBRARY_PATH}/cmd/*.{rb,sh}").
|
|
|
|
sort_by { |source_file| source_file.basename.sub(/\.(rb|sh)$/, "") }.
|
|
|
|
map { |source_file|
|
|
|
|
source_file.read.
|
|
|
|
split("\n").
|
|
|
|
grep(/^#:/).
|
|
|
|
map { |line| line.slice(2..-1) }.
|
|
|
|
join("\n")
|
|
|
|
}.
|
|
|
|
reject { |s| s.strip.empty? }.
|
|
|
|
join("\n\n")
|
|
|
|
|
|
|
|
target_md = SOURCE_PATH/"brew.1.md"
|
|
|
|
target_md.atomic_write(header + sub_commands + footer)
|
|
|
|
|
|
|
|
args = %W[
|
|
|
|
--pipe
|
|
|
|
--organization=Homebrew
|
|
|
|
--manual=brew
|
|
|
|
#{SOURCE_PATH}/brew.1.md
|
|
|
|
]
|
|
|
|
|
|
|
|
target_html = DOC_PATH/"brew.1.html"
|
|
|
|
target_html.atomic_write Utils.popen_read("ronn", "--fragment", *args)
|
|
|
|
|
|
|
|
target_man = TARGET_PATH/"brew.1"
|
|
|
|
target_man.atomic_write Utils.popen_read("ronn", "--roff", *args)
|
2014-09-20 15:30:44 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|