downloader.rb: Add --help option

This commit is contained in:
Nobuyoshi Nakada 2024-03-15 14:11:16 +09:00
parent f082605735
commit eceb36c7b9
No known key found for this signature in database
GPG Key ID: 3582D74E1FEE4465

View File

@ -407,26 +407,42 @@ if $0 == __FILE__
case ARGV[0]
when '-d', '--destdir'
## -d, --destdir DIRECTORY Download into the directory
destdir = ARGV[1]
ARGV.shift
when '-p', '--prefix'
# strip directory names from the name to download, and add the
# prefix instead.
## -p, --prefix Strip directory names from the name to download,
## and add the prefix instead.
prefix = ARGV[1]
ARGV.shift
when '-e', '--exist', '--non-existent-only'
## -e, --exist, --non-existent-only Skip already existent files.
since = nil
when '-a', '--always'
## -a, --always Download all files.
since = false
when '-u', '--update', '--if-modified'
## -u, --update, --if-modified Download newer files only.
since = true
when '-n', '--dryrun'
## -n, --dryrun Do not download actually.
options[:dryrun] = true
when '--cache-dir'
## --cache-dir DIRECTORY Cache downloaded files in the directory.
options[:cache_dir] = ARGV[1]
ARGV.shift
when /\A--cache-dir=(.*)/m
options[:cache_dir] = $1
when /\A--help\z/
## --help Print this message
puts "Usage: #$0 [options] relative-url..."
File.foreach(__FILE__) do |line|
line.sub!(/^ *## /, "") or next
break if line.chomp!.empty?
opt, desc = line.split(/ {2,}/, 2)
printf " %-28s %s\n", opt, desc
end
exit
when /\A-/
abort "#{$0}: unknown option #{ARGV[0]}"
else