_interactive_dummy.py 793 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env python3
  2. from __future__ import annotations
  3. import time
  4. class InteractiveDummyCommand:
  5. PROMPT = "(dummy) "
  6. def start(self):
  7. print("Started interactive dummy command")
  8. def send(self, input: str):
  9. print(f"Received input: {input}")
  10. time.sleep(0.5)
  11. def stop(self):
  12. print("Stopped interactive dummy command")
  13. def __call__(self):
  14. self.start()
  15. while True:
  16. inpt = input(self.PROMPT)
  17. cmd, _, args = inpt.partition(" ")
  18. if cmd == "stop":
  19. self.stop()
  20. break
  21. if cmd == "send":
  22. self.send(args)
  23. else:
  24. print(f"Unknown command: {cmd}")
  25. if __name__ == "__main__":
  26. InteractiveDummyCommand()()