Class: Exctl::Commands

Inherits:
Object show all
Includes:
Enumerable
Defined in:
lib/exctl/commands.rb

Instance Method Summary collapse

Methods included from Enumerable

#amap, #amap!, #average, #mean_ad, #median, #median_ad, #median_mad, #median_madr, #medianr, #mid, #q20, #q80, #robust_ad, #robust_ad2, #robust_avg, #robust_avgm, #sample_variance, #standard_deviation, #sum, #summarize_runs

Constructor Details

#initialize(proj_root) ⇒ Commands

Returns a new instance of Commands.



18
19
20
21
22
23
24
# File 'lib/exctl/commands.rb', line 18

def initialize(proj_root)
  @root = proj_root
  @cmd_manifests = Path[@root]['**/**/.commands']
  @namespace = []
  #@bin_files = `find '#{@root}' -executable -type f -print0`.split("\x00")
  #pp @bin_files
end

Instance Method Details

#commandsObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/exctl/commands.rb', line 28

def commands
  return @commands unless @commands.nil?

  # 1. Commands in manifests
  # 2. Default commands (unless overridden already)
  # 3. Commands found in 'scripts' etc. (unless overridden)

  @commands = []
  @cmd_manifests.each do |cf|
    cmd_path = cf.short(Path[@root]).to_s.split('/')[0..-2]
    cmd_path.shift if ['bin','scripts'].include?(cmd_path[0])
    @namespace = cmd_path.dup
    eval(File.read(cf), binding, cf.to_s)
    @namespace = []
  end
  @commands
end

#each(&block) ⇒ Object



26
# File 'lib/exctl/commands.rb', line 26

def each(&block) commands.each(&block) end

#family(name, opts = {}, &block) ⇒ Object

—— Interface ——



47
48
49
50
51
# File 'lib/exctl/commands.rb', line 47

def family(name, opts={}, &block)
  @namespace << name
  yield
  @namespace.pop
end

#task(name, opts = {}, &block) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/exctl/commands.rb', line 53

def task(name, opts={}, &block)
  cmd = Cmd.new(@namespace, name, opts)
  init_res = yield cmd
  if init_res
    @commands << cmd
  end
end