CLI: accept --log option
This commit is contained in:
parent
d2fac07249
commit
d552f2a540
@ -22,10 +22,10 @@ module Imbecile
|
|||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
def run(input_file, output_file)
|
def run(input_file, output_file, log_file)
|
||||||
begin
|
begin
|
||||||
grammar = Grammar.new(File.read(input_file))
|
grammar = Grammar.new(File.read(input_file))
|
||||||
generator = Generator.new(grammar)
|
generator = Generator.new(grammar, log_file)
|
||||||
generator.generate(output_file)
|
generator.generate(output_file)
|
||||||
rescue Error => e
|
rescue Error => e
|
||||||
$stderr.puts e.message
|
$stderr.puts e.message
|
||||||
|
@ -4,6 +4,7 @@ module Imbecile
|
|||||||
USAGE = <<EOF
|
USAGE = <<EOF
|
||||||
Usage: #{$0} [options] <input-file> <output-file>
|
Usage: #{$0} [options] <input-file> <output-file>
|
||||||
Options:
|
Options:
|
||||||
|
--log LOG Write log file
|
||||||
--version Show program version and exit
|
--version Show program version and exit
|
||||||
-h, --help Show this usage and exit
|
-h, --help Show this usage and exit
|
||||||
EOF
|
EOF
|
||||||
@ -11,9 +12,17 @@ EOF
|
|||||||
class << self
|
class << self
|
||||||
|
|
||||||
def run(args)
|
def run(args)
|
||||||
extra_args = []
|
params = []
|
||||||
args.each do |arg|
|
log_file = nil
|
||||||
|
i = 0
|
||||||
|
while i < args.size
|
||||||
|
arg = args[i]
|
||||||
case arg
|
case arg
|
||||||
|
when "--log"
|
||||||
|
if i + 1 < args.size
|
||||||
|
i += 1
|
||||||
|
log_file = args[i]
|
||||||
|
end
|
||||||
when "--version"
|
when "--version"
|
||||||
puts "imbecile v#{VERSION}"
|
puts "imbecile v#{VERSION}"
|
||||||
return 0
|
return 0
|
||||||
@ -24,18 +33,19 @@ EOF
|
|||||||
$stderr.puts "Error: unknown option #{arg}"
|
$stderr.puts "Error: unknown option #{arg}"
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
extra_args << arg
|
params << arg
|
||||||
end
|
end
|
||||||
|
i += 1
|
||||||
end
|
end
|
||||||
if extra_args.size != 2
|
if params.size != 2
|
||||||
$stderr.puts "Error: specify input and output files"
|
$stderr.puts "Error: specify input and output files"
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
unless File.readable?(args[0])
|
unless File.readable?(params[0])
|
||||||
$stderr.puts "Error: cannot read #{args[0]}"
|
$stderr.puts "Error: cannot read #{params[0]}"
|
||||||
return 2
|
return 2
|
||||||
end
|
end
|
||||||
Imbecile.run(*args)
|
Imbecile.run(*params, log_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -3,8 +3,9 @@ module Imbecile
|
|||||||
# Class to generate the parser generator source.
|
# Class to generate the parser generator source.
|
||||||
class Generator
|
class Generator
|
||||||
|
|
||||||
def initialize(grammar)
|
def initialize(grammar, log_file)
|
||||||
@grammar = grammar
|
@grammar = grammar
|
||||||
|
@log_file = log_file
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate(output_file)
|
def generate(output_file)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user