summaryrefslogtreecommitdiff
path: root/quick_lineup.py
blob: 3f4d00095d58445fa467d6e327fd2a7768573b2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import argparse
import sys
from ql.console import Console


class DefaultArgumentInput(argparse.Action):
    def __init__(self, *args, **kwargs):
        super(DefaultArgumentInput, self).__init__(*args, **kwargs)

    def __call__(self, parser, namespace, values, option_string=None):
        if values is None:
            values = input('Please enter value for %s: ' % self.metavar)
            try:
                values = self.type(values)
            except ValueError:
                parser.error(
                    "argument %s: invalid %s value: '%s'" % (
                        self.metavar, self.type.__name__, values))
        setattr(namespace, self.dest, values)


def main():
    parser = argparse.ArgumentParser(
        description='Interface for line-up management in JFR Teamy')

    parser.add_argument('round', metavar='ROUND',
                        action=DefaultArgumentInput,
                        type=int, nargs='?',
                        help='round number')
    parser.add_argument('segment', metavar='SEGMENT',
                        action=DefaultArgumentInput,
                        type=int, nargs='?',
                        help='segment number')
    parser.add_argument('table', metavar='TABLE', type=int,
                        nargs='?', default=None,
                        help='table to start from')

    arguments = parser.parse_args()

    try:
        Console(arguments.round, arguments.segment, arguments.table).run()
    except:
        print('ERROR: %s' % sys.exc_info()[1])


if __name__ == '__main__':
    main()