diff --git a/qfieldcloud_sdk/cli.py b/qfieldcloud_sdk/cli.py index ff9f675..1184dd8 100755 --- a/qfieldcloud_sdk/cli.py +++ b/qfieldcloud_sdk/cli.py @@ -177,6 +177,28 @@ def logout(ctx): log(payload["detail"]) +@cli.command() +@click.pass_context +def status(ctx: Context): + """Check the status of the QFieldCloud server.""" + log("Checking server status...") + client: sdk.Client = ctx.obj["client"] + is_json: bool = ctx.obj["format_json"] + + status_info = client.check_server_status() + + if is_json: + print_json(status_info) + else: + log(click.style("Server Status:", bold=True)) + + if isinstance(status_info, dict): + for key, value in status_info.items(): + log(f" {key.replace('_', ' ').capitalize()}: {value}") + else: + log(str(status_info)) + + @cli.command() @paginated @click.option( diff --git a/qfieldcloud_sdk/sdk.py b/qfieldcloud_sdk/sdk.py index 5cc7aa8..1de7156 100644 --- a/qfieldcloud_sdk/sdk.py +++ b/qfieldcloud_sdk/sdk.py @@ -302,6 +302,28 @@ def logout(self) -> None: return resp.json() + def check_server_status(self) -> Dict[str, Any]: + """Checks the status of the QFieldCloud server. + + This endpoint usually provides information of the server health. + + Returns: + A dictionary containing the server status information (e.g., {"storage": "ok", ...}). + + Example: + ```python + client = sdk.Client(url="[https://app.qfield.cloud/api/v1/](https://app.qfield.cloud/api/v1/)") + status = client.check_server_status() + print(f"Server status: {status}") + ``` + """ + resp = self._request( + "GET", + "status/", + skip_token=True, + ) + return resp.json() + def list_projects( self, include_public: bool = False,