diff --git a/test/test_optiondescription.py b/test/test_optiondescription.py index ba42e86..290901e 100644 --- a/test/test_optiondescription.py +++ b/test/test_optiondescription.py @@ -9,7 +9,7 @@ from tiramisu import IntOption, StrOption, BoolOption, ChoiceOption, \ from tiramisu_api import Config as JsonConfig -def get_config(json, has_tree=False, default_verbosity=False, add_long=False, add_store_false=False): +def get_config(json, has_tree=False, default_verbosity=False, add_long=False, add_store_false=False, empty_optiondescription=False): choiceoption = ChoiceOption('cmd', 'choice the sub argument', ('str', 'list', 'int', 'none'), @@ -26,8 +26,12 @@ def get_config(json, has_tree=False, default_verbosity=False, add_long=False, ad booloption, short_booloption, ]) + if empty_optiondescription: + descr = None + else: + descr = 'First OptionDescription' od1 = OptionDescription('od1', - 'First OptionDescription', + descr, [od0]) before = StrOption('before', 'Before', @@ -137,9 +141,6 @@ def test_optiondescription_help_remove_empty_description_od(json): optional arguments: -h, --help show this help message and exit -od1: - First OptionDescription - od1.od0: Sub-Tree 1 @@ -148,13 +149,17 @@ od1.od0: increase output verbosity -nv, --od1.od0.no-verbosity +od2: + --od2.before BEFORE Before + --od2.after AFTER After + od2.subtree: Sub-Tree 2 --od2.subtree.str STR string option 2 """ - parser = TiramisuCmdlineParser(get_config(json), 'prog.py', remove_empty_description_od=True) + parser = TiramisuCmdlineParser(get_config(json, empty_optiondescription=True), 'prog.py') f = StringIO() with redirect_stdout(f): parser.print_help() diff --git a/tiramisu_cmdline_parser/api.py b/tiramisu_cmdline_parser/api.py index e292a8b..3338fa3 100644 --- a/tiramisu_cmdline_parser/api.py +++ b/tiramisu_cmdline_parser/api.py @@ -128,13 +128,6 @@ class TiramisuHelpFormatter: len(self.items) == 1 and \ self.items[0][0].__name__ == '_format_text': return '' - # Remove OD if name == description - if self.formatter.remove_empty_description_od and \ - self.items is not None and \ - self.heading is not None and \ - len(self.items) > 1 and \ - self.items[0][0].__name__ != '_format_text': - return '' return super().format_help() @@ -227,7 +220,6 @@ class TiramisuCmdlineParser(ArgumentParser): root: str=None, fullpath: bool=True, remove_empty_od: bool=False, - remove_empty_description_od: bool=False, formatter_class=HelpFormatter, _forhelp: bool=False, **kwargs): @@ -235,11 +227,9 @@ class TiramisuCmdlineParser(ArgumentParser): self.config = config self.root = root self.remove_empty_od = remove_empty_od - self.remove_empty_description_od = remove_empty_description_od if TiramisuHelpFormatter not in formatter_class.__mro__: formatter_class = type('TiramisuHelpFormatter', (TiramisuHelpFormatter, formatter_class), {}) formatter_class.remove_empty_od = self.remove_empty_od - formatter_class.remove_empty_description_od = self.remove_empty_description_od kwargs['formatter_class'] = formatter_class if self.root is None: subconfig = self.config.option @@ -294,9 +284,9 @@ class TiramisuCmdlineParser(ArgumentParser): self.prog, root=self.root, remove_empty_od=self.remove_empty_od, - remove_empty_description_od=self.remove_empty_description_od, formatter_class=self.formatter_class, epilog=self.epilog, + description=self.description, fullpath=self.fullpath) namespace_, args_ = new_parser._parse_known_args(args_, new_parser.namespace) else: @@ -555,9 +545,9 @@ class TiramisuCmdlineParser(ArgumentParser): root=self.root, fullpath=self.fullpath, remove_empty_od=self.remove_empty_od, - remove_empty_description_od=self.remove_empty_description_od, formatter_class=self.formatter_class, epilog=self.epilog, + description=self.description, _forhelp=True) return super(TiramisuCmdlineParser, help_formatter).format_usage(*args, **kwargs) @@ -567,9 +557,9 @@ class TiramisuCmdlineParser(ArgumentParser): root=self.root, fullpath=self.fullpath, remove_empty_od=self.remove_empty_od, - remove_empty_description_od=self.remove_empty_description_od, formatter_class=self.formatter_class, epilog=self.epilog, + description=self.description, _forhelp=True) return super(TiramisuCmdlineParser, help_formatter).format_help()