lib/krane/cli/render_command.rb in kubernetes-deploy-0.31.1 vs lib/krane/cli/render_command.rb in kubernetes-deploy-1.0.0.pre.1

- old
+ new

@@ -2,24 +2,32 @@ module Krane module CLI class RenderCommand 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" }, + "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, desc: "Read resources from stdin", default: false }, + "current-sha" => { type: :string, banner: "SHA", desc: "Expose SHA `current_sha` in ERB bindings" }, } 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| + # never mutate options directly + filenames = options[:filenames].dup + filenames << "-" if options[:stdin] + if filenames.empty? + raise Thor::RequiredArgumentMissingError, 'At least one of --filenames or --stdin must be set' + end + + ::Krane::OptionsHelper.with_processed_template_paths(filenames) do |paths| runner = ::Krane::RenderTask.new( current_sha: options['current-sha'], template_paths: paths, bindings: bindings_parser.parse, )