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

Support CSV format for get_info and allow including any violation types #110

Merged
merged 8 commits into from
Oct 13, 2023
Prev Previous commit
Next Next commit
Allow specifying what types of violations to output on get_info
  • Loading branch information
oboxodo committed Oct 12, 2023
commit 7c24364ee7b68cc422b16081ccefd99955d25648
8 changes: 7 additions & 1 deletion lib/packs/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,17 @@ def update

desc 'get_info [ packs/my_pack packs/my_other_pack ]', 'Get info about size and violations for packs'
option :format, type: :string, default: 'detail', aliases: :f, banner: 'Specify the output format (detail, csv)'
option :types, type: :string, default: 'privacy,dependency', aliases: :t, banner: 'List of validation types to include (privacy,dependency,architecture)'
sig { params(pack_names: String).void }
def get_info(*pack_names)
selected_types = options[:types].to_s.downcase.split(',')
invalid_types = selected_types - POSIBLE_TYPES
raise StandardError, "Invalid type(s): #{invalid_types.join(', ')}. Possible types are: #{POSIBLE_TYPES.join(', ')}" unless invalid_types.empty?

Private.get_info(
packs: parse_pack_names(pack_names),
format: options[:format].to_sym
format: options[:format].to_sym,
types: selected_types.map(&:to_sym)
)
exit_successfully
end
Expand Down
8 changes: 4 additions & 4 deletions lib/packs/private.rb
Original file line number Diff line number Diff line change
Expand Up @@ -482,19 +482,19 @@ def self.packwerk_package_to_pack(package)
sig do
params(
packs: T::Array[Packs::Pack],
format: Symbol
format: Symbol,
types: T::Array[Symbol]
).void
end
def self.get_info(packs: Packs.all, format: :detail)
def self.get_info(packs: Packs.all, format: :detail, types: %i[privacy dependency architecture])
require 'csv' if format == :csv

violation_types = %i[privacy dependency architecture]
violations = {
inbound: {},
outbound: {}
}
directions = violations.keys
dir_x_types = directions.product(violation_types)
dir_x_types = directions.product(types)

ParsePackwerk.all.each do |p|
p.violations.each do |violation|
Expand Down
11 changes: 10 additions & 1 deletion lib/packs/private/interactive_cli/use_cases/get_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,18 @@ def perform!(prompt)

format = prompt.select('What output format do you want?', %w[Detail CSV])

types = prompt.multi_select(
'What violation types do you want stats for?',
%w[Privacy Dependency Architecture]
)

puts "You've selected #{selected_packs.count} packs. Wow! Here's all the info."

Private.get_info(packs: selected_packs, format: format.downcase.to_sym)
Private.get_info(
packs: selected_packs,
format: format.downcase.to_sym,
types: types.map(&:downcase).map(&:to_sym)
)
end
end
end
Expand Down