timer.py 349 B

1234567891011121314151617
  1. """
  2. A timer context manager to measure the time taken to execute each command in the CLI.
  3. """
  4. import time
  5. from contextlib import contextmanager
  6. import asyncclick as click
  7. @contextmanager
  8. def timer():
  9. start = time.time()
  10. yield
  11. end = time.time()
  12. duration = max(0, end - start)
  13. click.echo(f"Time taken: {duration:.2f} seconds")