outdate-bundled-gems.rb: Add --help option

This commit is contained in:
Nobuyoshi Nakada 2024-03-15 13:55:47 +09:00
parent a1ced60692
commit f082605735
No known key found for this signature in database
GPG Key ID: 3582D74E1FEE4465

View File

@ -3,34 +3,52 @@ require 'fileutils'
require 'rubygems'
fu = FileUtils::Verbose
until ARGV.empty?
case ARGV.first
when '--'
ARGV.shift
break
when '-n', '--dryrun'
## -n, --dryrun Don't remove
fu = FileUtils::DryRun
when /\A--make=/
# just to run when `make -n`
when /\A--mflags=(.*)/
fu = FileUtils::DryRun if /\A-\S*n/ =~ $1
when /\A--gem[-_]platform=(.*)/im
## --gem-platform=PLATFORM Platform in RubyGems style
gem_platform = $1
ruby_platform = nil
when /\A--ruby[-_]platform=(.*)/im
## --ruby-platform=PLATFORM Platform in Ruby style
ruby_platform = $1
gem_platform = nil
when /\A--ruby[-_]version=(.*)/im
## --ruby-version=VERSION Ruby version to keep
ruby_version = $1
when /\A--only=(?:(curdir|srcdir)|all)\z/im
## --only=(curdir|srcdir|all) Specify directory to remove gems from
only = $1&.downcase
when /\A--all\z/im
## --all Remove all gems not only bundled gems
all = true
when /\A--help\z/im
## --help Print this message
puts "Usage: #$0 [options] [srcdir]"
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-/
raise "#{$0}: unknown option: #{ARGV.first}"
else
break
end
##
ARGV.shift
end