Class: PDK::CLI::Util::OptionNormalizer
- Inherits:
-
Object
- Object
- PDK::CLI::Util::OptionNormalizer
- Defined in:
- lib/pdk/cli/util/option_normalizer.rb
Class Method Summary collapse
- .comma_separated_list_to_array(list, _options = {}) ⇒ Object
- .parameter_specification(value) ⇒ Object
-
.report_formats(formats) ⇒ Array<Hash{Symbol=>Object}>
Parse one or more format:target pairs into report format specifications.
Class Method Details
.comma_separated_list_to_array(list, _options = {}) ⇒ Object
5 6 7 8 |
# File 'lib/pdk/cli/util/option_normalizer.rb', line 5 def self.comma_separated_list_to_array(list, = {}) raise _('Error: expected comma separated list') unless OptionValidator.comma_separated_list?(list) list.split(',').compact end |
.parameter_specification(value) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/pdk/cli/util/option_normalizer.rb', line 51 def self.parameter_specification(value) param_name, param_type = value.split(':', 2) param_type = 'String' if param_type.nil? unless PDK::CLI::Util::OptionValidator.valid_param_name?(param_name) raise PDK::CLI::FatalError, _("'%{name}' is not a valid parameter name") % { name: param_name, } end unless PDK::CLI::Util::OptionValidator.valid_data_type?(param_type) raise PDK::CLI::FatalError, _("'%{type}' is not a valid data type") % { type: param_type, } end { name: param_name, type: param_type } end |
.report_formats(formats) ⇒ Array<Hash{Symbol=>Object}>
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.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/pdk/cli/util/option_normalizer.rb', line 25 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::FatalError, _("'%{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 |