feat: add 'add_help' option un TiramisuCmdLineParser
This commit is contained in:
parent
9befbf0ade
commit
f458c9eefc
1 changed files with 9 additions and 7 deletions
|
|
@ -332,6 +332,7 @@ class TiramisuCmdlineParser(ArgumentParser):
|
||||||
unrestraint: bool = False,
|
unrestraint: bool = False,
|
||||||
add_extra_options: bool = True,
|
add_extra_options: bool = True,
|
||||||
short_name_max_len: int = 1,
|
short_name_max_len: int = 1,
|
||||||
|
add_help: bool = True,
|
||||||
_forhelp: bool = False,
|
_forhelp: bool = False,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
|
|
@ -345,6 +346,7 @@ class TiramisuCmdlineParser(ArgumentParser):
|
||||||
self.add_extra_options = add_extra_options
|
self.add_extra_options = add_extra_options
|
||||||
self.display_modified_value = display_modified_value
|
self.display_modified_value = display_modified_value
|
||||||
self.short_name_max_len = short_name_max_len
|
self.short_name_max_len = short_name_max_len
|
||||||
|
self.add_help = add_help
|
||||||
if TiramisuHelpFormatter not in formatter_class.__mro__:
|
if TiramisuHelpFormatter not in formatter_class.__mro__:
|
||||||
formatter_class = type(
|
formatter_class = type(
|
||||||
"TiramisuHelpFormatter", (TiramisuHelpFormatter, formatter_class), {}
|
"TiramisuHelpFormatter", (TiramisuHelpFormatter, formatter_class), {}
|
||||||
|
|
@ -361,7 +363,7 @@ class TiramisuCmdlineParser(ArgumentParser):
|
||||||
else:
|
else:
|
||||||
subconfig = subconfig.option(self.root)
|
subconfig = subconfig.option(self.root)
|
||||||
self.namespace = TiramisuNamespace(self.config, self.root)
|
self.namespace = TiramisuNamespace(self.config, self.root)
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, add_help=add_help, **kwargs)
|
||||||
self.register("action", "help", _TiramisuHelpAction)
|
self.register("action", "help", _TiramisuHelpAction)
|
||||||
self._config_to_argparser(
|
self._config_to_argparser(
|
||||||
_forhelp,
|
_forhelp,
|
||||||
|
|
@ -419,16 +421,16 @@ class TiramisuCmdlineParser(ArgumentParser):
|
||||||
add_extra_options=self.add_extra_options,
|
add_extra_options=self.add_extra_options,
|
||||||
short_name_max_len=self.short_name_max_len,
|
short_name_max_len=self.short_name_max_len,
|
||||||
fullpath=self.fullpath,
|
fullpath=self.fullpath,
|
||||||
|
add_help=self.add_help,
|
||||||
)
|
)
|
||||||
namespace_, args_ = new_parser._parse_known_args(
|
namespace_, args_ = new_parser._parse_known_args(
|
||||||
args_, new_parser.namespace, *others
|
args_, new_parser.namespace, *others
|
||||||
)
|
)
|
||||||
else:
|
elif self._registries["action"]["help"].needs:
|
||||||
if self._registries["action"]["help"].needs:
|
# display help only when all variables assignemnt are done
|
||||||
# display help only when all variables assignemnt are done
|
self._registries["action"]["help"].needs = False
|
||||||
self._registries["action"]["help"].needs = False
|
helper = self._registries["action"]["help"](None)
|
||||||
helper = self._registries["action"]["help"](None)
|
helper.display(self)
|
||||||
helper.display(self)
|
|
||||||
return namespace_, args_
|
return namespace_, args_
|
||||||
|
|
||||||
def add_argument(self, *args, **kwargs):
|
def add_argument(self, *args, **kwargs):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue