# File lib/drydock.rb, line 612
612:   def command(*cmds, &b)
613:     cmd = cmds.shift # Should we accept aliases here?
614:     
615:     if cmd.is_a? Hash
616:       klass = cmd.values.first
617:       names = cmd.keys.first
618:       if names.is_a? Array
619:         cmd, cmds = names.shift, [names].flatten.compact
620:       else
621:         cmd = names
622:       end
623:       raise "#{klass} is not a subclass of Drydock::Command" unless klass.ancestors.member?(Drydock::Command)
624:       c = klass.new(cmd, &b)          # A custom class was specified
625:     else
626:       c = Drydock::Command.new(cmd, &b)
627:     end
628:     
629:     @@command_descriptions[@@command_index] ||= ""
630:     @@command_actions[@@command_index] ||= []
631:     @@command_argv_names[@@command_index] ||= []
632:     
633:     c.desc = @@command_descriptions[@@command_index]
634:     c.actions = @@command_actions[@@command_index]
635:     c.argv.fields = @@command_argv_names[@@command_index]
636:     
637:     # Default Usage Banner. 
638:     # Without this, there's no help displayed for the command. 
639:     option_parser = get_option_parser(@@command_index)
640:     if option_parser.is_a?(OptionParser) && option_parser.banner !~ /^USAGE/
641:       usage "#{c.executable} #{c.cmd}"
642:     end
643:     
644:     @@commands[c.cmd] = c
645:     @@command_index_map[c.cmd] = @@command_index
646:     @@command_index += 1 # This will point to the next command
647:     
648:     # Created aliases to the command using any additional command names 
649:     # i.e. command :something, :sumpin => Something
650:     cmds.each { |aliaz| command_alias(cmd, aliaz); } unless cmds.empty?
651:     
652:     c  # Return the Command object
653:   end