Sha256: f7476faf7919e581439f94c3ccfc963908f72c6951acc6f957497ff13b0a2feb

Contents?: true

Size: 1.35 KB

Versions: 4

Compression:

Stored size: 1.35 KB

Contents

#!/usr/bin/env ruby
# WANT_JSON

# Reinstate Bundler ENV vars if they have been moved
load ENV['QB_REBUNDLE_PATH'] if ENV['QB_REBUNDLE_PATH']

require 'nrser'
require 'qb'
require 'qb/ansible/module'
require 'cmds'

class Stream < QB::Ansible::Module
  def main
    template = @args['template'] || @args['cmd']
    
    if template.nil?
      raise ArgumentError,
            "Must supply `template` or `cmd` argument."
    end
    
    if @args['creates'] && File.exists?( @args['creates'] )
      debug "File #{ @args['creates'] } exists, skipping"
      return nil
    end
    
    opts = {}
    
    [:args, :kwds, :input, :assert, :env, :chdir].each { |key|
      opts[key] = @args[key.to_s] if @args.key?(key.to_s)
    }
    
    [:format, :env_mode].each { |key|
      opts[key] = @args[key.to_s].to_sym if @args.key?(key.to_s)
    }
    
    cmd = Cmds.new(template, **opts)
    
    if @args['log']
      info binding.erb <<-END
        
        STREAMING
        ========================================================================
        
        Template:
        
            <%= template %>
        
        Options:
        
            <%= opts.pretty_inspect %>
        
        Prepared command:
        
          <%= cmd.prepare %>
        
      END
    end
    
    QB::Util::Bundler.unbundle! { cmd.stream! }
    
    changed!
  end
end

Stream.run!

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
qb-0.4.5 library/stream
qb-0.4.4 library/stream
qb-0.4.3 library/stream
qb-0.4.2 library/stream