Sha256: de194e2274dd3a6f016d15e18597c1831f4ec0ce00c19de0a202a18f1d3a0add

Contents?: true

Size: 1 KB

Versions: 12

Compression:

Stored size: 1 KB

Contents

require 'open3'
require 'papa/helper/output'

module Papa
  module Command
    class Base
      attr_accessor :command, :stdout, :stderr, :exit_status, :silent

      def initialize(command, options = {})
        @command = command
        @silent = options.has_key?(:silent) ? options[:silent] : false
      end

      def run
        return if command.nil?
        Helper::Output.stdout "Running #{command.bold}..." unless silent
        @stdout, @stderr, status = Open3.capture3(command)
        @exit_status = status.exitstatus
        self
      end

      def failure_message
        message = "Error while running #{command.bold}"
        Helper::Output.error message
        Helper::Output.error stderr
        message
      end

      def cleanup
        # Override me
      end

      def success?
        !failed?
      end

      def failed?
        exit_status != 0
      end

      private

      def current_branch
        @current_branch ||= `git symbolic-ref --short HEAD`.chomp
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
papa-1.2.0 lib/papa/command/base.rb
papa-1.1.0 lib/papa/command/base.rb
papa-1.0.0 lib/papa/command/base.rb
papa-0.7.2 lib/papa/command/base.rb
papa-0.7.1 lib/papa/command/base.rb
papa-0.7.0 lib/papa/command/base.rb
papa-0.6.2 lib/papa/command/base.rb
papa-0.6.1 lib/papa/command/base.rb
papa-0.6.0 lib/papa/command/base.rb
papa-0.5.0 lib/papa/command/base.rb
papa-0.4.1 lib/papa/command/base.rb
papa-0.4.0 lib/papa/command/base.rb