positional arguments works well
This commit is contained in:
parent
8e91667a66
commit
6508030888
|
@ -17,8 +17,8 @@ from tiramisu import IntOption, StrOption, BoolOption, ChoiceOption, \
|
||||||
choiceoption = ChoiceOption('cmd',
|
choiceoption = ChoiceOption('cmd',
|
||||||
'choice the sub argument',
|
'choice the sub argument',
|
||||||
('str', 'list', 'int'),
|
('str', 'list', 'int'),
|
||||||
properties=('mandatory',))
|
properties=('mandatory',
|
||||||
# 'positional'))
|
'positional'))
|
||||||
# * a boolean to pass script in verbosity mode with argument -v --verbosity
|
# * a boolean to pass script in verbosity mode with argument -v --verbosity
|
||||||
booloption = BoolOption('verbosity',
|
booloption = BoolOption('verbosity',
|
||||||
'increase output verbosity',
|
'increase output verbosity',
|
||||||
|
@ -60,6 +60,7 @@ config = Config(OptionDescription('root',
|
||||||
int_
|
int_
|
||||||
]))
|
]))
|
||||||
# initialise the parser
|
# initialise the parser
|
||||||
|
config.property.read_write()
|
||||||
parser = TiramisuCmdlineParser(config)
|
parser = TiramisuCmdlineParser(config)
|
||||||
# parse arguments of current script
|
# parse arguments of current script
|
||||||
parser.parse_args()
|
parser.parse_args()
|
||||||
|
|
|
@ -166,16 +166,17 @@ class TiramisuCmdlineParser(ArgumentParser):
|
||||||
if name.startswith(self.prefix_chars):
|
if name.startswith(self.prefix_chars):
|
||||||
raise ValueError('name cannot startswith "{}"'.format(self.prefix_chars))
|
raise ValueError('name cannot startswith "{}"'.format(self.prefix_chars))
|
||||||
properties = obj.property.get()
|
properties = obj.property.get()
|
||||||
kwargs = {'help': option.doc().replace('%', '%%'),
|
kwargs = {'help': option.doc().replace('%', '%%')}
|
||||||
'default': SUPPRESS,
|
|
||||||
'dest': option.path()}
|
|
||||||
if 'positional' in properties:
|
if 'positional' in properties:
|
||||||
#if not 'mandatory' in properties:
|
#if not 'mandatory' in properties:
|
||||||
# raise ValueError('"positional" argument must be "mandatory" too')
|
# raise ValueError('"positional" argument must be "mandatory" too')
|
||||||
args = [name]
|
args = [option.path()]
|
||||||
#if option.requires():
|
#if option.requires():
|
||||||
|
kwargs['default'] = obj.value.get()
|
||||||
kwargs['nargs'] = '?'
|
kwargs['nargs'] = '?'
|
||||||
else:
|
else:
|
||||||
|
kwargs['dest'] = option.path()
|
||||||
|
kwargs['default'] = SUPPRESS
|
||||||
if self.fullpath and prefix:
|
if self.fullpath and prefix:
|
||||||
name = prefix + '.' + name
|
name = prefix + '.' + name
|
||||||
args = [self._gen_argument(name, properties)]
|
args = [self._gen_argument(name, properties)]
|
||||||
|
@ -240,11 +241,15 @@ class TiramisuCmdlineParser(ArgumentParser):
|
||||||
self.error('unrecognized arguments: {}'.format(name))
|
self.error('unrecognized arguments: {}'.format(name))
|
||||||
if valid_mandatory:
|
if valid_mandatory:
|
||||||
for key in self.config.value.mandatory():
|
for key in self.config.value.mandatory():
|
||||||
if self.fullpath or '.' not in key:
|
properties = self.config.option(key).property.get()
|
||||||
name = key
|
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:
|
else:
|
||||||
name = key.rsplit('.', 1)[1]
|
args = key
|
||||||
args = self._gen_argument(name, self.config.option(key).property.get())
|
|
||||||
self.error('the following arguments are required: {}'.format(args))
|
self.error('the following arguments are required: {}'.format(args))
|
||||||
return namespaces
|
return namespaces
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue