valid mandatory arguments
This commit is contained in:
parent
dc550d0e69
commit
02f7e7eabf
@ -136,6 +136,11 @@ class TiramisuCmdlineParser(ArgumentParser):
|
|||||||
def add_subparsers(self, *args, **kwargs):
|
def add_subparsers(self, *args, **kwargs):
|
||||||
raise NotImplementedError('do not use add_subparsers')
|
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,
|
def _config_to_argparser(self,
|
||||||
_forhelp: bool,
|
_forhelp: bool,
|
||||||
config,
|
config,
|
||||||
@ -173,10 +178,7 @@ class TiramisuCmdlineParser(ArgumentParser):
|
|||||||
else:
|
else:
|
||||||
if self.fullpath and prefix:
|
if self.fullpath and prefix:
|
||||||
name = prefix + '.' + name
|
name = prefix + '.' + name
|
||||||
if len(name) == 1 and 'longargument' not in properties:
|
args = [self._gen_argument(name, properties)]
|
||||||
args = [self.prefix_chars + name]
|
|
||||||
else:
|
|
||||||
args = [self.prefix_chars * 2 + name]
|
|
||||||
if _forhelp and 'mandatory' in properties:
|
if _forhelp and 'mandatory' in properties:
|
||||||
kwargs['required'] = True
|
kwargs['required'] = True
|
||||||
if option.type() == 'bool':
|
if option.type() == 'bool':
|
||||||
@ -234,6 +236,13 @@ class TiramisuCmdlineParser(ArgumentParser):
|
|||||||
self.error('the following arguments are required: {}'.format(name))
|
self.error('the following arguments are required: {}'.format(name))
|
||||||
else:
|
else:
|
||||||
self.error('unrecognized arguments: {}'.format(name))
|
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
|
return namespaces
|
||||||
|
|
||||||
def format_usage(self,
|
def format_usage(self,
|
||||||
|
Loading…
Reference in New Issue
Block a user