Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions mcstatus/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from __future__ import annotations

import argparse
import dataclasses
import json
import socket
import sys
Expand Down Expand Up @@ -122,21 +121,9 @@ def json_cmd(server: SupportedServers) -> int:
data["error"] = str(exn)

if status_res is not None:
data["status"] = dataclasses.asdict(status_res)

# ensure we are overwriting the motd and not making a new dict field
assert "motd" in data["status"], "motd field missing. has it been renamed?"
data["status"]["motd"] = status_res.motd.simplify().to_minecraft()

data["status"] = status_res.as_dict()
if query_res is not None:
# TODO: QueryResponse is not (yet?) a dataclass
data["query"] = qdata = {}

qdata["ip"] = query_res.raw["hostip"]
qdata["port"] = query_res.raw["hostport"]
qdata["map"] = query_res.map_name
qdata["plugins"] = query_res.software.plugins
qdata["raw"] = query_res.raw
data["query"] = query_res.as_dict()

json.dump(data, sys.stdout)
return 0
Expand Down
22 changes: 19 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,25 @@ def test_json(mock_network_requests):
},
"query": {
"ip": "192.168.56.1",
"port": "9999",
"map": "world",
"plugins": [],
"port": 9999,
"map_name": "world",
"motd": "A Minecraft Server",
"game_id": "GAME ID",
"game_type": "GAME TYPE",
"players": {
"list": [
"Dinnerbone",
"Djinnibone",
"Steve",
],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really consider adding new fields to JSON as a breaking change, but we can postpone this PR until v13

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I'm not sure, I mean, it depends on how people are using this output, it could be breaking (if used with some kind of strict parsing into specific fields, where all have to be consumed), or it might not be (more likely).

The change of port from str to int might also be breaking.

I don't know how we should treat these kind of changes in the CLI. I think most people that rely on the kind of consumption where this would be breaking are likely using mcstatus as a library, rather than calling it via CLI, and generally, I think most people that are using it as CLI are doing so from simple bash scripts where these changes very likely wouldn't be braking, so I don't think it'd be particularly wrong to release this without a braking change. Though I also wouldn't mind postponing until the next major release.

Copy link
Member Author

@PerchunPak PerchunPak Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to postpone it after all, this is purely an internal QOL change

"max": 20,
"online": 3,
},
"software": {
"brand": "vanilla",
"plugins": [],
"version": "1.8",
},
"raw": {
"hostname": "A Minecraft Server",
"gametype": "GAME TYPE",
Expand Down