Method: Automate::Chain#run_command_list

Defined in:
lib/automate/chain.rb

#run_command_list(list, args) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/automate/chain.rb', line 62

def run_command_list(list, args)
  list.each_with_index do |cmd, index|
    desc, proc = cmd
    success "#{timestamp} // Running link ##{index+1} - #{desc}"

    error = false
    begin
      ret, out, chain_link_defer = ChainLink.invoke(proc, args)
      @defer_list += chain_link_defer
    rescue ChainLinkFailedError => e
      # TODO: Storing the defer_list in the ChainLinkFailedError is awful,
      # and shall be fixed when there's time to remove this entire exception-based
      # "communication" between chain and chain link.
      @defer_list += e.defer_list
      error = true
    end
    raise ChainFailedError.new(index + 1, desc) if ret == false || error == true

    # Pass the arguments from the last iteration, overwriting everything that
    # was passed from the current one.
    args.merge! out

    # Make it possible to run commands step by step
    if !ENV["AUTOMATE_STEP"].nil?
      puts "Press a key to continue..."
      $stdin.gets
      puts "\n"
    end
  end

  args
end