Sha256: ae29ae932335df11b9bcc22b7ae68b747427c7c13881aa4d938861e9103fda90

Contents?: true

Size: 1.13 KB

Versions: 42

Compression:

Stored size: 1.13 KB

Contents

module FWToolkit
  module Executable

    class ThorRunner
      def run(command, config={})
        Thor::Actions::run(command, config)
      end

      def report_error(command, command_output)
        command_output.gsub!(/e\[\d+m/, '') #Stripping colors
        say "An error has occured while running: \"#{command}\"", :red
        say 'Command output:'
        raise Thor::Error, "\n***\n#{command_output}***"
      end
    end

    class CliRunner
      def run(command, config={})
        `#{command}`
      end

      def report_error(command, command_output)
        command_output.gsub!(/e\[\d+m/, '')
        puts "An error has occured while running: \"#{command}\"", :red
        puts 'Command output:'
        raise "\n***\n#{command_output}***"
      end
 
    end

    def self.runner=(runner)
      @@runner = runner
    end

    def run(command, options = {})
      cmd_output = @@runner.run command, options
      @@runner.report_error(command, cmd_output) if options[:raise_errors] && !$?.success?
    end

    def run!(command, options = {})
      config.merge!({ :raise_errors => true })
      run command config
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
fwtoolkit-2.6.4 lib/fwtoolkit/executable/executable.rb
fwtoolkit-2.6.3 lib/fwtoolkit/executable/executable.rb
fwtoolkit-2.6.2 lib/fwtoolkit/executable/executable.rb
fwtoolkit-2.6.1 lib/fwtoolkit/executable/executable.rb
fwtoolkit-2.6.0 lib/fwtoolkit/executable/executable.rb
fwtoolkit-2.5.0 lib/fwtoolkit/executable/executable.rb
fwtoolkit-2.4.0 lib/fwtoolkit/executable/executable.rb
fwtoolkit-2.3.6 lib/fwtoolkit/executable/executable.rb
fwtoolkit-2.3.5 lib/fwtoolkit/executable/executable.rb
fwtoolkit-2.3.4 lib/fwtoolkit/executable/executable.rb
fwtoolkit-2.3.3 lib/fwtoolkit/executable/executable.rb
fwtoolkit-2.3.2 lib/fwtoolkit/executable/executable.rb
fwtoolkit-2.3.1 lib/fwtoolkit/executable/executable.rb
fwtoolkit-2.3.0 lib/fwtoolkit/executable/executable.rb
fwtoolkit-2.2.4 lib/fwtoolkit/executable/executable.rb
fwtoolkit-2.2.3 lib/fwtoolkit/executable/executable.rb
fwtoolkit-2.2.2 lib/fwtoolkit/executable/executable.rb
fwtoolkit-2.2.1 lib/fwtoolkit/executable/executable.rb
fwtoolkit-2.2.0 lib/fwtoolkit/executable/executable.rb
fwtoolkit-2.1.10 lib/fwtoolkit/executable/executable.rb