diff --git a/lib/lrama/option_parser.rb b/lib/lrama/option_parser.rb index 35725fc6..86e48291 100644 --- a/lib/lrama/option_parser.rb +++ b/lib/lrama/option_parser.rb @@ -60,7 +60,8 @@ def parse_by_option_parser(argv) o.on('-t', 'reserved, do nothing') { } o.separator '' o.separator 'Output:' - o.on('-h', '--header=[FILE]', 'also produce a header file named FILE') {|v| @options.header = true; @options.header_file = v } + o.on('-H', '--header=[FILE]', 'also produce a header file named FILE') {|v| @options.header = true; @options.header_file = v } + o.on('-h=[FILE]', 'also produce a header file named FILE (deprecated)') {|v| @options.header = true; @options.header_file = v } o.on('-d', 'also produce a header file') { @options.header = true } o.on('-r', '--report=THINGS', Array, 'also produce details on the automaton') {|v| @report = v } o.on('--report-file=FILE', 'also produce details on the automaton output to a file named FILE') {|v| @options.report_file = v } diff --git a/spec/lrama/option_parser_spec.rb b/spec/lrama/option_parser_spec.rb index 8e34cb28..71972c41 100644 --- a/spec/lrama/option_parser_spec.rb +++ b/spec/lrama/option_parser_spec.rb @@ -48,7 +48,8 @@ -t reserved, do nothing Output: - -h, --header=[FILE] also produce a header file named FILE + -H, --header=[FILE] also produce a header file named FILE + -h=[FILE] also produce a header file named FILE (deprecated) -d also produce a header file -r, --report=THINGS also produce details on the automaton --report-file=FILE also produce details on the automaton output to a file named FILE @@ -137,6 +138,15 @@ describe "@header_file" do context "header file name is not passed" do context "outfile option is passed" do + it "@header_file is set based on outfile" do + option_parser = Lrama::OptionParser.new + option_parser.send(:parse, ["-H", "-o", "parse.c", "-", "test.y"]) + options = option_parser.instance_variable_get(:@options) + expect(options.header_file).to eq "./parse.h" + end + end + + context "deprecated outfile option is passed" do it "@header_file is set based on outfile" do option_parser = Lrama::OptionParser.new option_parser.send(:parse, ["-h", "-o", "parse.c", "-", "test.y"]) @@ -148,7 +158,7 @@ context "outfile option is not passed" do it "@header_file is set based on outfile default value" do option_parser = Lrama::OptionParser.new - option_parser.send(:parse, ["-h", "-", "test.y"]) + option_parser.send(:parse, ["-H", "-", "test.y"]) options = option_parser.instance_variable_get(:@options) expect(options.header_file).to eq "./y.tab.h" end @@ -158,7 +168,7 @@ context "header file name is passed" do it "@header_file is same with passed value" do option_parser = Lrama::OptionParser.new - option_parser.send(:parse, ["-hparse.h", "-", "test.y"]) + option_parser.send(:parse, ["-Hparse.h", "-", "test.y"]) options = option_parser.instance_variable_get(:@options) expect(options.header_file).to eq "parse.h" end