Method: Drydock#run!

Defined in:
lib/drydock.rb

#run!(argv = [], stdin = $stdin) ⇒ Object

Execute the given command. By default, Drydock automatically executes itself and provides handlers for known errors. You can override this functionality by calling Drydock.run! yourself. Drydock will only call run! once.



752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
# File 'lib/drydock.rb', line 752

def run!(argv=[], stdin=$stdin)
  return if has_run?
  @@has_run = true
  raise NoCommandsDefined.new if commands.empty?

  global_options, cmd_name, command_options, argv = process_arguments(argv)
  stdin = (defined? @@stdin_block) ? @@stdin_block.call(stdin, []) : stdin

  command_obj = get_command(cmd_name)
  command_obj.prepare(cmd_name, argv, stdin, global_options, command_options)

  # Execute before block
  @@before_block.call(command_obj) if defined? @@before_block

  # Execute the requested command. We'll capture STDERR or STDOUT if desired.
  @@captured = capture? ? capture_io(@@capture) { command_obj.call } : command_obj.call

  # Execute after block
  @@after_block.call(command_obj) if defined? @@after_block

rescue OptionParser::InvalidOption => ex
  raise Drydock::InvalidArgument.new(ex.args)
rescue OptionParser::MissingArgument => ex
  raise Drydock::MissingArgument.new(ex.args)
end