Sha256: a87590c67d1ce669d98e3d05339c690b2815bcb8e09220cb4e4fc7b4f3b8149c

Contents?: true

Size: 977 Bytes

Versions: 1

Compression:

Stored size: 977 Bytes

Contents

require 'open-uri'

module Wordless
  module CLIHelper
    def error(message)
      say message, :red
    end

    def success(message)
      say message, :green
    end

    def warning(message)
      say message, :yellow
    end

    def download(url, destination)
      begin
        f = open(destination, "wb")
        f.write(open(url).read) ? true : false
      rescue
        false
      ensure
        f.close
      end
    end

    def unzip(file, destination)
      run "unzip #{file} -d #{destination}", :verbose => false, :capture => true
    end

    def git_installed?
      # http://stackoverflow.com/questions/4597490/platform-independent-way-of-detecting-if-git-is-installed
      void = RbConfig::CONFIG['host_os'] =~ /msdos|mswin|djgpp|mingw/ ? 'NUL' : '/dev/null'
      system "git --version >>#{void} 2>&1"
    end

    def add_git_repo(repo, destination)
      run "git clone #{repo} #{destination}", :verbose => false, :capture => true
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wordless-0.3.0 lib/wordless/cli_helper.rb