From e0491111107c19f14252122748d59e93d7379bae Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Fri, 3 Oct 2025 10:34:04 +0000 Subject: [PATCH] CmdGroupMgr:list_cmd_groups(): cleanups --- test/cmdtest_d/include/group_mgr.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/test/cmdtest_d/include/group_mgr.py b/test/cmdtest_d/include/group_mgr.py index 745c056b..118eea25 100755 --- a/test/cmdtest_d/include/group_mgr.py +++ b/test/cmdtest_d/include/group_mgr.py @@ -151,27 +151,26 @@ class CmdGroupMgr: return self.load_mod(gname, self.cmd_groups[gname].params.get('modname')) def list_cmd_groups(self): - ginfo = [] - for gname in self.cmd_groups: - ginfo.append((gname, self.get_cls_by_gname(gname))) if self.cfg.list_current_cmd_groups: - exclude = (self.cfg.exclude_groups or '').split(',') - ginfo = [g for g in ginfo - if self.network_id in g[1].networks - and not g[0] in exclude - and g[0] in tuple(self.cmd_groups_dfl) + tuple(self.cfg._args)] + names = tuple(cmd_groups_dfl) + tuple(self.cfg._args) + exclude = self.cfg.exclude_groups.split(',') if self.cfg.exclude_groups else [] + ginfo = {name: cls + for name, cls in [(gname, self.get_cls_by_gname(gname)) for gname in names] + if self.network_id in cls.networks and not name in exclude} desc = 'CONFIGURED' else: + ginfo = {name: self.get_cls_by_gname(name) for name in self.cmd_groups} desc = 'AVAILABLE' def gen_output(): yield green(f'{desc} COMMAND GROUPS AND SUBGROUPS:') yield '' - for name, cls in ginfo: + name_w = max(len(name) for name in ginfo) + for name, cls in ginfo.items(): if not cls.is_helper: yield ' {} - {}'.format( - yellow(name.ljust(13)), + yellow(name.ljust(name_w)), (cls.__doc__.strip() if cls.__doc__ else cls.__name__)) if 'cmd_subgroups' in cls.__dict__: subgroups = {k:v for k, v in cls.cmd_subgroups.items() if not k.startswith('_')} @@ -181,8 +180,7 @@ class CmdGroupMgr: from mmgen.ui import do_pager do_pager('\n'.join(gen_output())) - - Msg('\n' + ' '.join(e[0] for e in ginfo)) + Msg('\n' + ' '.join(ginfo)) def find_cmd_in_groups(self, cmd, group=None): """