Commit 65080308 authored by Emmanuel Garette's avatar Emmanuel Garette

positional arguments works well

parent 8e91667a
......@@ -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()
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment