Method: Sfn::Command::Graph#execute!

Defined in:
lib/sfn/command/graph.rb

#execute!Object

Generate graph



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
# File 'lib/sfn/command/graph.rb', line 21

def execute!
  config[:print_only] = true
  validate_graph_style!
  file = load_template_file
  provider = Bogo::Utility.camel(file.provider).to_sym
  if Provider.constants.include?(provider)
    graph_const = Provider.const_get(provider)
    ui.debug "Loading provider graph implementation - #{graph_const}"
    extend graph_const
    @outputs = Smash.new
    ui.info "Template resource graph generation - Style: #{ui.color(config[:graph_style], :bold)}"
    if config[:file]
      ui.puts "  -> path: #{config[:file]}"
    end
    template_dump = file.compile.sparkle_dump!.to_smash
    run_action "Pre-processing template for graphing" do
      output_discovery(template_dump, @outputs, nil, nil)
      ui.debug "Output remapping results from pre-processing:"
      @outputs.each_pair do |o_key, o_value|
        ui.debug "#{o_key} -> #{o_value}"
      end
      nil
    end
    graph = nil
    run_action "Generating resource graph" do
      graph = generate_graph(template_dump)
      nil
    end
    run_action "Writing graph result" do
      FileUtils.mkdir_p(File.dirname(config[:output_file]))
      if config[:output_type] == "dot"
        File.open("#{config[:output_file]}.dot", "w") do |o_file|
          o_file.puts graph.to_s
        end
      else
        graph.save config[:output_file], config[:output_type]
      end
      nil
    end
  else
    valid_providers = Provider.constants.sort.map { |provider|
      Bogo::Utility.snake(provider)
    }.join("`, `")
    ui.error "Graphing for provider `#{file.provider}` not currently supported."
    ui.error "Currently supported providers: `#{valid_providers}`."
  end
end