mcserver-cli 4.0.0.dev0__py3-none-any.whl → 4.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. mcserver/__init__.py +1 -1
  2. mcserver/cli.py +131 -157
  3. mcserver/commands/__init__.py +18 -18
  4. mcserver/commands/add_projects.py +218 -127
  5. mcserver/commands/import_setup.py +1 -1
  6. mcserver/commands/initialize_server.py +39 -15
  7. mcserver/commands/list_projects.py +1 -1
  8. mcserver/commands/op_grant.py +1 -1
  9. mcserver/commands/op_list.py +1 -1
  10. mcserver/commands/op_revoke.py +1 -1
  11. mcserver/commands/print_help.py +1 -1
  12. mcserver/commands/remove_projects.py +1 -1
  13. mcserver/commands/search_projects.py +141 -71
  14. mcserver/commands/server_status.py +1 -1
  15. mcserver/commands/show_projects.py +94 -18
  16. mcserver/commands/start_server.py +26 -14
  17. mcserver/commands/stop_server.py +2 -10
  18. mcserver/commands/update_projects.py +1 -1
  19. mcserver/commands/whitelist_add.py +1 -1
  20. mcserver/commands/whitelist_list.py +10 -9
  21. mcserver/commands/whitelist_remove.py +31 -25
  22. mcserver/config.py +14 -3
  23. mcserver/fabricmc/meta.py +1 -1
  24. mcserver/metadata.py +16 -6
  25. mcserver/modrinth/apis/__init__.py +5 -5
  26. mcserver/modrinth/apis/get_project_informations.py +49 -44
  27. mcserver/modrinth/apis/get_project_versions.py +85 -40
  28. mcserver/modrinth/apis/search_projects.py +64 -27
  29. mcserver/modrinth/project_records.py +40 -28
  30. mcserver/modrinth/shared.py +22 -20
  31. mcserver/modrinth/slug_index.py +3 -7
  32. mcserver/modrinth/typings/__init__.py +26 -14
  33. mcserver/modrinth/typings/{project_informations.py → project_information.py} +5 -3
  34. mcserver/modrinth/typings/project_version.py +90 -0
  35. mcserver/mysterious.py +1 -1
  36. mcserver/networking.py +3 -0
  37. mcserver/paths.py +2 -1
  38. mcserver/resolver.py +47 -30
  39. mcserver/server_files/paths.py +3 -0
  40. mcserver/server_files/whitelist.py +102 -148
  41. mcserver/shared.py +29 -7
  42. {mcserver_cli-4.0.0.dev0.dist-info → mcserver_cli-4.3.0.dist-info}/METADATA +6 -5
  43. mcserver_cli-4.3.0.dist-info/RECORD +70 -0
  44. {mcserver_cli-4.0.0.dev0.dist-info → mcserver_cli-4.3.0.dist-info}/WHEEL +1 -1
  45. mcserver/mcserver_v2.0.0.py +0 -1119
  46. mcserver/modrinth/api.py +0 -768
  47. mcserver/modrinth/project_records/metadata.py +0 -0
  48. mcserver/modrinth/project_records/relationships.py +0 -205
  49. mcserver/modrinth/project_records/shared.py +0 -8
  50. mcserver_cli-4.0.0.dev0.dist-info/RECORD +0 -73
  51. /mcserver/{legacyfabric → legacy_fabric}/meta.py +0 -0
  52. {mcserver_cli-4.0.0.dev0.dist-info → mcserver_cli-4.3.0.dist-info}/entry_points.txt +0 -0
  53. {mcserver_cli-4.0.0.dev0.dist-info → mcserver_cli-4.3.0.dist-info}/licenses/LICENSE +0 -0
