main
1@echo off
2setlocal EnableDelayedExpansion
3
4set "YES_MODE=0"
5set "PLATFORM_ARG="
6
7:PARSE_ARGS
8if "%~1" == "" goto CHECK_PLATFORM
9
10if /i "%~1" == "-h" goto ShowHelp
11if /i "%~1" == "--help" goto ShowHelp
12
13if /i "%~1" == "-y" (
14 set "YES_MODE=1"
15 shift
16 goto PARSE_ARGS
17)
18if /i "%~1" == "--yes" (
19 set "YES_MODE=1"
20 shift
21 goto PARSE_ARGS
22)
23
24if /i "%~1" == "mr" (
25 if defined PLATFORM_ARG (
26 echo Error: Platform specified twice ('!PLATFORM_ARG!' and '%~1'). >&2
27 exit /b 1
28 )
29 set "PLATFORM_ARG=mr"
30 shift
31 goto PARSE_ARGS
32)
33if /i "%~1" == "cf" (
34 if defined PLATFORM_ARG (
35 echo Error: Platform specified twice ('!PLATFORM_ARG!' and '%~1'). >&2
36 exit /b 1
37 )
38 set "PLATFORM_ARG=cf"
39 shift
40 goto PARSE_ARGS
41)
42
43if "%~1:~0,1%" == "-" (
44 echo Error: Unknown option '%~1'. >&2
45 call :ShowHelp
46 exit /b 1
47)
48
49echo Error: Invalid argument '%~1'. Platform must be 'mr' or 'cf'. >&2
50exit /b 1
51
52:CHECK_PLATFORM
53if not defined PLATFORM_ARG (
54 echo Error: Missing platform argument (mr or cf). >&2
55 call :ShowHelp
56 exit /b 1
57)
58
59if "%PLATFORM_ARG%" == "mr" (
60 set "PLATFORM_NAME=Modrinth"
61) else (
62 set "PLATFORM_NAME=CurseForge"
63)
64
65where packwiz >nul 2>&1
66if %ERRORLEVEL% neq 0 (
67 echo Error: 'packwiz' command not found in PATH. >&2
68 exit /b 1
69)
70
71set "PACKWIZ_ARGS="
72if "%YES_MODE%" == "1" (
73 set "PACKWIZ_ARGS=-y"
74)
75
76echo Reading clipboard for: %PLATFORM_NAME% (%PLATFORM_ARG%)...
77if "%VERBOSE%" == "1" (
78 echo Verbose mode: ON
79)
80echo ----------------------------------------
81
82for /f "usebackq tokens=* delims=" %%L in (`powershell -NoProfile -Command "Get-Clipboard"`) do (
83 set "line=%%L"
84 if defined line (
85 if not "!line:~0,1!" == "#" (
86 <nul set /p "=Processing: !line! ... "
87 echo(
88 packwiz %PLATFORM_ARG% add !PACKWIZ_ARGS! "!line!"
89 if !errorlevel! equ 0 (
90 echo -^> OK
91 ) else (
92 echo -^> FAILED
93 )
94 echo ----------------------------------------
95 )
96 )
97)
98
99echo Done.
100exit /b 0
101
102:ShowHelp
103echo Usage: %~nx0 ^<platform^> [OPTIONS]
104echo(
105echo Description:
106echo Read lines from the system clipboard and add them to packwiz.
107echo(
108echo Arguments:
109echo platform The platform to add mods from.
110echo Must be either 'mr' (Modrinth) or 'cf' (CurseForge).
111echo(
112echo Options:
113echo -y, --yes Automatically answer yes to all prompts.
114echo -h, --help Show this help message and exit.
115goto :eof