mirror of
https://github.com/Radiquum/YAMPD.git
synced 2025-05-20 07:39:35 +05:00
feat: add packs cli management command
This commit is contained in:
parent
c78314fb0a
commit
5d6f654b69
5 changed files with 272 additions and 1 deletions
|
@ -4,3 +4,5 @@ requests
|
||||||
Pillow
|
Pillow
|
||||||
flask-socketio
|
flask-socketio
|
||||||
tqdm
|
tqdm
|
||||||
|
rich
|
||||||
|
beaupy
|
92
src/cli.py
Normal file
92
src/cli.py
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
os.environ["is_dev"] = "True"
|
||||||
|
os.environ["is_cli"] = "True"
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
from rich.console import Console
|
||||||
|
|
||||||
|
from cli.packs import getPacksCommand, createPackCommand, deletePacksCommand
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
"YAMCPACK", description="Yet Another (Minecraft) Mod Pack Downloader"
|
||||||
|
)
|
||||||
|
sub_parsers = parser.add_subparsers(help="CLI Commands", dest="command")
|
||||||
|
|
||||||
|
# ----- Packs -----
|
||||||
|
|
||||||
|
packs_parser = sub_parsers.add_parser("packs", help="Manage packs")
|
||||||
|
sub_packs_parsers = packs_parser.add_subparsers(dest="subcommand")
|
||||||
|
packs_list = sub_packs_parsers.add_parser("list", help="List all packs")
|
||||||
|
packs_new = sub_packs_parsers.add_parser("new", help="Create a new pack")
|
||||||
|
packs_delete = sub_packs_parsers.add_parser("delete", help="Delete pack")
|
||||||
|
|
||||||
|
pack_parser = sub_parsers.add_parser("pack")
|
||||||
|
sub_pack_parsers = pack_parser.add_subparsers(
|
||||||
|
help="Manage pack commands", dest="subcommand"
|
||||||
|
)
|
||||||
|
|
||||||
|
console = Console()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if os.environ["is_dev"]:
|
||||||
|
console.print("--- DEBUG MODE ---", style="bold red")
|
||||||
|
console.print("Provided arguments:", args)
|
||||||
|
console.print(f"{'-':-<18}", style="bold red")
|
||||||
|
console.print("\n")
|
||||||
|
|
||||||
|
if args.command is None:
|
||||||
|
parser.print_help()
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
if args.command == "packs" and args.subcommand is None:
|
||||||
|
packs_parser.print_help()
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
if args.command == "packs" and args.subcommand == "list":
|
||||||
|
getPacksCommand()
|
||||||
|
|
||||||
|
if args.command == "packs" and args.subcommand == "new":
|
||||||
|
createPackCommand()
|
||||||
|
|
||||||
|
if args.command == "packs" and args.subcommand == "delete":
|
||||||
|
deletePacksCommand()
|
||||||
|
|
||||||
|
if args.command == "pack" and args.subcommand is None:
|
||||||
|
pack_parser.print_help()
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
# if args.command == "packs":
|
||||||
|
# if args.packs_command == "new":
|
||||||
|
# title = input("Pack title: ")
|
||||||
|
# author = input("Pack author: ")
|
||||||
|
# game_version = input("Game version: ")
|
||||||
|
# mod_loader = input("Mod loader (fabric, forge, neoforge, quilt): ")
|
||||||
|
|
||||||
|
# if title == "" or author == "" or game_version == "" or mod_loader == "":
|
||||||
|
# print("some parameters weren't provided")
|
||||||
|
# exit(1)
|
||||||
|
|
||||||
|
# if len(game_version.split(".")) == 1:
|
||||||
|
# print("wrong version format. should be int.int or int.int.int")
|
||||||
|
# exit(1)
|
||||||
|
|
||||||
|
# if mod_loader.lower() not in ["fabric", "forge", "neoforge", "quilt"]:
|
||||||
|
# print("wrong mod loader is provided")
|
||||||
|
# exit(1)
|
||||||
|
|
||||||
|
# pack, is_exists = createPack(title, author, game_version, mod_loader)
|
||||||
|
# if is_exists:
|
||||||
|
# print(f"Pack {pack.title} already exists")
|
||||||
|
# else:
|
||||||
|
# print(f"Pack {pack.title} was created")
|
||||||
|
# elif args.packs_command == "delete":
|
||||||
|
# deletePack
|
||||||
|
# print("Del Pack")
|
||||||
|
# else:
|
||||||
|
# packs_parser.print_help()
|
||||||
|
|
||||||
|
# print("---------------")
|
||||||
|
# print(args)
|
1
src/cli/__init__.py
Normal file
1
src/cli/__init__.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
96
src/cli/packs.py
Normal file
96
src/cli/packs.py
Normal file
|
@ -0,0 +1,96 @@
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import json
|
||||||
|
|
||||||
|
from config import PACKS_FOLDER
|
||||||
|
from shared.packs import getPacks, createPack, deletePack
|
||||||
|
|
||||||
|
|
||||||
|
def resource_path(relative_path):
|
||||||
|
if hasattr(sys, "_MEIPASS"):
|
||||||
|
return os.path.join(sys._MEIPASS, relative_path)
|
||||||
|
return os.path.join(os.path.abspath("."), relative_path)
|
||||||
|
|
||||||
|
|
||||||
|
from beaupy import confirm, prompt, select, select_multiple
|
||||||
|
from beaupy.spinners import *
|
||||||
|
from rich.console import Console
|
||||||
|
from rich.columns import Columns
|
||||||
|
from rich.panel import Panel
|
||||||
|
|
||||||
|
console = Console()
|
||||||
|
|
||||||
|
|
||||||
|
def getPacksCommand():
|
||||||
|
packs = []
|
||||||
|
packs_json = getPacks()
|
||||||
|
for pack in packs_json:
|
||||||
|
packs.append(
|
||||||
|
Panel(
|
||||||
|
f"[b][cyan]{pack.get('title')}[/cyan][/b]\n{pack.get('author')}\n{len(pack.get('mods'))} mods"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
console.print(Columns(packs))
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
def createPackCommand():
|
||||||
|
title = prompt("How the mod pack will be named?")
|
||||||
|
if title == "":
|
||||||
|
console.print("[ERROR]: Pack Title is required!", style="bold red")
|
||||||
|
exit(1)
|
||||||
|
_id = title.replace(" ", "_")
|
||||||
|
|
||||||
|
if os.path.exists(f"{PACKS_FOLDER}/{_id}"):
|
||||||
|
console.print(
|
||||||
|
f"Pack {title} already exists in {PACKS_FOLDER}/{_id}", style="green"
|
||||||
|
)
|
||||||
|
exit(1)
|
||||||
|
print(f"Title: {title}")
|
||||||
|
|
||||||
|
author = prompt("Pack author?")
|
||||||
|
if author == "":
|
||||||
|
console.print("[ERROR]: Pack author is required!", style="bold red")
|
||||||
|
exit(1)
|
||||||
|
print(f"Author: {author}")
|
||||||
|
|
||||||
|
versions: list = []
|
||||||
|
with open(resource_path("./mc_version.json")) as fp:
|
||||||
|
versions = json.load(fp)
|
||||||
|
versions.reverse()
|
||||||
|
|
||||||
|
print("Game Version")
|
||||||
|
game_version = select(
|
||||||
|
versions, cursor="🢧", cursor_style="cyan", pagination=True, page_size=10
|
||||||
|
)
|
||||||
|
print(game_version)
|
||||||
|
|
||||||
|
print("Mod Loader")
|
||||||
|
mod_loader = select(
|
||||||
|
["Fabric", "Forge", "Quilt", "NeoForge"], cursor="🢧", cursor_style="cyan"
|
||||||
|
)
|
||||||
|
print(mod_loader)
|
||||||
|
|
||||||
|
pack, is_exists = createPack(title, author, game_version, mod_loader)
|
||||||
|
console.print(
|
||||||
|
f"Pack {pack.title} was created in {PACKS_FOLDER}/{pack._id}", style="green"
|
||||||
|
)
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
def deletePacksCommand():
|
||||||
|
packs = []
|
||||||
|
packs_json = getPacks()
|
||||||
|
for pack in packs_json:
|
||||||
|
packs.append(pack.get("title"))
|
||||||
|
print("select a pack to delete")
|
||||||
|
title = select(
|
||||||
|
packs, cursor="🢧", cursor_style="cyan", pagination=True, page_size=10
|
||||||
|
)
|
||||||
|
_id = title.replace(" ", "_")
|
||||||
|
if confirm(f"Are you sure you want to delete pack [cyan]{title}[/cyan]?"):
|
||||||
|
deletePack(_id)
|
||||||
|
console.print(f"Pack [cyan]{title}[/cyan] was deleted")
|
||||||
|
else:
|
||||||
|
print("delete cancelled")
|
||||||
|
exit(0)
|
80
src/mc_version.json
Normal file
80
src/mc_version.json
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
[
|
||||||
|
"1.6",
|
||||||
|
"1.6.1",
|
||||||
|
"1.6.2",
|
||||||
|
"1.6.4",
|
||||||
|
"1.7",
|
||||||
|
"1.7.2",
|
||||||
|
"1.7.3",
|
||||||
|
"1.7.4",
|
||||||
|
"1.7.5",
|
||||||
|
"1.7.6",
|
||||||
|
"1.7.7",
|
||||||
|
"1.7.9",
|
||||||
|
"1.7.8",
|
||||||
|
"1.7.10",
|
||||||
|
"1.8",
|
||||||
|
"1.8.1",
|
||||||
|
"1.8.2",
|
||||||
|
"1.8.3",
|
||||||
|
"1.8.4",
|
||||||
|
"1.8.5",
|
||||||
|
"1.8.6",
|
||||||
|
"1.8.7",
|
||||||
|
"1.8.8",
|
||||||
|
"1.8.9",
|
||||||
|
"1.9",
|
||||||
|
"1.9.1",
|
||||||
|
"1.9.2",
|
||||||
|
"1.9.3",
|
||||||
|
"1.9.4",
|
||||||
|
"1.10",
|
||||||
|
"1.10.1",
|
||||||
|
"1.10.2",
|
||||||
|
"1.11",
|
||||||
|
"1.11.1",
|
||||||
|
"1.11.2",
|
||||||
|
"1.12",
|
||||||
|
"1.12.1",
|
||||||
|
"1.12.2",
|
||||||
|
"1.13",
|
||||||
|
"1.13.1",
|
||||||
|
"1.13.2",
|
||||||
|
"1.14",
|
||||||
|
"1.14.1",
|
||||||
|
"1.14.2",
|
||||||
|
"1.14.3",
|
||||||
|
"1.14.4",
|
||||||
|
"1.15",
|
||||||
|
"1.15.1",
|
||||||
|
"1.15.2",
|
||||||
|
"1.16",
|
||||||
|
"1.16.1",
|
||||||
|
"1.16.2",
|
||||||
|
"1.16.3",
|
||||||
|
"1.16.4",
|
||||||
|
"1.16.5",
|
||||||
|
"1.17",
|
||||||
|
"1.17.1",
|
||||||
|
"1.18",
|
||||||
|
"1.18.1",
|
||||||
|
"1.18.2",
|
||||||
|
"1.19",
|
||||||
|
"1.19.1",
|
||||||
|
"1.19.2",
|
||||||
|
"1.19.3",
|
||||||
|
"1.19.4",
|
||||||
|
"1.20",
|
||||||
|
"1.20.1",
|
||||||
|
"1.20.2",
|
||||||
|
"1.20.3",
|
||||||
|
"1.20.4",
|
||||||
|
"1.20.5",
|
||||||
|
"1.20.6",
|
||||||
|
"1.21",
|
||||||
|
"1.21.1",
|
||||||
|
"1.21.2",
|
||||||
|
"1.21.3",
|
||||||
|
"1.21.4",
|
||||||
|
"1.21.5"
|
||||||
|
]
|
Loading…
Add table
Add a link
Reference in a new issue