Skip to content

Commit

Permalink
Merge pull request #310 from silasb/chore/add-version-command
Browse files Browse the repository at this point in the history
chore: add version command
  • Loading branch information
gmcgibbon committed Feb 24, 2023
2 parents 6e57928 + 722d7a5 commit 868fa97
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
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"

$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

0 comments on commit 868fa97

Please sign in to comment.