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::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



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sfn/command/print.rb', line 14

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

  json_content = format_json(parameter_scrub!(template_content(file)))

  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], json_content)
      nil
    end
  else
    ui.puts json_content
  end
end