Digitale bierlijst

cli.py 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import click
  2. from piket_client.model import ServerStatus, NetworkError
  3. @click.group()
  4. def cli():
  5. """Poke coco from the command line."""
  6. pass
  7. @cli.command()
  8. def status():
  9. """Show the current status of the server."""
  10. status = ServerStatus.is_server_running()
  11. if isinstance(status, NetworkError):
  12. print_error(f"Failed to get data from server, error {status.value}")
  13. return
  14. print_ok("Server is available.")
  15. open_consumptions = ServerStatus.unsettled_consumptions()
  16. if isinstance(open_consumptions, NetworkError):
  17. print_error(f"Failed to get unsettled consumptions, error {open_consumptions.value}")
  18. return
  19. click.echo(f"There are {open_consumptions.amount} unsettled consumptions.")
  20. if open_consumptions.amount > 0:
  21. click.echo(f"First at: {open_consumptions.first_timestamp.strftime('%c')}")
  22. click.echo(f"Most recent at: {open_consumptions.last_timestamp.strftime('%c')}")
  23. @cli.group()
  24. def people():
  25. pass
  26. @cli.group()
  27. def settlements():
  28. pass
  29. def print_ok(msg: str) -> None:
  30. click.echo(click.style(msg, fg="green"))
  31. def print_error(msg: str) -> None:
  32. click.echo(click.style(msg, fg="red", bold=True), err=True)
  33. if __name__ == "__main__":
  34. cli()