Class: Krane::CLI::RenderCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/krane/cli/render_command.rb

Constant Summary collapse

OPTIONS =
{
  "bindings" => { type: :array, banner: "foo=bar abc=def", desc: 'Bindings for erb' },
  "filenames" => { type: :array, banner: 'config/deploy/production config/deploy/my-extra-resource.yml',
                   required: false, default: [], aliases: 'f', desc: 'Directories and files to render' },
  "stdin" => { type: :boolean, default: false,
               desc: "[DEPRECATED] Read resources from stdin" },
  "current-sha" => { type: :string, banner: "SHA", desc: "Expose SHA `current_sha` in ERB bindings",
                     lazy_default: '' },
}

Class Method Summary collapse

Class Method Details

.from_options(options) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/krane/cli/render_command.rb', line 16

def self.from_options(options)
  require 'krane/render_task'
  require 'krane/bindings_parser'
  require 'krane/options_helper'

  bindings_parser = ::Krane::BindingsParser.new
  options[:bindings]&.each { |b| bindings_parser.add(b) }

  filenames = options[:filenames].dup
  filenames << "-" if options[:stdin]
  if filenames.empty?
    raise(Thor::RequiredArgumentMissingError, '--filenames must be set and not empty')
  end

  ::Krane::OptionsHelper.with_processed_template_paths(filenames, render_erb: true) do |paths|
    renderer = ::Krane::RenderTask.new(
      current_sha: options['current-sha'],
      filenames: paths,
      bindings: bindings_parser.parse,
    )
    renderer.run!(stream: STDOUT)
  end
end