Class: FastlaneCore::PrintTable
- Inherits:
-
Object
- Object
- FastlaneCore::PrintTable
- Defined in:
- fastlane_core/lib/fastlane_core/print_table.rb
Class Method Summary collapse
- .collect_rows(options: nil, hide_keys: [], mask_keys: [], prefix: '', mask: '********') ⇒ Object
- .colorize_array(array, colors) ⇒ Object
-
.print_values(config: nil, title: nil, hide_keys: [], mask_keys: [], transform: :newline) ⇒ Object
This method prints out all the user inputs in a nice table.
- .should_transform? ⇒ Boolean
- .transform_output(rows, transform: :newline) ⇒ Object
- .transform_row(column, transform, max_value_length) ⇒ Object
Class Method Details
.collect_rows(options: nil, hide_keys: [], mask_keys: [], prefix: '', mask: '********') ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'fastlane_core/lib/fastlane_core/print_table.rb', line 111 def collect_rows(options: nil, hide_keys: [], mask_keys: [], prefix: '', mask: '********') rows = [] .each do |key, value| prefixed_key = "#{prefix}#{key}" next if value.nil? next if value.to_s == "" next if hide_keys.include?(prefixed_key) value = mask if mask_keys.include?(prefixed_key) if value.respond_to?(:key) rows.concat(self.collect_rows(options: value, hide_keys: hide_keys, mask_keys: mask_keys, prefix: "#{prefix}#{key}.", mask: mask)) else rows << [prefixed_key, value] end end rows end |
.colorize_array(array, colors) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'fastlane_core/lib/fastlane_core/print_table.rb', line 46 def colorize_array(array, colors) value = "" array.each do |l| colored_line = l colored_line = "#{colors.first}#{l}#{colors.last}" if colors.length > 0 value << colored_line value << "\n" end return value end |
.print_values(config: nil, title: nil, hide_keys: [], mask_keys: [], transform: :newline) ⇒ Object
This method prints out all the user inputs in a nice table. Useful to summarize the run You can pass an array to ‘hide_keys` if you don’t want certain elements to show up (symbols or strings) You can pass an array to ‘mask_keys` if you want to mask certain elements (symbols or strings)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'fastlane_core/lib/fastlane_core/print_table.rb', line 10 def print_values(config: nil, title: nil, hide_keys: [], mask_keys: [], transform: :newline) require 'terminal-table' = {} unless config.nil? if config.kind_of?(FastlaneCore::Configuration) # find sensitive options and mask them by default config..each do |config_item| if config_item.sensitive mask_keys << config_item.key.to_s end end = config.values(ask: false) else = config end end rows = self.collect_rows(options: , hide_keys: hide_keys.map(&:to_s), mask_keys: mask_keys.map(&:to_s), prefix: '') params = {} if transform params[:rows] = transform_output(rows, transform: transform) else params[:rows] = rows end params[:title] = title.green if title puts("") puts(Terminal::Table.new(params)) puts("") return params end |
.should_transform? ⇒ Boolean
57 58 59 60 61 62 |
# File 'fastlane_core/lib/fastlane_core/print_table.rb', line 57 def should_transform? if FastlaneCore::Helper.ci? || FastlaneCore::Helper.test? return false end return !FastlaneCore::Env.truthy?("FL_SKIP_TABLE_TRANSFORM") end |
.transform_output(rows, transform: :newline) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'fastlane_core/lib/fastlane_core/print_table.rb', line 87 def transform_output(rows, transform: :newline) return rows unless should_transform? require 'fastlane_core/string_filters' require 'tty-screen' number_of_cols = TTY::Screen.width col_count = rows.map(&:length).first || 1 # -4 per column - as tt adds "| " and " |" terminal_table_padding = 4 max_length = number_of_cols - (col_count * terminal_table_padding) max_value_length = (max_length / col_count) - 1 return_array = rows.map do |row| row.map do |column| transform_row(column, transform, max_value_length) end end return return_array end |
.transform_row(column, transform, max_value_length) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'fastlane_core/lib/fastlane_core/print_table.rb', line 64 def transform_row(column, transform, max_value_length) return column if column.nil? # we want to keep the nil and not convert it to a string return column if transform.nil? value = column.to_s.dup if transform == :truncate_middle return value.middle_truncate(max_value_length) elsif transform == :newline # remove all fixed newlines as it may mess up the output value.gsub!("\n", " ") if value.kind_of?(String) if value.length >= max_value_length colors = value.scan(/\e\[.*?m/) colors.each { |color| value.gsub!(color, '') } lines = value.wordwrap(max_value_length) return colorize_array(lines, colors) end elsif transform UI.user_error!("Unknown transform value '#{transform}'") end return value end |