Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --version flag and version subcommand #483

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions lib/bootsnap/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,35 @@ def match?(string)

attr_reader :cache_dir, :argv

attr_accessor :compile_gemfile, :exclude, :verbose, :iseq, :yaml, :json, :jobs
attr_accessor(
:compile_gemfile,
:exclude,
:verbose,
:iseq,
:yaml,
:json,
:jobs,
:version
)

def initialize(argv)
@argv = argv
self.cache_dir = ENV.fetch("BOOTSNAP_CACHE_DIR", "tmp/cache")
self.compile_gemfile = false
self.exclude = nil
self.verbose = false
self.version = false
self.jobs = Etc.nprocessors
self.iseq = true
self.yaml = true
self.json = true
end

def version_command
puts Bootsnap::VERSION
0
end

def precompile_command(*sources)
require "bootsnap/compile_cache"

Expand Down Expand Up @@ -113,7 +128,7 @@ def list_files(path, pattern)
def run
parser.parse!(argv)
command = argv.shift
method = "#{command}_command"
method = version ? "version_command" : "#{command}_command"
if respond_to?(method)
public_send(method, *argv)
else
Expand Down Expand Up @@ -227,6 +242,13 @@ def parser
opts.separator "GLOBAL OPTIONS"
opts.separator ""

help = <<~HELP
Prints the version of bootsnap
HELP
opts.on("--version", help.strip) do
self.version = true
end

help = <<~HELP
Path to the bootsnap cache directory. Defaults to tmp/cache
HELP
Expand All @@ -252,6 +274,7 @@ def parser
opts.separator "COMMANDS"
opts.separator ""
opts.separator " precompile [DIRECTORIES...]: Precompile all .rb files in the passed directories"
opts.separator " version: Prints the version of bootsnap"

help = <<~HELP
Precompile the gems in Gemfile
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

def test_version
out, err = capture_io do
assert_equal 0, CLI.new(["version"]).run
end

assert_equal Bootsnap::VERSION + "\n", out
assert_equal "", err
end

def test_version_flag
out, err = capture_io do
assert_equal 0, CLI.new(["--version"]).run
end

assert_equal Bootsnap::VERSION + "\n", out
assert_equal "", err
end

private

def skip_unless_iseq
Expand Down
Loading