5 $stderr.printf("fatal: %s\n" % fmt, *args)
10 sha1.unpack('H*').first
13 class CommandError < RuntimeError
15 def initialize(command)
20 Array(@command).join(' ').inspect
27 raise CommandError.new(cmd) unless $?.success?
31 def skip_prefix(prefix)
32 return self[prefix.length..-1]
40 attr_reader :short, :long, :help
42 def initialize(short, long, help, &block)
58 def on(short = nil, long = nil, help: nil, &block)
59 opt = Option.new(short, long, help, &block)
60 @list[short] = opt if short
61 @list[long] = opt if long
65 if ARGV.member?('-h') or ARGV.member?('--help')
70 ARGV.delete_if do |cur|
72 next false if cur[0] != '-' or seen_dash
80 when /^-([^-])(.+)?$/, /^--(.+?)(?:=(.+))?$/
96 return str ? prefix + str : nil
98 puts 'usage: %s' % @usage
99 @list.values.uniq.each do |opt|
102 s << [fmt('-', opt.short), fmt('--', opt.long)].compact.join(', ')
104 s << '%*s%s' % [26 - s.size, '', opt.help] if opt.help