Merge pull request #1805 from Abperron/enh-2047-log-show-last-x

[enh] Implement 'yunohost log show last' to display the last log file.
This commit is contained in:
Alexandre Aubin 2024-05-18 14:29:36 +02:00 committed by GitHub
commit 48c673478d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

2
share/actionsmap.yml Normal file → Executable file
View file

@ -1976,7 +1976,7 @@ log:
- display
arguments:
path:
help: Log file which to display the content
help: Log file which to display the content. 'last' or 'last-X' selects the last but X log file
-n:
full: --number
help: Number of lines to display

14
src/log.py Normal file → Executable file
View file

@ -173,6 +173,20 @@ def log_show(
share
"""
# Set up path with correct value if 'last' or 'last-X' magic keywords are used
last = re.match(r"last(?:-(?P<position>[0-9]{1,6}))?$", path)
if last:
position = 1
if last.group("position") is not None:
position += int(last.group("position"))
logs = list(log_list()["operation"])
if position > len(logs):
raise YunohostValidationError(f"There isn't that many logs", raw_msg=True)
path = logs[-position]["path"]
if share:
filter_irrelevant = True