mcserver/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "4.0.0.dev0"
1
+ __version__ = "4.3.0"
mcserver/cli.py CHANGED
@@ -1,114 +1,119 @@
1
- def main() -> int:
2
- import argparse
3
- import sys
4
-
5
- from . import __version__
6
- from .modrinth.shared import search_sort_index
7
- from .shared import loader_list
8
-
9
- def bound_int(min_integer: int, max_integer: int | None = None):
10
- def parse(cli_string: str):
11
- try:
12
- integer = int(cli_string)
13
- except TypeError:
14
- raise argparse.ArgumentTypeError(f"{cli_string} is not an integer")
15
-
16
- if integer <= min_integer:
17
- raise argparse.ArgumentTypeError(
18
- f"{integer} must be higher than or equal to {min_integer}"
19
- )
20
- if max_integer is not None and integer >= max_integer:
21
- raise argparse.ArgumentTypeError(
22
- f"{integer} must be between {min_integer} and {max_integer} (inclusive)"
23
- )
24
- return integer
25
-
26
- return parse
27
-
28
- def command_function(args: argparse.Namespace) -> int:
29
- command_name: str = args.command_name
30
-
31
- match command_name:
32
- case "add":
33
- from .commands import add_projects
34
-
35
- return add_projects(args)
36
- case "import":
37
- from .commands import import_setup
38
-
39
- return import_setup(args)
40
- case "help":
41
- from .commands import print_help
42
-
43
- return print_help(args)
44
- case "init":
45
- from .commands import initialize_server
46
-
47
- return initialize_server(args)
48
- case "list":
49
- from .commands import list_projects
50
-
51
- return list_projects(args)
52
- case "op_grant":
53
- from .commands import op_grant
54
-
55
- return op_grant(args)
56
- case "op_list":
57
- from .commands import op_list
58
-
59
- return op_list(args)
60
- case "op_revoke":
61
- from .commands import op_revoke
62
-
63
- return op_revoke(args)
64
- case "remove":
65
- from .commands import remove_projects
66
-
67
- return remove_projects(args)
68
- case "search":
69
- from .commands import search_projects
70
-
71
- return search_projects(args)
72
- case "show":
73
- from .commands import show_projects
74
-
75
- return show_projects(args)
76
- case "start":
77
- from .commands import start_server
78
-
79
- return start_server(args)
80
- case "status":
81
- from .commands import server_status
82
-
83
- return server_status(args)
84
- case "stop":
85
- from .commands import stop_server
86
-
87
- return stop_server(args)
88
- case "update":
89
- from .commands import update_projects
90
-
91
- return update_projects(args)
92
- case "whitelist_add":
93
- from .commands import whitelist_add
94
-
95
- return whitelist_add(args)
96
- case "whitelist_list":
97
- from .commands import whitelist_list
98
-
99
- return whitelist_list(args)
100
- case "whitelist_remove":
101
- from .commands import whitelist_remove
102
-
103
- return whitelist_remove(args)
104
- case _:
105
- import logging as log
106
-
107
- log.error(f"Unknown command: {command_name}")
108
- return 1
1
+ import argparse
2
+ import sys
3
+ from types import FunctionType
109
4
 
