62
62
author "Esteban Manchado Vel�zquez"
63
63
copyright "Copyright (c) 2005-2007, Esteban Manchado Vel�zquez"
64
synopsis "[-h] -a doc-base_file | -d doc-base_file | -r"
64
synopsis "[-h] -a doc-base_file1 d-b_f2 ... | -d doc-base_file1 d-b_f2 ... | -r"
65
65
short_description "Debian online help system parser"
66
66
long_description "Dhelp parser to add/remove/reindex dhelp files"
69
option :names => %w(-a), :arity => 1,
69
option :names => %w(-a), :arity => [0,-1],
70
70
:opt_found => lambda {|opt, name, value| @action = :add;
71
@doc_base_file = value.first },
71
@doc_base_files = value },
72
72
:opt_description => "add documents registered in the given doc-base file"
73
option :names => %w(-d), :arity => 1,
73
option :names => %w(-d), :arity => [0,-1],
74
74
:opt_found => lambda {|opt, name, value| @action = :delete;
75
@doc_base_file = value.first },
76
:opt_description => "ignored, for compatibility"
75
@doc_base_files = value },
76
:opt_description => "remove documents registered in the given doc-base file"
77
77
option :names => %w(-r), :arity => [0,0],
78
78
:opt_found => lambda { @action = :reindex },
79
79
:opt_description => "ignored, for compatibility"
80
option :names => %w(-v), :arity => [0,0],
81
:opt_description => "verbose mode"
83
81
expected_args [0,0]
106
104
# List of directories to look for doc-base documents
107
105
doc_base_dirs = conf.search_directories.map {|d| File.expand_path(d)}
109
indexer = Indexer.new(:search_dirs => doc_base_dirs)
106
pool = Dhelp::DhelpDocumentPool.new(:doc_base_dir => doc_base_dirs)
113
# We are given a doc-base file. We have to extract its files and feed
114
# them to the indexer
115
if File.readable? @doc_base_file
116
doc_base_doc = Dhelp::DocBaseDocument.new(@doc_base_file)
117
indexer.index(doc_base_doc.files)
119
$stderr.puts "Can't read doc-base file '#{@doc_base_file}'"
110
@doc_base_files.each do |doc_base_file|
111
if File.readable? doc_base_file
112
doc_base_doc = Dhelp::DocBaseDocument.new(doc_base_file)
113
pool.register(doc_base_doc)
115
$stderr.puts "Can't read doc-base file '#{doc_base_file}'"
123
# There's no easy way to "unindex" a file apart from rebuilding the whole
124
# thing from scratch, so we'll have to leave with false positives in
125
# searches. However, the doc-base file is there when someone de-register
126
# a document, so we have to skip it when regenerating the documentation
128
deleted_docs = @doc_base_file
120
@doc_base_files.each do |doc_base_file|
121
pool.deregister(doc_base_file)
130
124
# Simply ignore, the documentation directory will be up-to-date anyway.
131
# See above note for :delete action.
133
126
$stderr.puts usage
137
130
# Always executed
138
pool = DocBaseDocumentPool.new(:dirs => doc_base_dirs,
139
:skip => deleted_docs)
140
131
exporter = Dhelp::Exporter::Html.new(pool)
141
132
exporter.export(:dir => DEFAULT_INDEX_ROOT)