Skip to content

Commit

Permalink
Fix to print version when version option is passed
Browse files Browse the repository at this point in the history
Before this commit

```
$ lrama --version
File should be specified
```

After

```
$ lrama --version
lrama 0.5.4
```
  • Loading branch information
yui-knk committed Aug 27, 2023
1 parent f029dd6 commit 0ebf2e9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
8 changes: 1 addition & 7 deletions lib/lrama/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class Command
def initialize(argv)
@argv = argv

@version = nil
@skeleton = "bison/yacc.c"
@header = false
@header_file = nil
Expand All @@ -23,11 +22,6 @@ def initialize(argv)
def run
parse_option

if @version
puts Lrama::VERSION
exit 0
end

Report::Duration.enable if @trace_opts[:time]

warning = Lrama::Warning.new
Expand Down Expand Up @@ -113,7 +107,7 @@ def parse_option
opt = OptionParser.new

# opt.on('-h') {|v| p v }
opt.on('-V', '--version') {|v| @version = true }
opt.on('-V', '--version') {|v| puts "lrama #{Lrama::VERSION}"; exit 0 }

# Tuning the Parser
opt.on('-S', '--skeleton=FILE') {|v| @skeleton = v }
Expand Down
11 changes: 11 additions & 0 deletions spec/lrama/command_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
require "open3"

RSpec.describe Lrama::Command do
describe "version option" do
it "print Lrama version and exit" do
result = Open3.popen3("ruby", exe_path("lrama"), "--version") do |stdin, stdout, stderr, wait_thr|
stdout.read
end
expect(result).to eq("lrama #{Lrama::VERSION}\n")
end
end

describe "#run" do
describe "a grammar file is specified" do
it "ends successfully" do
Expand Down
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@
def fixture_path(file_name)
File.expand_path("../fixtures/#{file_name}", __FILE__)
end

def exe_path(file_name)
File.expand_path("../../exe/#{file_name}", __FILE__)
end

0 comments on commit 0ebf2e9

Please sign in to comment.