Sha256: 13ea7fa5e3c20de38a53aa830e65117e2e668afc245d8e3296ea1a3f7c321405

Contents?: true

Size: 1.32 KB

Versions: 19

Compression:

Stored size: 1.32 KB

Contents

require 'thor/actions'

require_relative '../util'

class Thor
  ##
  # Patch some Thor actions
  ##
  module Actions
    ##
    # Replace `run` with IO::popen to accept STDIN
    ##
    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 options[: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

    ##
    # Make `template` load from a sane path and render in the context of Config
    ##
    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
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
builderator-1.1.8 lib/builderator/patch/thor-actions.rb
builderator-1.1.7 lib/builderator/patch/thor-actions.rb
builderator-1.1.6 lib/builderator/patch/thor-actions.rb
builderator-1.1.5 lib/builderator/patch/thor-actions.rb
builderator-1.1.4 lib/builderator/patch/thor-actions.rb
builderator-1.1.3 lib/builderator/patch/thor-actions.rb
builderator-1.1.2 lib/builderator/patch/thor-actions.rb
builderator-1.1.1 lib/builderator/patch/thor-actions.rb
builderator-1.1.0 lib/builderator/patch/thor-actions.rb
builderator-1.0.4 lib/builderator/patch/thor-actions.rb
builderator-1.0.3 lib/builderator/patch/thor-actions.rb
builderator-1.0.2 lib/builderator/patch/thor-actions.rb
builderator-1.0.1 lib/builderator/patch/thor-actions.rb
builderator-1.0.0.pre.rc.12 lib/builderator/patch/thor-actions.rb
builderator-1.0.0.pre.rc.11 lib/builderator/patch/thor-actions.rb
builderator-1.0.0.pre.rc.10 lib/builderator/patch/thor-actions.rb
builderator-1.0.0.pre.rc.9 lib/builderator/patch/thor-actions.rb
builderator-1.0.0.pre.rc.8 lib/builderator/patch/thor-actions.rb
builderator-1.0.0.pre.rc.7 lib/builderator/patch/thor-actions.rb