Total Complexity | 3 |
Total Lines | 29 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | #!/usr/bin/env python3 |
||
2 | # -*- coding: utf-8 -*- |
||
3 | |||
4 | # pylint: disable=C0111,C0326,C0103 |
||
5 | |||
6 | """Custom argument parser.""" |
||
7 | |||
8 | import argparse |
||
9 | import webbrowser |
||
10 | |||
11 | |||
12 | class DefaultParser(argparse.ArgumentParser): |
||
|
|||
13 | """argparse parser with some defaults set.""" |
||
14 | |||
15 | def __init__(self, appname, desc=None): |
||
16 | """Set default name, description, epilogue, arguments.""" |
||
17 | homeurl = "https://github.com/mbirth/tcl_ota_check" |
||
18 | super().__init__(prog=appname, description=desc, epilog=homeurl) |
||
19 | self.add_argument("--webdb", help="open web database in browser and exit", action="store_true") |
||
20 | |||
21 | def parse_args(self, args=None, namespace=None): |
||
22 | """Parse special args first, defer to parent class second.""" |
||
23 | if set(args) & {"--webdb"}: # if they intersect |
||
24 | webbrowser.open("https://tclota.birth-online.de/", new=2) |
||
25 | raise SystemExit |
||
26 | else: |
||
27 | argx = super().parse_args(args, namespace) |
||
28 | return argx |
||
29 |