positional arguments works well

This commit is contained in:
Emmanuel Garette 2019-01-28 17:05:50 +01:00
parent 8e91667a66
commit 6508030888
2 changed files with 16 additions and 10 deletions

View file

@ -17,8 +17,8 @@ from tiramisu import IntOption, StrOption, BoolOption, ChoiceOption, \
choiceoption = ChoiceOption('cmd',
'choice the sub argument',
('str', 'list', 'int'),
properties=('mandatory',))
# 'positional'))
properties=('mandatory',
'positional'))
# * a boolean to pass script in verbosity mode with argument -v --verbosity
booloption = BoolOption('verbosity',
'increase output verbosity',
@ -60,6 +60,7 @@ config = Config(OptionDescription('root',
int_
]))
# initialise the parser
config.property.read_write()
parser = TiramisuCmdlineParser(config)
# parse arguments of current script
parser.parse_args()

View file

@ -166,16 +166,17 @@ class TiramisuCmdlineParser(ArgumentParser):
if name.startswith(self.prefix_chars):
raise ValueError('name cannot startswith "{}"'.format(self.prefix_chars))
properties = obj.property.get()
kwargs = {'help': option.doc().replace('%', '%%'),
'default': SUPPRESS,
'dest': option.path()}
kwargs = {'help': option.doc().replace('%', '%%')}
if 'positional' in properties:
#if not 'mandatory' in properties:
# raise ValueError('"positional" argument must be "mandatory" too')
args = [name]
args = [option.path()]
#if option.requires():
kwargs['default'] = obj.value.get()
kwargs['nargs'] = '?'
else:
kwargs['dest'] = option.path()
kwargs['default'] = SUPPRESS
if self.fullpath and prefix:
name = prefix + '.' + name
args = [self._gen_argument(name, properties)]
@ -240,11 +241,15 @@ class TiramisuCmdlineParser(ArgumentParser):
self.error('unrecognized arguments: {}'.format(name))
if valid_mandatory:
for key in self.config.value.mandatory():
if self.fullpath or '.' not in key:
name = key
properties = self.config.option(key).property.get()
if 'positional' not in properties:
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())
else:
name = key.rsplit('.', 1)[1]
args = self._gen_argument(name, self.config.option(key).property.get())
args = key
self.error('the following arguments are required: {}'.format(args))
return namespaces