Module: GitReflow::Sandbox

Extended by:
Sandbox
Included in:
GitReflow, GitHelpers, GitServer::GitHub, Sandbox, Workflow::ClassMethods
Defined in:
lib/git_reflow/sandbox.rb

Defined Under Namespace

Classes: CommandError

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#run(command, options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/git_reflow/sandbox.rb', line 23

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

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

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

    if !$?.success?
      raise CommandError.new(output, "\"#{command}\" failed to run.") if options[:raise] == true
      abort "\"#{command}\" failed to run." if options[:blocking] == true
    end

    puts output if options[:loud] == true
    output
  end
end

#run_command_with_label(command, options = {}) ⇒ Object



43
44
45
46
47
# File 'lib/git_reflow/sandbox.rb', line 43

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

#say(message, label_type = :plain) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/git_reflow/sandbox.rb', line 49

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