Skip to content

Commit

Permalink
status: improve tag matching pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
slyon committed Aug 15, 2023
1 parent ad66ec5 commit 073a190
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions netplan_cli/cli/commands/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 073a190

Please sign in to comment.