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.13.7 lib/jazzy/executable.rb
jazzy-0.13.6 lib/jazzy/executable.rb
jazzy-0.13.5 lib/jazzy/executable.rb
jazzy-0.13.4 lib/jazzy/executable.rb
jazzy-0.13.3 lib/jazzy/executable.rb
jazzy-0.13.2 lib/jazzy/executable.rb
jazzy-0.13.1 lib/jazzy/executable.rb
jazzy-0.13.0 lib/jazzy/executable.rb
jazzy-0.12.0 lib/jazzy/executable.rb
jazzy-0.11.2 lib/jazzy/executable.rb
jazzy-0.11.1 lib/jazzy/executable.rb
jazzy-0.11.0 lib/jazzy/executable.rb
jazzy-0.10.0 lib/jazzy/executable.rb
jazzy-0.9.6 lib/jazzy/executable.rb
jazzy-0.9.5 lib/jazzy/executable.rb
jazzy-0.9.4 lib/jazzy/executable.rb
jazzy-0.9.3 lib/jazzy/executable.rb
jazzy-0.9.2 lib/jazzy/executable.rb
jazzy-0.9.1 lib/jazzy/executable.rb
jazzy-0.9.0 lib/jazzy/executable.rb