1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

33 lines
884 B
Python
Raw Normal View History

2021-09-11 00:47:01 -07:00
"""Remove anything before the command if found in output."""
# Standard Library
from typing import TYPE_CHECKING
2021-09-11 00:47:01 -07:00
# Third Party
from pydantic import PrivateAttr
2021-09-11 00:47:01 -07:00
# Local
from .._output import OutputPlugin
if TYPE_CHECKING:
# Project
from hyperglass.models.config.devices import Device
2021-09-11 00:47:01 -07:00
class RemoveCommand(OutputPlugin):
"""Remove anything before the command if found in output."""
__hyperglass_builtin__: bool = PrivateAttr(True)
def process(self, device_output: str, device: "Device") -> str:
2021-09-11 00:47:01 -07:00
"""Remove anything before the command if found in output."""
output = device_output.strip().split("\n")
for command in device.directive_commands:
for line in output:
if command in line:
idx = output.index(line) + 1
output = output[idx:]
return "\n".join(output)