Class: LogicalConstruct::Target::CommandLine

Inherits:
Rake::Application
  • Object
show all
Defined in:
lib/logical-construct/target/command-line.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CommandLine



6
7
8
9
10
11
12
# File 'lib/logical-construct/target/command-line.rb', line 6

def initialize(argv)
  @argv = argv
  @manifest_path = nil
  @flight_deck_tasks = []
  @plan_options = []
  super()
end

Instance Method Details

#add_options(options) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/logical-construct/target/command-line.rb', line 75

def add_options(options)
  return options + [
    [ "--control-task", "-C TASK",
      "Alter the tasks run by flight-deck itself (rather than task run by the plans)",
      lambda{|value| @flight_deck_tasks << value} ],
      [ "--manifest-file", "-M MANIFEST",
        "Supply a starting server manifest (gotten from e.g. AWS userdata)",
        lambda{|value| @manifest_path = value } ] ]
end

#collect_plan_option(name, value) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/logical-construct/target/command-line.rb', line 46

def collect_plan_option(name, value)
  if value == true or value.nil? or value.empty?
    @plan_options << name
  else
    @plan_options << "#{name}=#{value}"
  end
end

#collect_tasksObject



26
27
28
29
30
31
32
33
# File 'lib/logical-construct/target/command-line.rb', line 26

def collect_tasks
  super
  @implement_tasks = @top_level_tasks
  @top_level_tasks = @flight_deck_tasks
  if @top_level_tasks.empty?
    @top_level_tasks = ['implement']
  end
end

#forward_to_plans(options) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/logical-construct/target/command-line.rb', line 54

def forward_to_plans(options)
  patterns = %w{--prereqs}
  new_options = []
  patterns.each do |switch|
    option = options.find{|list| /^#{switch}/ =~ list[0]}
    next if option.nil?
    new_options << [option[0].sub(/^--/, "--flight-deck-"), option[-2], option[-1]]
  end

  new_options + mutate_options(patterns, options) do |switch, previous_handler, value|
    collect_plan_option(switch, value)
  end
end

#goObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/logical-construct/target/command-line.rb', line 14

def go
  init(File::basename($0))
  Rake.application = self
  FlightDeck.new do |control|
    control.namespace_name = nil
    control.top_level_tasks = @implement_tasks
    control.manifest_path = @manifest_path
    control.plan_options = @plan_options
  end
  top_level
end

#mirror_to_plans(options) ⇒ Object



68
69
70
71
72
73
# File 'lib/logical-construct/target/command-line.rb', line 68

def mirror_to_plans(options)
  mutate_options(%w{--trace}, options) do |switch, previous_handler, value|
    previous_handler[value]
    collect_plan_option(switch, value)
  end
end

#mutate_options(patterns, options, &block) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/logical-construct/target/command-line.rb', line 35

def mutate_options(patterns, options, &block)
  patterns.each do |switch|
    option = options.find{|list| /^#{switch}/ =~ list[0]}
    next if option.nil?
    previous_handler = option.pop
    option.push lambda{|value| yield(switch, previous_handler, value)}
    lambda{|value| @plan_options << "#{switch}=#{value}"}
  end
  options
end

#standard_rake_optionsObject



85
86
87
# File 'lib/logical-construct/target/command-line.rb', line 85

def standard_rake_options
  sort_options( add_options( forward_to_plans( mirror_to_plans( super))))
end