code: def main(argv=sys.argv[1:], loop=None):
      
      args = docopt(__doc__, argv=argv,
                    version=pkg_resources.require('rflink')[0].version)
  
      level = logging.ERROR
      if args['-v']:
          level = logging.INFO
      if args['-v'] == 2:
          level = logging.DEBUG
      logging.basicConfig(level=level)
  
      if not loop:
          loop = asyncio.get_event_loop()
  
      if args['--ignore']:
          ignore = args['--ignore'].split(',')
      else:
          ignore = []
  
      command = next((c for c in ALL_COMMANDS if args[c] is True), None)
  
      if command:
          protocol = PROTOCOLS['command']
      else:
          protocol = PROTOCOLS[args['-m']]
  
      conn = create_rflink_connection(
          protocol=protocol,
          host=args['--host'],
          port=args['--port'],
          baud=args['--baud'],
          loop=loop,
          ignore=ignore,
      )
  
      transport, protocol = loop.run_until_complete(conn)
  
      try:
          if command:
              for _ in range(int(args['--repeat'])):
                  loop.run_until_complete(
                      protocol.send_command_ack(
                          args['<id>'], command))
          else:
              loop.run_forever()
      except KeyboardInterrupt:
          # cleanup connection
          transport.close()
          loop.run_forever()
      finally:
          loop.close()
docs: Parse argument and setup main program loop.