Files

43 lines
933 B
Python
Raw Permalink Normal View History

class Args:
def __init__(self, argv):
self.__argv = argv
def get_positional(self, index):
if len(self.__argv) > index:
return self.__argv[index]
return None
def get_named(self, name, index, nr_args):
found_name = False
values = []
for s in self.__argv:
if found_name:
if nr_args > 0:
nr_args -= 1
values.append(s)
continue
else:
break
if s == '--{}'.format(name):
if index > 0:
index -= 1
continue
found_name = True
continue
if nr_args == 0:
return found_name
if nr_args > 0 or not found_name:
return None
if len(values) == 1:
return values[0]
return values