Files
importer-issue-ops/lib/models/arguments.rb
T

37 lines
906 B
Ruby
Raw Normal View History

2022-01-07 19:45:53 +00:00
# frozen_string_literal: true
require_relative "../concerns/output_writer"
class Arguments
include OutputWriter
def initialize(provider, command, issue_content)
@args = argument_class(provider, command, issue_content)
2022-11-22 10:24:42 -05:00
@custom_transformers = custom_transformers(command)
2022-01-07 19:45:53 +00:00
end
def argument_class(provider, command, issue_content)
provider.module.const_get(command.classify).new(issue_content, command)
end
2022-11-22 10:24:42 -05:00
def custom_transformers(command)
command.options&.dig("custom-transformers")&.split(" ") || Dir.glob("transformers/**/*.rb")
end
2022-01-07 19:45:53 +00:00
def to_output
arguments = @args.to_a
return if arguments.blank?
2022-11-22 10:24:42 -05:00
arguments.concat(["--custom-transformers", *@custom_transformers]) if @custom_transformers.length.positive?
2022-01-07 19:45:53 +00:00
set_output(
"args",
arguments.map do |a|
next a unless a.include?(" ")
a.inspect
end.join(" ")
)
end
end