Sha256: 86ca31d5ac9e1a6947a0a98c9fa1c8a183d81686b9a78a2253a32611449886b9

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

require "colored"
require "active_support/core_ext/module/delegation"
require "highline"
require "hirb-colors"
require "hirb"

module Cp8Cli
  class Command
    class << self
      delegate :table, :open_url, :say, :success, :ask, :title, :error, :run, :read, to: :client
      attr_accessor :client
    end

    self.client = new

    def table(items)
      puts Hirb::Helpers::AutoTable.render(items, unicode: true)
    end

    def open_url(url)
      return title(url) if ENV['BROWSER'] == 'echo'
      `open \"#{url}\"`
    end

    def say(*args)
      highline.say(*args)
    end

    def success(message)
      highline.say(message.green.bold)
    end

    def ask(message, type = nil)
      highline.ask(message, type)
    end

    def title(message)
      highline.say(message.bold)
    end

    def error(message)
      say(message.red.bold)
      exit(false)
    end

    def run(command)
      title(command)
      system(command) || error("Error running: #{command}")
    end

    def read(command)
      `#{command}`.strip.presence
    end

    private

      def highline
        @_highline ||= HighLine.new
      end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cp8_cli-4.1.2 lib/cp8_cli/command.rb
cp8_cli-4.1.1 lib/cp8_cli/command.rb
cp8_cli-4.1.0 lib/cp8_cli/command.rb
cp8_cli-4.0.1 lib/cp8_cli/command.rb