lib/packwerk/cli.rb in packwerk-2.1.0 vs lib/packwerk/cli.rb in packwerk-2.1.1
- old
+ new
@@ -1,6 +1,6 @@
-# typed: true
+# typed: strict
# frozen_string_literal: true
require "optparse"
module Packwerk
@@ -28,13 +28,14 @@
)
@out = out
@err_out = err_out
@environment = environment
@style = style
- @configuration = configuration || Configuration.from_path
- @progress_formatter = Formatters::ProgressFormatter.new(@out, style: style)
- @offenses_formatter = offenses_formatter || Formatters::OffensesFormatter.new(style: @style)
+ @configuration = T.let(configuration || Configuration.from_path, Configuration)
+ @progress_formatter = T.let(Formatters::ProgressFormatter.new(@out, style: style), Formatters::ProgressFormatter)
+ @offenses_formatter = T.let(offenses_formatter || Formatters::OffensesFormatter.new(style: @style),
+ OffensesFormatter)
end
sig { params(args: T::Array[String]).returns(T.noreturn) }
def run(args)
success = execute_command(args)
@@ -76,16 +77,18 @@
end
end
private
+ sig { returns(T::Boolean) }
def init
@out.puts("📦 Initializing Packwerk...")
generate_configs
end
+ sig { returns(T::Boolean) }
def generate_configs
configuration_file = Packwerk::Generators::ConfigurationFile.generate(
root: @configuration.root_path,
out: @out
)
@@ -110,72 +113,78 @@
@out.puts(result)
success
end
+ sig { params(result: Result).returns(T::Boolean) }
def output_result(result)
@out.puts
@out.puts(result.message)
result.status
end
- def fetch_files_to_process(paths, ignore_nested_packages)
- files = FilesForProcessing.fetch(
- paths: paths,
+ sig { params(relative_file_paths: T::Array[String], ignore_nested_packages: T::Boolean).returns(T::Array[String]) }
+ def fetch_files_to_process(relative_file_paths, ignore_nested_packages)
+ absolute_files = FilesForProcessing.fetch(
+ relative_file_paths: relative_file_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
+ "Specify files or check the include and exclude glob in the config file.") if absolute_files.empty?
+ absolute_files
end
+ sig { params(_paths: T::Array[String]).returns(T::Boolean) }
def validate(_paths)
@progress_formatter.started_validation do
result = checker.check_all
list_validation_errors(result)
return result.ok?
end
end
+ sig { returns(ApplicationValidator) }
def checker
Packwerk::ApplicationValidator.new(
config_file_path: @configuration.config_path,
configuration: @configuration,
environment: @environment,
)
end
+ sig { params(result: ApplicationValidator::Result).void }
def list_validation_errors(result)
@out.puts
if result.ok?
@out.puts("Validation successful 🎉")
else
@out.puts("Validation failed ❗")
@out.puts(result.error_value)
end
end
+ sig { params(params: T.untyped).returns(ParseRun) }
def parse_run(params)
- paths = T.let([], T::Array[String])
+ relative_file_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
+ relative_file_paths = p
end
end.parse!(params)
ignore_nested_packages = true
else
- paths = params
+ relative_file_paths = params
ignore_nested_packages = false
end
ParseRun.new(
- files: fetch_files_to_process(paths, ignore_nested_packages),
+ absolute_files: fetch_files_to_process(relative_file_paths, ignore_nested_packages),
configuration: @configuration,
progress_formatter: @progress_formatter,
offenses_formatter: @offenses_formatter
)
end