# File lib/cft/commands.rb, line 108
            def execute(argv)
                gopts = self.opts
                name = "help"
                rest = []
                begin
                    rest = gopts.order(argv) do |arg|
                        name = arg
                        gopts.terminate
                    end
                rescue OptionParser::InvalidOption => detail
                    $stderr.puts detail
                    $stderr.puts gopts
                    exit(1)
                end
                found_cmds = Base::find(name)
                if found_cmds.empty?
                    $stderr.puts "Unknown mode #{name}" unless name == "help"
                    $stderr.puts gopts
                    exit(1)
                elsif found_cmds.size > 1
                    names = found_cmds.map { |c| c.name }.join(", ")
                    $stderr.puts "Ambiguous mode #{name}: matches #{names}" unless name == "help"
                    $stderr.puts gopts
                    exit(1)
                end
                cmd = found_cmds[0]
                
                opts = cmd.opts
                
                begin
                    rest = opts.order(rest)
                rescue OptionParser::InvalidOption => detail
                    $stderr.puts detail
                    $stderr.puts opts
                    exit(1)
                end
                
                if cmd.respond_to?(:create_session)
                    session = cmd.create_session(rest, @global_opts)
                    return 1 if session.nil?
                    return cmd.execute(session, rest)
                else
                    return cmd.execute(rest)
                end
            end