1
0
mirror of https://github.com/mbirth/tcl_ota_check.git synced 2024-11-09 22:06:47 +00:00
tcl_ota_check/tcllib/argparser.py

28 lines
968 B
Python
Raw Normal View History

2018-02-03 20:40:17 +00:00
#!/usr/bin/env python3
2018-02-02 02:33:53 +00:00
# -*- coding: utf-8 -*-
2018-02-03 20:40:17 +00:00
# pylint: disable=C0111,C0326,C0103
2018-02-02 02:33:53 +00:00
2018-02-03 21:25:26 +00:00
"""Custom argument parser."""
2018-02-02 02:33:53 +00:00
import argparse
import webbrowser
2018-02-03 20:24:36 +00:00
2018-02-02 02:33:53 +00:00
class DefaultParser(argparse.ArgumentParser):
2018-02-03 21:25:26 +00:00
"""argparse parser with some defaults set."""
2018-02-02 02:33:53 +00:00
def __init__(self, appname, desc=None):
2018-02-03 21:25:26 +00:00
"""Set default name, description, epilogue, arguments."""
homeurl = "https://github.com/mbirth/tcl_ota_check"
super().__init__(prog=appname, description=desc, epilog=homeurl)
2018-02-02 02:33:53 +00:00
self.add_argument("--webdb", help="open web database in browser and exit", action="store_true")
def parse_args(self, args=None, namespace=None):
2018-02-03 21:25:26 +00:00
"""Parse special args first, defer to parent class second."""
2018-02-02 02:33:53 +00:00
if set(args) & {"--webdb"}: # if they intersect
webbrowser.open("https://tclota.birth-online.de/", new=2)
raise SystemExit
else:
argx = super().parse_args(args, namespace)
return argx