module UberDoc::Util

Public Class Methods

execute_command(command, verbose) click to toggle source

Exectues the given command and optionally dumps the command and its output

# File lib/uberdoc/utils.rb, line 16
def self.execute_command(command, verbose)

    if verbose
        puts ">>>>>>>>>>>>>>>>>>>>>>>>>".green
        puts "Command '#{command}'".green
    end

    res = ""
    Open3.popen3(command) do |stdin, stdout, stderr, thread|

        {:out => stdout, :err => stderr}.each do |key, stream|
            Thread.new do
                until (line = stream.gets).nil? do
                    if key == :out
                        res += line
                    end

                    if verbose
                        case key
                        when :out
                            puts line
                        when :err
                            puts line.red                                    
                        end
                    end
                end
            end
        end

        thread.join
    end
    
    if verbose
        puts "<<<<<<<<<<<<<<<<<<<<<<<<<".green
    end

    return res
end
template_file_path(file) click to toggle source
# File lib/uberdoc/utils.rb, line 9
def self.template_file_path(file)
    File.absolute_path("#{File.dirname(File.dirname(File.dirname(__FILE__)))}/templates/#{file}") 
end