lib/packwerk/cli.rb in packwerk-1.3.2 vs lib/packwerk/cli.rb in packwerk-1.4.0

- old
+ new

@@ -1,9 +1,12 @@ # typed: true # frozen_string_literal: true +require "optparse" + module Packwerk + # A command-line interface to Packwerk. class Cli extend T::Sig sig do params( @@ -95,11 +98,11 @@ success = configuration_file && inflections_file && root_package result = if success <<~EOS - 🎉 Packwerk is ready to be used. You can start defining packages and run `packwerk check`. + 🎉 Packwerk is ready to be used. You can start defining packages and run `bin/packwerk check`. For more information on how to use Packwerk, see: https://github.com/Shopify/packwerk/blob/main/USAGE.md EOS else <<~EOS @@ -121,12 +124,16 @@ @out.puts @out.puts(result.message) result.status end - def fetch_files_to_process(paths) - files = FilesForProcessing.fetch(paths: paths, configuration: @configuration) + def fetch_files_to_process(paths, ignore_nested_packages) + files = FilesForProcessing.fetch( + paths: paths, + ignore_nested_packages: ignore_nested_packages, + configuration: @configuration + ) abort("No files found or given. "\ "Specify files or check the include and exclude glob in the config file.") if files.empty? files end @@ -153,12 +160,27 @@ @out.puts("Validation failed ❗") @out.puts(result.error_value) end end - def parse_run(paths) + def parse_run(params) + paths = T.let([], T::Array[String]) + ignore_nested_packages = nil + + if params.any? { |p| p.include?("--packages") } + OptionParser.new do |parser| + parser.on("--packages=PACKAGESLIST", Array, "package names, comma separated") do |p| + paths = p + end + end.parse!(params) + ignore_nested_packages = true + else + paths = params + ignore_nested_packages = false + end + ParseRun.new( - files: fetch_files_to_process(paths), + files: fetch_files_to_process(paths, ignore_nested_packages), configuration: @configuration, progress_formatter: @progress_formatter, offenses_formatter: @offenses_formatter ) end