Sha256: b2cef4e12e606b29382c8484af38772f0004496c6eca2b38ef41b55536480686

Contents?: true

Size: 1.07 KB

Versions: 38

Compression:

Stored size: 1.07 KB

Contents

module Jazzy
  module Executable
    class IO < Array
      def initialize(io = nil)
        @io = io
      end

      def <<(value)
        super
      ensure
        @io << value.to_s if @io
      end

      def to_s
        join("\n")
      end
    end

    class << self
      def execute_command(executable, args, raise_on_failure, env: {})
        require 'shellwords'
        bin = `which #{executable.to_s.shellescape}`.strip
        raise "Unable to locate the executable `#{executable}`" if bin.empty?

        require 'open4'

        stdout = IO.new
        stderr = IO.new($stderr)

        options = { stdout: stdout, stderr: stderr, status: true }
        status  = Open4.spawn(env, bin, *args, options)
        unless status.success?
          full_command = "#{bin.shellescape} #{args.map(&:shellescape)}"
          output = stdout.to_s << stderr.to_s
          if raise_on_failure
            raise "#{full_command}\n\n#{output}"
          else
            warn("[!] Failed: #{full_command}")
          end
        end
        [stdout.to_s, status]
      end
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
jazzy-0.8.4 lib/jazzy/executable.rb
jazzy-0.8.3 lib/jazzy/executable.rb
jazzy-0.8.2 lib/jazzy/executable.rb
jazzy-0.8.1 lib/jazzy/executable.rb
jazzy-0.8.0 lib/jazzy/executable.rb
jazzy-0.7.5 lib/jazzy/executable.rb
jazzy-0.7.4 lib/jazzy/executable.rb
jazzy-0.7.3 lib/jazzy/executable.rb
jazzy-0.7.2 lib/jazzy/executable.rb
jazzy-0.7.1 lib/jazzy/executable.rb
jazzy-0.7.0 lib/jazzy/executable.rb
jazzy-0.6.3 lib/jazzy/executable.rb
jazzy-0.6.2 lib/jazzy/executable.rb
jazzy-0.6.1 lib/jazzy/executable.rb
jazzy-0.6.0 lib/jazzy/executable.rb
jazzy-0.5.0 lib/jazzy/executable.rb
jazzy-0.4.1 lib/jazzy/executable.rb
jazzy-0.4.0 lib/jazzy/executable.rb