diff --git a/tiramisu_cmdline_parser.py b/tiramisu_cmdline_parser.py index a6cec66..c2dbe17 100644 --- a/tiramisu_cmdline_parser.py +++ b/tiramisu_cmdline_parser.py @@ -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,