Require output file on command line
This commit is contained in:
parent
768a0ef17f
commit
c1666a1e74
@ -6,7 +6,7 @@ module Imbecile
|
|||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
def run(input_file)
|
def run(input_file, output_file)
|
||||||
grammar = Grammar.new
|
grammar = Grammar.new
|
||||||
unless grammar.load(input_file)
|
unless grammar.load(input_file)
|
||||||
return 2
|
return 2
|
||||||
|
@ -2,7 +2,7 @@ module Imbecile
|
|||||||
module CLI
|
module CLI
|
||||||
|
|
||||||
USAGE = <<EOF
|
USAGE = <<EOF
|
||||||
Usage: #{$0} [options] <input-file>
|
Usage: #{$0} [options] <input-file> <output-file>
|
||||||
Options:
|
Options:
|
||||||
--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
|
||||||
@ -11,7 +11,7 @@ EOF
|
|||||||
class << self
|
class << self
|
||||||
|
|
||||||
def run(args)
|
def run(args)
|
||||||
input_file = nil
|
extra_args = []
|
||||||
args.each do |arg|
|
args.each do |arg|
|
||||||
case arg
|
case arg
|
||||||
when "--version"
|
when "--version"
|
||||||
@ -24,23 +24,18 @@ EOF
|
|||||||
$stderr.puts "Error: unknown option #{arg}"
|
$stderr.puts "Error: unknown option #{arg}"
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
if input_file
|
extra_args << arg
|
||||||
$stderr.puts "Error: only one input file supported"
|
|
||||||
return 1
|
|
||||||
else
|
|
||||||
input_file = arg
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if input_file.nil?
|
if extra_args.size != 2
|
||||||
$stderr.puts "Error: must specify input file"
|
$stderr.puts "Error: specify input and output files"
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
unless File.readable?(input_file)
|
unless File.readable?(args[0])
|
||||||
$stderr.puts "Error: cannot read #{input_file}"
|
$stderr.puts "Error: cannot read #{args[0]}"
|
||||||
return 2
|
return 2
|
||||||
end
|
end
|
||||||
Imbecile.run(input_file)
|
Imbecile.run(*args)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user