Class: Sfn::Command::Print

Inherits:
Sfn::Command
  • Object
show all
Includes:
Sfn::CommandModule::Base, Sfn::CommandModule::Stack, Sfn::CommandModule::Template
Defined in:
lib/sfn/command/print.rb

Overview

Print command

Constant Summary

Constants included from Sfn::CommandModule::Template

Sfn::CommandModule::Template::DEFAULT_PROVIDER_NAME, Sfn::CommandModule::Template::MAX_PARAMETER_ATTEMPTS, Sfn::CommandModule::Template::TEMPLATE_IGNORE_DIRECTORIES

Constants inherited from Sfn::Command

CONFIG_BASE_NAME, VALID_CONFIG_EXTENSIONS

Instance Method Summary collapse

Methods included from Sfn::CommandModule::Stack

included

Methods included from Sfn::CommandModule::Template

included

Methods included from Sfn::CommandModule::Base

included

Methods inherited from Sfn::Command

#config, #initialize

Methods included from Sfn::CommandModule::Callbacks

#api_action!, #callbacks_for, #run_callbacks_for

Constructor Details

This class inherits a constructor from Sfn::Command

Instance Method Details

#execute!Object

Print the requested template



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

def execute!
  config[:print_only] = true
  file = load_template_file

  output_content = parameter_scrub!(template_content(file))
  if config[:yaml]
    require "yaml"
    output_content = YAML.dump(output_content)
  else
    output_content = format_json(output_content)
  end

  if config[:write_to_file]
    unless File.directory?(File.dirname(config[:write_to_file]))
      run_action "Creating parent directory" do
        FileUtils.mkdir_p(File.dirname(config[:write_to_file]))
        nil
      end
    end
    run_action "Writing template to file - #{config[:write_to_file]}" do
      File.write(config[:write_to_file], output_content)
      nil
    end
  else
    ui.puts output_content
  end
end