#! /usr/bin/env python3

import logging
import argparse
import functools

def sorter(a, b):
  """
  Compare method for two strings.
    Argument a: String 1
    Argument b: String 2
    Returns: 
      -1 if `a` == 'master'
      1 if `b` == 'master'
      0 if a == b but neither != 'master'
      -1 if a < b but neither != 'master'
      1 if a > b but neither != 'master'
  """
  if a == 'master':
    return -1
  elif b == 'master':
    return 1
  else:
    return (a>b) - (a<b) # stolen from https://codegolf.stackexchange.com/questions/49778/how-can-i-use-cmpa-b-with-python3

parser = argparse.ArgumentParser(description='Play with Python 3 cmp-like operator for builtin sorted() function')
parser.add_argument('keys', metavar='key', nargs='+', help='One or more keys to sort')
parser.add_argument('-v', '--verbose', action='count', help='Enable debugging')
args = parser.parse_args()

logging.basicConfig(format='%(asctime)s %(levelname)s %(pathname)s:%(lineno)d %(msg)s')
log = logging.getLogger()
log.setLevel(logging.WARNING - (args.verbose or 0)*10)

print('\n'.join(sorted(args.keys, key=functools.cmp_to_key(sorter))))
