def main():
    flags = get_flags()

    # route to the appropriate command
    if flags.cmd == 'stats':
        printer = LatencyPrinter(expected_calls=flags.count)
        read_values = False
    elif flags.cmd == 'dump':
        printer_cls = Printer if flags.unpaired else PairedPrinter
        format_opts = FormatOptions(
            flags.pretty,
            flags.color,
            flags.show_header or flags.show_all,
            flags.show_fields or flags.show_all,
            flags.json,
            )
        printer = printer_cls(format_opts)
        read_values = flags.show_values or flags.show_all
    else:
        print(flags.cmd % 'Unknown command: %s')
        sys.exit(1)

    # which protocol to use
    if flags.protocol == 'auto':
        protocol = None
    elif flags.protocol == 'binary':
        protocol = TBinaryProtocol
    elif flags.protocol == 'compact':
        protocol = TCompactProtocol
    elif flags.protocol == 'json':
        protocol = TJSONProtocol
    else:
        print('Unknown protocol: %s' % flags.protocol)
        print('Valid options for --protocol are: %s' % VALID_PROTOCOLS)
        sys.exit(1)

    # launch the thrift message sniffer
    options = MessageSnifferOptions(
        iface=flags.iface,
        port=flags.port,
        ip=flags.ip,
        pcap_file=flags.pcap_file,
        protocol=protocol,
        finagle_thrift=flags.finagle_thrift,
        read_values=read_values,
        max_queued=flags.max_queued,
        max_message_size=flags.max_message_size,
        debug=flags.debug
        )
    message_sniffer = MessageSniffer(options, printer)

    def sigusr_handler(*args):
        print('message sniffer status: %s' % message_sniffer.status(),
              file=sys.stderr)

    # wire up sigusr1 for debugging info
    signal.signal(signal.SIGUSR1, sigusr_handler)

    # loop forever
    try:
        while message_sniffer.isAlive():
            message_sniffer.join(1)
    except (KeyboardInterrupt, SystemExit):
        pass
    finally:
        # force a stop
        message_sniffer.stop(wait_for_stopped=True)
dataset/ETHPy150Open pinterest/thrift-tools/thrift_tools/tool.py/main/swapped operands of `%`