Skip to content

Commit

Permalink
Add --version flag
Browse files Browse the repository at this point in the history
Fix: #483
  • Loading branch information
dorianmariecom authored and byroot committed Apr 4, 2024
1 parent 87edda3 commit f627992
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/bootsnap/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ def exclude_pattern(pattern)

def parser
@parser ||= OptionParser.new do |opts|
opts.version = Bootsnap::VERSION
opts.program_name = "bootsnap"

opts.banner = "Usage: bootsnap COMMAND [ARGS]"
opts.separator ""
opts.separator "GLOBAL OPTIONS"
Expand Down
18 changes: 18 additions & 0 deletions test/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ def test_no_yaml
assert_equal 0, CLI.new(["precompile", "-j", "0", "--no-yaml", path]).run
end

if Process.respond_to?(:fork)
def test_version_flag
read, write = IO.pipe
# optparse --version immediately call exit so we test in a subprocess
pid = fork do
STDOUT.reopen(write)
read.close
exit(CLI.new(["--version"]).run)
end
write.close

_, status = Process.waitpid2(pid)
assert_predicate status, :success?

assert_includes read.read, Bootsnap::VERSION
end
end

private

def skip_unless_iseq
Expand Down

0 comments on commit f627992

Please sign in to comment.