From 889a15ad70d47afdb2ec8c46cbf967efd70eb759 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 5 Sep 2014 17:01:52 -0400 Subject: [PATCH] Reformatting rake libs --- rake/lib/git.rb | 11 +++++++---- rake/lib/output.rb | 12 ++++++------ rake/lib/sh.rb | 18 +++++++++--------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/rake/lib/git.rb b/rake/lib/git.rb index 0cab96bc..13415bd2 100644 --- a/rake/lib/git.rb +++ b/rake/lib/git.rb @@ -1,9 +1,12 @@ include Rake::DSL -def git(url,dest) - sh "git clone #{url} #{dest}" unless Dir.exists?(dest) +def git(url, dest) + unless Dir.exists?("#{dest}/.git") + rm_rf dest if Dir.exists?(dest) + sh "git clone '#{url}' '#{dest}'" + end end -def github(repo,dest) - git "https://github.com/#{repo}.git", dest +def github(repo, dest, protocol = "https") + git "#{protocol}://github.com/#{repo}.git", dest end diff --git a/rake/lib/output.rb b/rake/lib/output.rb index 9f407f6f..4717220f 100644 --- a/rake/lib/output.rb +++ b/rake/lib/output.rb @@ -1,9 +1,9 @@ -def echo(msg) - # print green text - puts "\e[32m=> #{msg}\e[0m" +def echo(msg, level = 1) + # print green text + puts "\e[32m#{"="*level}> #{msg}\e[0m" end -def echoerr(msg) - # print red text - puts "\e[31m=> #{msg}\e[0m" +def error(msg) + # print red text + puts "\e[31m=> #{msg}\e[0m" end diff --git a/rake/lib/sh.rb b/rake/lib/sh.rb index b7a02c9e..9e8b8b7a 100644 --- a/rake/lib/sh.rb +++ b/rake/lib/sh.rb @@ -4,16 +4,16 @@ require_relative 'output' # when it encounters a problem. I'll leave it up to the # programmer to expect problems and terminate when necessary. def sh_safe(cmd) - begin - return sh(cmd) - rescue - echoerr $! - return false - end + begin + return sh(cmd) + rescue + error $! + return false + end end def do_link(src, dest) - if not (File.exist?(path_to_file) || File.symlink?(path_to_file)) - sh_safe "ln -sf #{src} #{dest}" - end + if not (File.exist?(path_to_file) || File.symlink?(path_to_file)) + sh_safe "ln -sf #{src} #{dest}" + end end