Parse command-line options
This commit is contained in:
parent
a9ff93dda4
commit
75a1049040
@ -1,10 +1,41 @@
|
||||
module Imbecile
|
||||
module CLI
|
||||
|
||||
USAGE = <<EOF
|
||||
Usage: #{$0} [options] <input-file>
|
||||
Options:
|
||||
--version Show program version and exit
|
||||
-h, --help Show this usage and exit
|
||||
EOF
|
||||
|
||||
class << self
|
||||
|
||||
def run(args)
|
||||
p args
|
||||
input_file = nil
|
||||
args.each do |arg|
|
||||
case arg
|
||||
when "--version"
|
||||
puts "imbecile v#{VERSION}"
|
||||
return 0
|
||||
when "-h", "--help"
|
||||
puts USAGE
|
||||
return 0
|
||||
when /^-/
|
||||
$stderr.puts "Error: unknown option #{arg}"
|
||||
return 1
|
||||
else
|
||||
if input_file
|
||||
$stderr.puts "Error: only one input file supported"
|
||||
return 1
|
||||
else
|
||||
input_file = arg
|
||||
end
|
||||
end
|
||||
end
|
||||
if input_file.nil?
|
||||
$stderr.puts "Error: must specify input file"
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user