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: true, aliases: 'f', desc: 'Directories and files to render' },
  'current-sha': { type: :string, banner: "SHA", desc: "Expose SHA `current_sha` in ERB bindings" },
}

Class Method Summary collapse

Class Method Details

.from_options(options) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/krane/cli/render_command.rb', line 13

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) }

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