@@ -13,6 +13,7 @@ import (
1313 "log"
1414 "os"
1515 "path/filepath"
16+ "regexp"
1617 "runtime"
1718 "strings"
1819)
2728 dlRetries uint8
2829)
2930
31+ var (
32+ // local options
33+ optionalSelected []string
34+ optionalDisableAll bool
35+ )
36+
3037func init () {
3138 var printVersion bool
3239 RootCmd .Flags ().BoolVarP (& printVersion , "version" , "V" , false , "Print version and exit" )
@@ -46,6 +53,9 @@ func init() {
4653 RootCmd .PersistentFlags ().Uint8Var (& dlThreads , "dl-threads" , 8 , "Concurrent download threads" )
4754 RootCmd .PersistentFlags ().Uint8Var (& dlRetries , "dl-retries" , 3 , "Retries when download fails" )
4855
56+ RootCmd .Flags ().StringArrayVar (& optionalSelected , "optional-select" , nil , "Select optional mods by file path (regex)" )
57+ RootCmd .Flags ().BoolVar (& optionalDisableAll , "optional-disable-all" , false , "Disable all optional mods" )
58+
4959 cobra .OnInitialize (func () {
5060 if printVersion {
5161 buildinfo .Print ()
@@ -101,7 +111,8 @@ var RootCmd = &cobra.Command{
101111 mrpack-install adrenaserver --server-file srv.jar
102112 mrpack-install yK0ISmKn 1.0.0-1.18 --server-dir mcserver
103113 mrpack-install communitypack9000 --host api.labrinth.example.org
104- mrpack-install --version` ,
114+ mrpack-install example.mrpack --optional-select 'foo\.jar' \
115+ --optional-select 'bar-[\d+\.]+\.jar'` ,
105116 Args : cobra .RangeArgs (1 , 2 ),
106117 Run : func (cmd * cobra.Command , args []string ) {
107118 input := args [0 ]
@@ -144,7 +155,30 @@ var RootCmd = &cobra.Command{
144155 }
145156
146157 // downloads
147- downloads := index .ServerDownloads ()
158+ downloads := index .ServerDownloads (func (f mrpack.File ) bool {
159+ switch f .Env .Server {
160+ case modrinth .RequiredEnvSupport :
161+ return true
162+ case modrinth .OptionalEnvSupport :
163+ if optionalDisableAll {
164+ return false
165+ }
166+ if len (optionalSelected ) < 1 {
167+ return true
168+ }
169+ for _ , p := range optionalSelected {
170+ if regexp .MustCompile (p ).Match ([]byte (filepath .Base (f .Path ))) {
171+ return true
172+ }
173+ }
174+ return false
175+ case modrinth .UnsupportedEnvSupport :
176+ return false
177+ default :
178+ log .Fatalf ("Unexpected environment configuration %q for mod %q\n " , f .Env .Server , f .Path )
179+ return false
180+ }
181+ })
148182 log .Printf ("Downloading %v dependencies...\n " , len (downloads ))
149183 downloader := download.Downloader {
150184 Downloads : downloads ,
0 commit comments