Re-implemented P4Command class with contextmanager and generator