import click from piket_client.model import ServerStatus, NetworkError @click.group() def cli(): """Poke coco from the command line.""" pass @cli.command() def status(): """Show the current status of the server.""" status = ServerStatus.is_server_running() if isinstance(status, NetworkError): print_error(f"Failed to get data from server, error {status.value}") return print_ok("Server is available.") open_consumptions = ServerStatus.unsettled_consumptions() if isinstance(open_consumptions, NetworkError): print_error(f"Failed to get unsettled consumptions, error {open_consumptions.value}") return click.echo(f"There are {open_consumptions.amount} unsettled consumptions.") if open_consumptions.amount > 0: click.echo(f"First at: {open_consumptions.first_timestamp.strftime('%c')}") click.echo(f"Most recent at: {open_consumptions.last_timestamp.strftime('%c')}") @cli.group() def people(): pass @cli.group() def settlements(): pass def print_ok(msg: str) -> None: click.echo(click.style(msg, fg="green")) def print_error(msg: str) -> None: click.echo(click.style(msg, fg="red", bold=True), err=True) if __name__ == "__main__": cli()