Sha256: 761464fe3d7323470084b01f9431e619145c118ef1c20cb99ca70004cea723ea

Contents?: true

Size: 1.51 KB

Versions: 4

Compression:

Stored size: 1.51 KB

Contents

require 'optparse'
require 'yaml'
require 'highline/import'

require 'hanzo/base'
require 'hanzo/cli'
require 'hanzo/heroku'
require 'hanzo/version'

require 'hanzo/fetchers/environment'

module Hanzo
  def self.run(command, fetch_output = false)
    print(command, :green)
    output = true

    _run do
      output = if fetch_output
                 `#{command}`
               else
                 system(command)
               end
    end

    output
  end

  def self._run(&blk)
    if defined?(Bundler)
      ::Bundler.with_clean_env(&blk)
    else
      blk.call
    end
  end

  def self.print(text = '', *colors)
    colors = colors.map { |c| HighLine.const_get(c.to_s.upcase) }
    text = text.join("\n       ") if text.is_a?(Array)
    HighLine.say HighLine.color("       #{text}", *colors)
  end

  def self.unindent_print(text = '', *colors)
    colors = colors.map { |c| HighLine.const_get(c.to_s.upcase) }
    HighLine.say HighLine.color(text, *colors)
  end

  def self.title(text)
    HighLine.say HighLine.color("-----> #{text}", :blue)
  end

  def self.agree(question)
    HighLine.agree "       #{question} "
  end

  def self.ask(question, &blk)
    HighLine.ask "-----> #{question} ", &blk
  end

  def self.config
    return YAML.load_file('.hanzo.yml') if File.exist?('.hanzo.yml')

    Hanzo.print 'Cannot locate .hanzo.yml'
    Hanzo.print 'For more information, please read https://github.com/mirego/hanzo'

    exit
  end
end

class String
  def unindent
    gsub(/^#{scan(/^\s*/).min_by(&:length)}/, '')
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hanzo-1.1.0 lib/hanzo.rb
hanzo-1.0.2 lib/hanzo.rb
hanzo-1.0.1 lib/hanzo.rb
hanzo-1.0.0 lib/hanzo.rb