diff --git a/lib/bootsnap/cli.rb b/lib/bootsnap/cli.rb index 8172edd..d0cf876 100644 --- a/lib/bootsnap/cli.rb +++ b/lib/bootsnap/cli.rb @@ -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" diff --git a/test/cli_test.rb b/test/cli_test.rb index 0e78f8a..52e98d4 100644 --- a/test/cli_test.rb +++ b/test/cli_test.rb @@ -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