110
- # Parser Setup
5
+ from . import __version__
6
+ from .modrinth.shared import search_sort_index
7
+ from .shared import loader_list
8
+
9
+
10
+ def bound_int(min_integer: int, max_integer: int | None = None) -> FunctionType:
11
+ def parse(cli_string: str) -> int:
12
+ try:
13
+ integer = int(cli_string)
14
+ except ValueError:
15
+ raise argparse.ArgumentTypeError(f"{cli_string} is not an integer")
16
+
17
+ if integer < min_integer:
18
+ raise argparse.ArgumentTypeError(
19
+ f"{integer} must be higher than or equal to {min_integer}"
20
+ )
21
+ if max_integer is not None and integer > max_integer:
22
+ raise argparse.ArgumentTypeError(
23
+ f"{integer} must be between {min_integer} and {max_integer} (inclusive)"
24
+ )
25
+ return integer
26
+
27
+ return parse
28
+
29
+
30
+ def command_function(args: argparse.Namespace) -> int:
31
+ command_name: str = args.command_name
32
+
33
+ match command_name:
34
+ case "add":
35
+ from .commands import add_projects
36
+
37
+ return add_projects(args)
38
+ case "import":
39
+ from .commands import import_setup
40
+
41
+ return import_setup(args)
42
+ case "help":
43
+ from .commands import print_help
44
+
45
+ return print_help(args)
46
+ case "init":
47
+ from .commands import initialize_server
48
+
49
+ return initialize_server(args)
50
+ case "list":
51
+ from .commands import list_projects
52
+
53
+ return list_projects(args)
54
+ case "op_grant":
55
+ from .commands import op_grant
56
+
57
+ return op_grant(args)
58
+ case "op_list":
59
+ from .commands import op_list
60
+
61
+ return op_list(args)
62
+ case "op_revoke":
63
+ from .commands import op_revoke
64
+
65
+ return op_revoke(args)
66
+ case "remove":
67
+ from .commands import remove_projects
68
+
69
+ return remove_projects(args)
70
+ case "search":
71
+ from .commands import search_projects
72
+
73
+ return search_projects(args)
74
+ case "show":
75
+ from .commands import show_projects
76
+
77
+ return show_projects(args)
78
+ case "start":
79
+ from .commands import start_server
80
+
81
+ return start_server(args)
82
+ case "status":
83
+ from .commands import server_status
84
+
85
+ return server_status(args)
86
+ case "stop":
87
+ from .commands import stop_server
88
+
89
+ return stop_server(args)
90
+ case "update":
91
+ from .commands import update_projects
92
+
93
+ return update_projects(args)
94
+ case "whitelist_add":
95
+ from .commands import whitelist_add
96
+
97
+ return whitelist_add(args)
98
+ case "whitelist_list":
99
+ from .commands import whitelist_list
100
+
101
+ return whitelist_list(args)
102
+ case "whitelist_remove":
103
+ from .commands import whitelist_remove
104
+
105
+ return whitelist_remove(args)
106
+ case _:
107
+ import logging
108
+
109
+ logger = logging.getLogger(__name__)
110
+
111
+ logger.error(f"Unknown command: {command_name}")
112
+ return 1
111
113
 
