# File lib/rhc/commands.rb, line 221
    def self.to_commander(instance=Commander::Runner.instance)
      global_options.each do |args, block|
        args = args.dup
        opts = (args.pop if Hash === args.last) || {}
        option = instance.global_option(*args, &block).last
        option.merge!(opts)
      end

      commands.each_pair do |name, opts|
        name = Array(name)
        names = [name.reverse.join('-'), name.join(' ')] if name.length > 1
        name = name.join('-')

        instance.command name do |c|
          c.description = opts[:description]
          c.summary = opts[:summary]
          c.syntax = opts[:syntax]
          c.default_action = opts[:default]

          c.info = opts

          (options_metadata = Array(opts[:options])).each do |o|
            option_data = [o[:switches], o[:type], o[:description], o.slice(:optional, :default, :hide, :covered_by)].compact.flatten(1)
            c.option *option_data
            o[:arg] = Commander::Runner.switch_to_sym(Array(o[:switches]).last)
          end

          (args_metadata = Array(opts[:args])).each do |meta|
            switches = meta[:switches]
            unless switches.blank?
              switches = switches.dup
              switches << meta[:description]
              switches << meta.slice(:optional, :default, :hide, :covered_by, :allow_nil)
              c.option *switches
            end
          end

          Array(opts[:aliases]).each do |a|
            action = Array(a[:action])
            [' ', '-'].each do |s|
              cmd = action.join(s)
              instance.alias_command cmd, name
            end
          end

          if names
            names.each{ |alt| instance.alias_command alt, name }
          else
            c.root = true
          end

          c.when_called do |args, options|
            deprecated!

            config = c.instance_variable_get(:@config)

            cmd = opts[:class].new
            cmd.options = options
            cmd.config = config

            args = fill_arguments(cmd, options, args_metadata, options_metadata, args)
            needs_configuration!(cmd, options, config)

            return execute(cmd, :help, args) unless opts[:method]
            execute(cmd, opts[:method], args)
          end
        end
      end
      self
    end