5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/web_loader/downloader.rb', line 5
def self.run(argv)
STDOUT.sync = true
opts = {}
opt = OptionParser.new(argv)
opt.banner = "Usage: #{opt.program_name} [-h|--help] [Options] <URL> "
opt.version = WebLoader::VERSION
opt.separator('')
opt.separator("Options:")
opt.on_head('-h', '--help', 'Show this message') do |v|
puts opt.help
exit
end
opt.on('-v', '--verbose', 'Verbose message') {|v| opts[:v] = v}
drivers = ['pureruby', 'selenium']
opt.on('-d DRIVER', '--driver=DRIVER', drivers, drivers.join("|") + "(default pureruby)") {|v| opts[:d] = v }
opt.on("--disable-cache", "Disable cache") {|v| opts[:disable_cache] = v }
opt.on('--user-agent=USERAGENT', 'Set User-Agent header') {|v| opts[:user_agent] = v }
opt.on('-b', '--binary', 'Download binary files') {|v| opts[:binary] = v }
opt.on('--cache-dir=DIR', 'Cache directory (default ./cache)') {|v| opts[:cache_dir] = v }
begin
opt.parse!(argv)
rescue OptionParser::ParseError => e
warn "Error: #{e.message}"
puts opt.help
exit 1
end
if argv.empty?
warn "Error: URL is required."
puts opt.help
exit 1
end
command = self.new(opts)
url = argv[0]
command.execute(url)
end
|