From 073a19004d44e0ddb189e9b17124959ca493d194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20M=C3=A4rdian?= Date: Tue, 15 Aug 2023 11:20:19 +0200 Subject: [PATCH] status: improve tag matching pattern --- netplan_cli/cli/commands/status.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/netplan_cli/cli/commands/status.py b/netplan_cli/cli/commands/status.py index 7b65f37e2..908e31582 100644 --- a/netplan_cli/cli/commands/status.py +++ b/netplan_cli/cli/commands/status.py @@ -27,6 +27,7 @@ from ..state import SystemConfigState, JSON +MATCH_TAGS = re.compile(r'\[([a-z0-9]+)\].*\[\/\1\]') RICH_OUTPUT = False try: from rich.console import Console @@ -67,9 +68,11 @@ def run(self): def plain_print(self, *args, **kwargs): if len(args): - pattern = r'\[\/?\w+\]' lst = list(args) - lst[0] = re.sub(pattern, '', lst[0]) # remove any tags, like '[...]' or '[/...]' + for tag in MATCH_TAGS.findall(lst[0]): + # remove matching opening and closing tag + lst[0] = lst[0].replace('[{}]'.format(tag), '')\ + .replace('[/{}]'.format(tag), '') return print(*lst, **kwargs) return print(*args, **kwargs)