Skip to content

Commit

Permalink
Merge pull request #255 from Shopify/cleanup_cli
Browse files Browse the repository at this point in the history
Cleanup CLI
  • Loading branch information
gmcgibbon committed Nov 15, 2022
1 parent 56d6df5 commit 186201e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 20 deletions.
33 changes: 19 additions & 14 deletions lib/packwerk/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ def execute_command(args)
case subcommand
when "init"
init
when "generate_configs"
generate_configs
when "check"
output_result(parse_run(args).check)
when "detect-stale-violations"
Expand All @@ -61,19 +59,11 @@ def execute_command(args)
when "validate"
validate(args)
when nil, "help"
@err_out.puts(<<~USAGE)
Usage: #{$PROGRAM_NAME} <subcommand>
Subcommands:
init - set up packwerk
check - run all checks
update-deprecations - update deprecated references
validate - verify integrity of packwerk and package configuration
help - display help information about packwerk
USAGE
true
usage
else
@err_out.puts("'#{subcommand}' is not a packwerk command. See `packwerk help`.")
@err_out.puts(
"'#{subcommand}' is not a packwerk command. See `packwerk help`."
)
false
end
end
Expand Down Expand Up @@ -116,6 +106,21 @@ def generate_configs
success
end

sig { returns(T::Boolean) }
def usage
@err_out.puts(<<~USAGE)
Usage: #{$PROGRAM_NAME} <subcommand>
Subcommands:
init - set up packwerk
check - run all checks
update-deprecations - update deprecated_references.yml files
validate - verify integrity of packwerk and package configuration
help - display help information about packwerk
USAGE
true
end

sig { params(result: Result).returns(T::Boolean) }
def output_result(result)
@out.puts
Expand Down
5 changes: 5 additions & 0 deletions lib/packwerk/parse_run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def initialize(

sig { returns(Result) }
def detect_stale_violations
warn(<<~WARNING.squish)
DEPRECATION WARNING: `detect-stale-violation` is deprecated,
the output of `check` includes stale references.
WARNING

run_context = Packwerk::RunContext.from_configuration(@configuration)
offense_collection = find_offenses(run_context)

Expand Down
32 changes: 26 additions & 6 deletions test/unit/parse_run_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ class ParseRunTest < Minitest::Test
teardown_application_fixture
end

test "#detect_stale_violations is deprecated" do
use_template(:minimal)
RunContext.any_instance.stubs(:process_file).returns([])

parse_run = Packwerk::ParseRun.new(
relative_file_set: Set.new(["path/of/exile.rb"]),
configuration: Configuration.from_path
)

_, error_message = capture_io do
parse_run.detect_stale_violations
end

assert_equal(<<~MSG, error_message)
DEPRECATION WARNING: `detect-stale-violation` is deprecated, the output of `check` includes stale references.
MSG
end

test "#detect_stale_violations returns expected Result when stale violations present" do
use_template(:minimal)
OffenseCollection.any_instance.stubs(:stale_violations?).returns(true)
Expand All @@ -26,9 +44,11 @@ class ParseRunTest < Minitest::Test
relative_file_set: Set.new(["path/of/exile.rb"]),
configuration: Configuration.from_path
)
result = parse_run.detect_stale_violations
assert_equal "There were stale violations found, please run `packwerk update-deprecations`", result.message
refute result.status
capture_io do
result = parse_run.detect_stale_violations
assert_equal "There were stale violations found, please run `packwerk update-deprecations`", result.message
refute result.status
end
end

test "#update_deprecations returns success when there are no offenses" do
Expand Down Expand Up @@ -73,7 +93,7 @@ class ParseRunTest < Minitest::Test
refute result.status
end

test "#update_todo cleans up old package_todo files" do
test "#update_deprecations cleans up old deprecated_references files" do
use_template(:minimal)

FileUtils.mkdir_p("app/models")
Expand All @@ -85,7 +105,7 @@ def something
end
YML

File.write("package_todo.yml", <<~YML.strip)
File.write("deprecated_references.yml", <<~YML.strip)
---
"components/sales":
"::Order":
Expand All @@ -95,7 +115,7 @@ def something
- app/models/my_model.rb
YML

File.write("components/sales/package_todo.yml", <<~YML.strip)
File.write("components/sales/deprecated_references.yml", <<~YML.strip)
---
"components/destination":
"::SomeName":
Expand Down

0 comments on commit 186201e

Please sign in to comment.