Sha256: 8a16c540fe7ded52507d7f501872e77d23aef9292de0b1ba16251c71a09d2a95

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

module GitReflow
  module Sandbox
    extend self

    COLOR_FOR_LABEL = {
      notice:         :yellow,
      error:          :red,
      deliver_halted: :red,
      review_halted:  :red,
      success:        :green,
      plain:          :white
    }

    def run(command, options = {})
      options = { loud: true, blocking: true }.merge(options)

      GitReflow.logger.debug "Running... #{command}"

      if options[:with_system] == true
        system(command)
      else
        output = %x{#{command}}

        if options[:blocking] == true && !$?.success?
          abort "\"#{command}\" failed to run."
        else
          puts output if options[:loud] == true
          output
        end
      end
    end

    def run_command_with_label(command, options = {})
      label_color = options.delete(:color) || :green
      puts command.colorize(label_color)
      run(command, options)
    end

    def say(message, label_type = :plain)
      if COLOR_FOR_LABEL[label_type]
        label = (label_type.to_s == "plain") ? "" : "[#{ label_type.to_s.gsub('_', ' ').colorize(COLOR_FOR_LABEL[label_type]) }] "
        puts "#{label}#{message}"
      else
        puts message
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
git_reflow-0.8.10 lib/git_reflow/sandbox.rb
git_reflow-0.8.9 lib/git_reflow/sandbox.rb
git_reflow-0.8.8 lib/git_reflow/sandbox.rb