Sha256: 53e0bffdb414b837efdb27c37f8c1cba25baceba19fd60a35834f8e370e25425

Contents?: true

Size: 1.81 KB

Versions: 18

Compression:

Stored size: 1.81 KB

Contents

module PDK
  module CLI
    module Util
      class OptionNormalizer
        def self.comma_separated_list_to_array(list, _options = {})
          raise _('Error: expected comma separated list') unless OptionValidator.comma_separated_list?(list)
          list.split(',').compact
        end

        # Parse one or more format:target pairs into report format
        # specifications.
        #
        # Each specification is a Hash with two values:
        #   :method => The name of the method to call on the PDK::Report object
        #              to render the report.
        #   :target => The target to write the report to. This can be either an
        #              IO object that implements #write, or a String filename
        #              that will be opened for writing.
        #
        # If the target given is "stdout" or "stderr", this will convert those
        # strings into the appropriate IO object.
        #
        # @return [Array<Hash{Symbol=>Object}>] An array of one or more report
        #   format specifications
        def self.report_formats(formats)
          formats.map do |f|
            format, target = f.split(':', 2)

            begin
              OptionValidator.enum(format, PDK::Report.formats)
            rescue ArgumentError
              raise PDK::CLI::ExitWithError, _("'%{name}' is not a valid report format (%{valid})") % {
                name:  format,
                valid: PDK::Report.formats.join(', '),
              }
            end

            case target
            when 'stdout'
              target = $stdout
            when 'stderr'
              target = $stderr
            when nil
              target = PDK::Report.default_target
            end

            { method: "write_#{format}".to_sym, target: target }
          end
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
pdk-akerl-1.14.0.1 lib/pdk/cli/util/option_normalizer.rb
pdk-1.14.0 lib/pdk/cli/util/option_normalizer.rb
pdk-1.13.0 lib/pdk/cli/util/option_normalizer.rb
pdk-1.12.0 lib/pdk/cli/util/option_normalizer.rb
pdk-1.11.1 lib/pdk/cli/util/option_normalizer.rb
pdk-1.11.0 lib/pdk/cli/util/option_normalizer.rb
pdk-1.10.0 lib/pdk/cli/util/option_normalizer.rb
pdk-akerl-1.9.1.1 lib/pdk/cli/util/option_normalizer.rb
pdk-1.9.1 lib/pdk/cli/util/option_normalizer.rb
pdk-1.9.0 lib/pdk/cli/util/option_normalizer.rb
pdk-akerl-1.8.0.1 lib/pdk/cli/util/option_normalizer.rb
pdk-1.8.0 lib/pdk/cli/util/option_normalizer.rb
pdk-1.7.1 lib/pdk/cli/util/option_normalizer.rb
pdk-1.7.0 lib/pdk/cli/util/option_normalizer.rb
pdk-1.6.1 lib/pdk/cli/util/option_normalizer.rb
pdk-1.6.0 lib/pdk/cli/util/option_normalizer.rb
pdk-1.5.0 lib/pdk/cli/util/option_normalizer.rb
pdk-1.4.1 lib/pdk/cli/util/option_normalizer.rb