Sha256: 583bd4d964c807f602373a0b69a42987dad47f7b12b244f749478286d89dd52f

Contents?: true

Size: 875 Bytes

Versions: 2

Compression:

Stored size: 875 Bytes

Contents

# frozen_string_literal: true

module BackupRepos
  class Shell
    def initialize(opts = {})
      @debug = opts[:debug] || false
    end

    def run(command)
      log_command(command)
      execute_command(command)
    end

    private

    def debug?
      @debug || BackupRepos.config.debug
    end

    def execute_command(command)
      output = IO.popen(command, 'r', err: %i[child out]) do |io|
        output = io.read
        log_output(output)
        output
      end

      [success?(output), output]
    end

    def success?(output)
      return false if output =~ /remote error\:/
      return false if output =~ /fatal\:/

      true
    end

    def log_command(command)
      return unless debug?

      puts "EXECUTING: #{command}"
    end

    def log_output(output)
      return unless debug?

      puts 'OUTPUT:'
      puts output
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
backup_repos-0.5.0 lib/backup_repos/shell.rb
backup_repos-0.4.0 lib/backup_repos/shell.rb