Module: Thor::Actions
- Included in:
- Builderator::Tasks::Berkshelf, Builderator::Tasks::CLI, Builderator::Tasks::Cookbook, Builderator::Tasks::Packer, Builderator::Tasks::Vagrant, Builderator::Tasks::Vendor, Builderator::Tasks::Version
- Defined in:
- lib/builderator/patch/thor-actions.rb
Overview
Patch some Thor actions
Instance Method Summary collapse
-
#run_with_input(command, input, config = {}) ⇒ Object
Replace
runwith IO::popen to accept STDIN. -
#template(source, destination, config = {}) ⇒ Object
Make
templateload from a sane path and render in the context of Config.
Instance Method Details
#run_with_input(command, input, config = {}) ⇒ Object
Replace run with IO::popen to accept STDIN
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 40 |
# File 'lib/builderator/patch/thor-actions.rb', line 13 def run_with_input(command, input, config = {}) return unless behavior == :invoke destination = relative_to_original_destination_root(destination_root, false) desc = "#{command} from #{destination.inspect}" if config[:with] desc = "#{File.basename(config[:with].to_s)} #{desc}" command = "#{config[:with]} #{command}" end say_status :run, desc, config.fetch(:verbose, true) return if [:pretend] output = config.fetch(:stdout, STDOUT) IO.popen(command, 'r+') do |io| io.write(input) ## Stream output loop do break if io.eof? output.write(io.readpartial(4096)) output.flush end end end |
#template(source, destination, config = {}) ⇒ Object
Make template load from a sane path and render in the context of Config
45 46 47 48 49 50 |
# File 'lib/builderator/patch/thor-actions.rb', line 45 def template(source, destination, config = {}) content = ERB.new(Builderator::Util.source_path(source).binread, nil, '-', '@output_buffer').result(Builderator::Config.instance_eval('binding')) create_file Builderator::Util.relative_path(destination), content, config end |