Top Level Namespace

Defined Under Namespace

Modules: Escape, Rye

Constant Summary collapse

@@colors =
false || ENV['COLORS'] || ENV['TERM'].match(/.*color.*/)
@@command =
{}

Instance Method Summary collapse

Instance Method Details

#colors(state) ⇒ Object



18
# File 'lib/rye/dsl.rb', line 18

def colors   state; @@colors  = state; end

#command_group(name, &block) ⇒ Object



41
42
43
# File 'lib/rye/dsl.rb', line 41

def command_group(name, &block)
  @@command[name] = Proc.new &block
end

#debug(msg, *opts) ⇒ Object



97
98
99
# File 'lib/rye/dsl.rb', line 97

def debug msg, *opts
  STDOUT.puts strwrap(msg, *opts)
end

#err(msg, *opts) ⇒ Object



93
94
95
# File 'lib/rye/dsl.rb', line 93

def err msg, *opts
  STDOUT.puts strwrap(msg, *opts)
end

#exit_status_check(cmd, opts = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rye/dsl.rb', line 45

def exit_status_check(cmd, opts={})
  enable_quiet_mode
  @pass = opts[:pass_str] || cmd.to_s + ' Passed Status Check'
  @fail = opts[:fail_str] || cmd.to_s + ' Failed Status Check'
  def results(obj, out)
    if obj.exit_status == 0
      info out, :altstring => @pass
    else
      err out, :altstring => @fail
    end
  end
  out = execute cmd
  if out[0].class == Rye::Rap
    out.each do |rap|
      results(rap, out)
    end
  elsif out.exit_status == 0
    results(out, out)
  end
  disable_quiet_mode
end

#host(hostname, *args, &block) ⇒ Object



20
21
22
23
# File 'lib/rye/dsl.rb', line 20

def host(hostname, *args, &block)
  @hosts[hostname] = Rye::Box.new(hostname, *args) unless @hosts.key? hostname
  Docile.dsl_eval(Rye::Set.new.add_box(@hosts[hostname]), &block) if block_given?
end

#hostset(setname, *args, &block) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rye/dsl.rb', line 25

def hostset(setname, *args, &block)
  @hostsets[setname] = Rye::Set.new(setname) unless @hostsets.key? setname
  args.each do |host|
    @hosts[host] = Rye::Box.new(host) unless @hosts.key? host
    @hostsets[setname].add_box @hosts[host] unless @hostsets[setname].boxes.include? @hosts[host]
  end
  if @parallel
    @hostsets[setname].parallel = true
    Docile.dsl_eval(@hostsets[setname], &block) if block_given?
  else
    @hostsets[setname].boxes.each do |host|
      Docile.dsl_eval(Rye::Set.new.add_box(host), &block) if block_given?
    end
  end
end

#info(msg, *opts) ⇒ Object



89
90
91
# File 'lib/rye/dsl.rb', line 89

def info msg, *opts
  STDOUT.puts strwrap(msg, *opts)
end

#parallel(state) ⇒ Object



17
# File 'lib/rye/dsl.rb', line 17

def parallel state; @parallel = state; end

#results(obj, out) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/rye/dsl.rb', line 49

def results(obj, out)
  if obj.exit_status == 0
    info out, :altstring => @pass
  else
    err out, :altstring => @fail
  end
end

#strwrap(msg, opts = {}) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/rye/dsl.rb', line 67

def strwrap(msg, opts={})
  out = ''
  unless @@colors
    msg.each do |str|
      unless opts.key? :altstring
        out += str.to_s.gsub!(/^/, "[#{str.obj.hostname}] ") + "\n"
      else
        out += "[#{str.obj.hostname}] #{opts[:altstring]}\n"
      end
    end
  else
    msg.each do |str|
      unless opts.key? :altstring
        out += str.to_s.gsub!(/^(.*)$/, str.obj.hostname)
      else
        out += "#{str.obj.hostname} " + opts[:altstring]
      end
    end
  end
  out
end