def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-k', '--key', default='name')
    parser.add_argument('-s', '--case-sensitive', default=False, action='store_true')
    parser.add_argument('-r', '--reverse', default=False, action='store_true')
    args = parser.parse_args()

    if sys.stdin.isatty():
        parser.error('no input, pipe another btc command output into this command')
    l = sys.stdin.read()

    if len(l.strip()) == 0:
        exit(1)

    try:
        l = decoder.decode(l)
    except __HOLE__:
        error('unexpected input: %s' % l)

    def key(x):
        key = x[args.key]
        if ((isinstance(x[args.key], str)
             or isinstance(x[args.key], unicode))
            and not args.case_sensitive):
            return key.lower()
        return key

    l = sorted(l, key=key)

    if args.reverse:
        l = list(reversed(l))

    print(encoder.encode([ordered_dict(d) for d in l]))
dataset/ETHPy150Open bittorrent/btc/btc/btc_sort.py/main