Sha256: 9b5d1afd6228b595bc35434899b2972119ec9fe07bc2c8d8ee8f263cbcdca66b

Contents?: true

Size: 980 Bytes

Versions: 22

Compression:

Stored size: 980 Bytes

Contents

# rubocop:disable Metrics/BlockLength
module Shoryuken
  module CLI
    class Base < Thor
      no_commands do
        def print_table(entries)
          column_sizes = print_columns_size(entries)

          entries.map do |entry|
            puts entry.map.with_index { |e, i| print_format_column(e, column_sizes[i]) }.join
          end
        end

        def print_columns_size(entries)
          column_sizes = Hash.new(0)

          entries.each do |entry|
            entry.each_with_index do |e, i|
              e = e.to_s
              column_sizes[i] = e.size if column_sizes[i] < e.size
            end
          end

          column_sizes
        end

        def print_format_column(column, size)
          size_with_padding = size + 4
          column = column.to_s.ljust(size_with_padding)
          column
        end

        def fail_task(msg, quit = true)
          say "[FAIL] #{msg}", :red
          exit(1) if quit
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
shoryuken-3.2.3 bin/cli/base.rb
shoryuken-3.2.2 bin/cli/base.rb
shoryuken-3.2.1 bin/cli/base.rb
shoryuken-3.2.0 bin/cli/base.rb
shoryuken-3.1.12 bin/cli/base.rb
shoryuken-3.1.11 bin/cli/base.rb
shoryuken-3.1.10 bin/cli/base.rb
shoryuken-3.1.9 bin/cli/base.rb
shoryuken-3.1.8 bin/cli/base.rb
shoryuken-3.1.7 bin/cli/base.rb
shoryuken-3.1.6 bin/cli/base.rb
shoryuken-3.1.5 bin/cli/base.rb
shoryuken-3.1.4 bin/cli/base.rb
shoryuken-3.1.3 bin/cli/base.rb
shoryuken-3.1.2 bin/cli/base.rb
shoryuken-3.1.1 bin/cli/base.rb
shoryuken-3.1.0 bin/cli/base.rb
shoryuken-3.0.11 bin/cli/base.rb
shoryuken-3.0.10 bin/cli/base.rb
shoryuken-3.0.9 bin/cli/base.rb