public
Description: My set of personal Thor scripts.
Homepage:
Clone URL: git://github.com/crnixon/thor_tasks.git
Clinton R. Nixon (author)
Sat Sep 19 08:31:34 -0700 2009
thor_tasks / shell_utils.rb
100644 73 lines (59 sloc) 1.312 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# based off code at http://github.com/botanicus/thor-utils/blob/master/lib/thor-utils/shell.rb#L1
 
require "fileutils"
require "term/ansicolor"
 
String.send(:include, Term::ANSIColor)
 
module Thor
  module ShellUtils
    include FileUtils
    
    protected
    
    def banner(text)
      print "=" * 10
      print " #{text} "
      puts "=" * 10
    end
 
    def success(*messages)
      messages.each do |message|
        puts message.green.bold
      end
    end
 
    def notice(*messages)
      messages.each do |message|
        puts message.green
      end
    end
 
    def error(*messages)
      if messages.empty?
        messages.push("Error")
      end
      messages.each do |message|
        STDERR.puts message.red.bold
      end
    end
 
    def error!(*args)
      error(*args)
      exit 1
    end
 
    def warn(*messages)
      messages.each do |message|
        STDERR.puts message.yellow.bold
      end
    end
 
    def sh(command)
      puts "sh> ".blue + command.to_s
      if returned = %x(#{command})
        puts returned
      else
        error returned
      end
    end
 
    def rake(*tasks)
      sh "rake #{tasks.join(" ")}"
    end
 
    def thor(*options)
      sh "thor #{options.join(" ")}"
    end
 
    def ruby(*options)
      sh "ruby #{options.join(" ")}"
    end
  end
end