114
+
115
+ def main() -> int:
116
+ # Parser Setup
112
117
  parser = argparse.ArgumentParser(
113
118
  prog="mcserver",
114
119
  description="A CLI tool for managing Minecraft: Java Edition servers.",
@@ -134,28 +139,6 @@ def main() -> int:
134
139
 
135
140
  commands = parser.add_subparsers(title="Commands")
136
141
 
137
- # 'add' command
138
- add_command = commands.add_parser(
139
- "add",
140
- help="Add Modrinth projects to the server",
141
- description="Add Modrinth mods/plugins to the server",
142
- )
143
-
144
- add_command.set_defaults(command_name="add")
145
- add_command.add_argument(
146
- "projects", nargs="+", type=str, help="Modrinth project slugs or IDs"
147
- )
148
-
149
- # 'import' command
150
- import_command = commands.add_parser(
151
- "import",
152
- help="Import a Modrinth modpack",
153
- description="Import a Modrinth modpack from a file.",
154
- )
155
-
156
- import_command.set_defaults(command_name="import")
157
- import_command.add_argument("file", type=str, help="The Modrinth modpack file")
158
-
159
142
  # 'init' command
160
143
  init_command = commands.add_parser(
161
144
  "init",
@@ -193,15 +176,15 @@ def main() -> int:
193
176
  init_command.add_argument(
194
177
  "--min-ram",
195
178
  default=512,
196
- type=bound_int(1024),
197
- help="Minimum RAM for the server (in MebiBytes) (minimum value: 1024)",
179
+ type=bound_int(512),
180
+ help="Minimum RAM for the server (in MebiBytes) (minimum value: 512)",
198
181
  metavar="Size",
199
182
  )
200
183
 
201
184
  init_command.add_argument(
202
185
  "--max-ram",
203
- default=bound_int(1024),
204
- type=int,
186
+ default=1024,
187
+ type=bound_int(1024),
205
188
  help="Maximum RAM for the server (in MebiBytes) (minimum value: 1024)",
206
189
  metavar="Size",
207
190
  )
@@ -222,16 +205,9 @@ def main() -> int:
222
205
  choices=search_sort_index,
223
206
  help="Default search sort index",
224
207
  metavar="Index",
225
- dest="search_limit",
226
- )
227
-
228
- # 'list' command
229
- list_command = commands.add_parser(
230
- "list", help="List all added projects", description="List all added projects."
208
+ dest="sort_index",
231
209
  )
232
210
 
233
- list_command.set_defaults(command_name="list")
234
-
235
211
  # 'op' command
236
212
  op_command = commands.add_parser(
237
213
  "op", help="Manage operator players", description="Manage the operator status."
@@ -248,16 +224,6 @@ def main() -> int:
248
224
 
249
225
  op_list_command.set_defaults(command_name="op_list")
250
226
 
251
- # 'remove' command
252
- remove_command = commands.add_parser(
253
- "remove", help="Remove projects", description="Remove projects"
254
- )
255
-
256
- remove_command.set_defaults(command_name="remove")
257
- remove_command.add_argument(
258
- "projects", nargs="+", type=str, help="Modrinth project slugs or IDs"
259
- )
260
-
261
227
  # 'search' command
262
228
  search_command = commands.add_parser(
263
229
  "search",
@@ -272,7 +238,6 @@ def main() -> int:
272
238
 
273
239
  search_command.add_argument(
274
240
  "--limit",
275
- default=20,
276
241
  type=bound_int(1, 100),
277
242
  help="Search projects per page (value between (inclusive): 1-100)",
278
243
  metavar="Number",
@@ -289,13 +254,11 @@ def main() -> int:
289
254
  )
290
255
 
291
256
  search_command.add_argument(
292
- "--sort",
293
- default="relevance",
257
+ "--sort-index",
294
258
  type=str,
295
259
  choices=search_sort_index,
296
260
  help="Sort by index",
297
261
  metavar="Index",
298
- dest="sort_index",
299
262
  )
300
263
 
301
264
  search_command.add_argument(
@@ -348,6 +311,7 @@ def main() -> int:
348
311
 
349
312
  stop_command.set_defaults(command_name="stop")
350
313
 
314
+ # update is not going to be implemented in this version
351
315
  # 'whitelist' command
352
316
  whitelist_command = commands.add_parser(
353
317
  "whitelist",
@@ -368,5 +332,15 @@ def main() -> int:
368
332
 
369
333
  whitelist_list_command.set_defaults(command_name="whitelist_list")
370
334
 
335
+ # 'whitelist remove'
336
+ whitelist_remove_command = whitelist_subcommands.add_parser(
337
+ "remove",
338
+ help="Remove players from the whitelist",
339
+ description="List all whitelisted players.",
340
+ )
341
+
342
+ whitelist_remove_command.set_defaults(command_name="whitelist_remove")
343
+ whitelist_remove_command.add_argument("players", nargs="+", type=str, help="List of player names or UUIDs")
344
+
371
345
  args = parser.parse_args()
372
346
  return args.func(args)
@@ -1,21 +1,21 @@
1
- from .add_projects import main as add_projects
2
- from .import_setup import main as import_setup
3
- from .initialize_server import main as initialize_server
4
- from .list_projects import main as list_projects
5
- from .op_grant import main as op_grant
6
- from .op_list import main as op_list
7
- from .op_revoke import main as op_revoke
8
- from .print_help import main as print_help
9
- from .remove_projects import main as remove_projects
10
- from .search_projects import main as search_projects
11
- from .server_status import main as server_status
12
- from .show_projects import main as show_projects
13
- from .start_server import main as start_server
14
- from .stop_server import main as stop_server
15
- from .update_projects import main as update_projects
16
- from .whitelist_add import main as whitelist_add
17
- from .whitelist_list import main as whitelist_list
18
- from .whitelist_remove import main as whitelist_remove
1
+ from .add_projects import run as add_projects
2
+ from .import_setup import run as import_setup
3
+ from .initialize_server import run as initialize_server
4
+ from .list_projects import run as list_projects
5
+ from .op_grant import run as op_grant
6
+ from .op_list import run as op_list
7
+ from .op_revoke import run as op_revoke
8
+ from .print_help import run as print_help
9
+ from .remove_projects import run as remove_projects
10
+ from .search_projects import run as search_projects
11
+ from .server_status import run as server_status
12
+ from .show_projects import run as show_projects
13
+ from .start_server import run as start_server
14
+ from .stop_server import run as stop_server
15
+ from .update_projects import run as update_projects
16
+ from .whitelist_add import run as whitelist_add
17
+ from .whitelist_list import run as whitelist_list
18
+ from .whitelist_remove import run as whitelist_remove
19
19
 
20
20
  __all__ = [
21
21
  "add_projects",