Sha256: 4fc82eae1dc0b1f63744a3e1c61e2743635fc5bfc69b1591e9941cecdcf4b3ad

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

require 'awesome_print'

module Uffizzi
  module UI
    class Shell
      attr_accessor :output_format

      def initialize
        @shell = Thor::Shell::Basic.new
      end

      def say(message)
        @shell.say(message)
      end

      def ask(msg, *args)
        @shell.ask(msg, *args)
      end

      def print_in_columns(messages)
        @shell.print_in_columns(messages)
      end

      def print_table(table_data)
        @shell.print_table(table_data)
      end

      def last_message
        @shell.send(:stdout).string.strip
      end

      def pretty_say(collection, index = true)
        ap(collection, { index: index })
      end

      def disable_stdout
        $stdout = StringIO.new
      end

      def output(data)
        $stdout = IO.new(1, 'w')
        json_format? ? output_in_json(data) : output_in_github_format(data)
      end

      private

      def json_format?
        output_format == 'json'
      end

      def output_in_json(data)
        say(data.to_json)
      end

      def output_in_github_format(data)
        data.each_key do |key|
          say("::set-output name=#{key}::#{data[key]}")
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
uffizzi-cli-0.5.2 lib/uffizzi/shell.rb
uffizzi-cli-0.5.1 lib/uffizzi/shell.rb