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

chore: add version command #310

Merged
merged 1 commit into from
Feb 24, 2023
Merged
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
1 change: 0 additions & 1 deletion lib/packwerk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ module Packwerk
autoload :Reference
autoload :ReferenceOffense
autoload :Validator
autoload :Version

class Cli
extend ActiveSupport::Autoload
Expand Down
4 changes: 4 additions & 0 deletions lib/packwerk/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def execute_command(args)
output_result(parse_run(args).update_todo)
when "validate"
validate(args)
when "version"
@out.puts(Packwerk::VERSION)
true
when nil, "help"
usage
else
Expand Down Expand Up @@ -114,6 +117,7 @@ def usage
check - run all checks
update-todo - update package_todo.yml files
validate - verify integrity of packwerk and package configuration
version - output packwerk version
help - display help information about packwerk
USAGE
true
Expand Down
2 changes: 2 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

ENV["RAILS_ENV"] = "test"

require "pathname"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't needed for our setup, but I assume you ran tests without rake to get the error (via ruby -I). In that case, we can keep it 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an issue on my part, I ran with global rake and saw this issue, running with bundle exec rake resolved it.


$LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
ROOT = Pathname.new(__dir__).join("..").expand_path

Expand Down
10 changes: 10 additions & 0 deletions test/unit/packwerk/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ class CliTest < Minitest::Test
assert_match(/Subcommands:/, @err_out.string)
end

test "#execute_command with version subcommand returns the version" do
use_template(:blank)
string_io = StringIO.new
cli = ::Packwerk::Cli.new(out: string_io)

cli.execute_command(["version"])

assert_equal "#{Packwerk::VERSION}\n", string_io.string
end

test "#execute_command with an invalid subcommand" do
use_template(:blank)
@cli.execute_command(["beep boop"])
Expand Down