diff options
author | emkael <emkael@tlen.pl> | 2016-11-25 22:33:15 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2016-11-25 22:33:15 +0100 |
commit | 69449fe53c8bfc226bf48a9680d29c77e99dcf3c (patch) | |
tree | f7bcaac5ad04d4a9a62e05e6a52eb6c46a19a1da /quick_lineup.py | |
parent | 33159ab536d15adab09da18e0012889023887ec9 (diff) |
Parsing command-line arguments with argparse
Diffstat (limited to 'quick_lineup.py')
-rw-r--r-- | quick_lineup.py | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/quick_lineup.py b/quick_lineup.py index 965922e..7da857f 100644 --- a/quick_lineup.py +++ b/quick_lineup.py @@ -1,21 +1,24 @@ +import argparse import sys from ql.console import Console def main(): - if len(sys.argv) < 3 or len(sys.argv) > 4: - print('Give correct parameters: round, segment and (optionally) table') - sys.exit(1) + parser = argparse.ArgumentParser( + description='Interface for line-up management in JFR Teamy') - round = int(sys.argv[1]) - segment = int(sys.argv[2]) - if len(sys.argv) == 4: - table = int(sys.argv[3]) - else: - table = None + parser.add_argument('round', metavar='ROUND', type=int, + help='round number') + parser.add_argument('segment', metavar='SEGMENT', type=int, + 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(round, segment, table).run() + Console(arguments.round, arguments.segment, arguments.table).run() except: print('ERROR: %s' % sys.exc_info()[1]) |