Skip to content
Snippets Groups Projects
Commit 4c685c00 authored by Sven Mäder's avatar Sven Mäder :speech_balloon:
Browse files

Allow extendable simple argparser

parent e56065d0
No related branches found
No related tags found
No related merge requests found
......@@ -2,9 +2,10 @@
import argparse
def simple(description, arg=None, arg_help='', opts=dict(), noopts=dict()):
def extendable(description, arg=None, arg_help='', opts=dict(), noopts=dict()):
"""
Get cmd argument with simplified argparser
Get extendable simplified argparser
"""
parser = argparse.ArgumentParser(
add_help=False, description=description)
......@@ -15,18 +16,39 @@ def simple(description, arg=None, arg_help='', opts=dict(), noopts=dict()):
for k, v in opts.items():
if isinstance(v, list):
v = ', '.join(v)
parser.add_argument('-' + k[:1], '--' + k, dest=k,
action='store_const', const=True,
help='Show ' + v)
try:
parser.add_argument('-' + k[:1], '--' + k, dest=k,
action='store_const', const=True,
help='Show ' + v)
except argparse.ArgumentError:
parser.add_argument('--' + k, dest=k,
action='store_const', const=True,
help='Show ' + v)
for k, v in noopts.items():
if isinstance(v, list):
v = ', '.join(v)
parser.add_argument('-' + k[3:4].upper(), '--' + k, dest=k,
action='store_const', const=True,
help='Hide ' + v)
try:
parser.add_argument('-' + k[3:4].upper(), '--' + k, dest=k,
action='store_const', const=True,
help='Hide ' + v)
except argparse.ArgumentError:
parser.add_argument('--' + k, dest=k,
action='store_const', const=True,
help='Hide ' + v)
parser.add_argument('--help', action='help',
help='Show this help message and exit')
return parser
def simple(description, arg=None, arg_help='', opts=dict(), noopts=dict()):
"""
Get cmd argument with simplified argparser
"""
parser = extendable(description, arg=arg, arg_help=arg_help, opts=opts, noopts=noopts)
return vars(parser.parse_args())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment