valid mandatory arguments

This commit is contained in:
Emmanuel Garette 2019-01-16 17:44:49 +01:00
parent dc550d0e69
commit 02f7e7eabf

View File

@ -136,6 +136,11 @@ class TiramisuCmdlineParser(ArgumentParser):
def add_subparsers(self, *args, **kwargs):
raise NotImplementedError('do not use add_subparsers')
def _gen_argument(self, name, properties):
if len(name) == 1 and 'longargument' not in properties:
return self.prefix_chars + name
return self.prefix_chars * 2 + name
def _config_to_argparser(self,
_forhelp: bool,
config,
@ -173,10 +178,7 @@ class TiramisuCmdlineParser(ArgumentParser):
else:
if self.fullpath and prefix:
name = prefix + '.' + name
if len(name) == 1 and 'longargument' not in properties:
args = [self.prefix_chars + name]
else:
args = [self.prefix_chars * 2 + name]
args = [self._gen_argument(name, properties)]
if _forhelp and 'mandatory' in properties:
kwargs['required'] = True
if option.type() == 'bool':
@ -234,6 +236,13 @@ class TiramisuCmdlineParser(ArgumentParser):
self.error('the following arguments are required: {}'.format(name))
else:
self.error('unrecognized arguments: {}'.format(name))
for key in self.config.value.mandatory():
if self.fullpath or '.' not in key:
name = key
else:
name = key.rsplit('.', 1)[1]
args = self._gen_argument(name, self.config.option(key).property.get())
self.error('the following arguments are required: {}'.format(args))
return namespaces
def format_usage(self,