#!/usr/bin/env python
#
# gameclock - a simple chess/game clock

import getopt
import sys
import os
# crude hack to support running from the source directory
d, s = os.path.split(os.path.dirname(os.path.abspath(__file__)))
if s == 'scripts':
    sys.path.insert(0, d)
import gameclock

verbose = 0 # 0 means not verbose, higher numbers show more information, see ui.debug for more info

def usage():
    """gameclock v%s %s
Usage:
  %s [ -h | -v ... | -f ]

  -h --help: display this help
  -v --verbose: display progress information to stdout. repeating the flag will show more information
  -f --fullscreen: start in fullscreen mode

See the manpage for more information."""
    print usage.__doc__ % (gameclock.__version__, gameclock.__copyright__, sys.argv[0])

if __name__ == "__main__":
    try:
        opts, args = getopt.getopt(sys.argv[1:], "hvf:p:", ["help", "verbose", "fullscreen"])
    except getopt.GetoptError, err:
        # print help information and exit:
        usage()
        print "\nError: " + str(err) # will print something like "option -a not recognized"
        sys.exit(2)

    from gameclock.gtkui import GameclockUI
    clock = GameclockUI()
    for o, a in opts:
        if o in ("-v", "--verbose"):
            clock.verbose += 1
        elif o in ("-h", "--help"):
            usage()
            sys.exit()
        elif o in ("-f", "--fullscreen"):
            clock.fullscreen = True
        else:
            assert False, "unhandled option"
    clock.debug('running with verbosity: %d' % clock.verbose)
    clock.main()
