add cli flag to add missing mods in enabled state

This commit is contained in:
Lilian Jónsdóttir 2024-02-12 09:45:25 -08:00
parent 636c6f9143
commit c9eaba2737
2 changed files with 14 additions and 7 deletions

View file

@ -14,9 +14,9 @@ import (
)
type config struct {
modsdir, infile, outfile string
mods modlist.Modlist
clobber, addmissing bool
modsdir, infile, outfile string
mods modlist.Modlist
clobber, addmissing, missingstate bool
}
var cfg config
@ -79,6 +79,12 @@ func main() {
Required: false,
Usage: "don't automatically add mods missing from infile",
},
&cli.BoolFlag{
Name: "enable-missing",
Aliases: []string{"e"},
Required: false,
Usage: "Missing mods are added in enabled state",
},
},
Before: func(ctx *cli.Context) error {
// Setup logger
@ -93,6 +99,7 @@ func main() {
// Bool flags
cfg.clobber = ctx.Bool("clobber")
cfg.addmissing = !ctx.Bool("no-add-missing")
cfg.missingstate = ctx.Bool("enable-missing")
// Deal with in/out file
var in = ctx.String("infile")
@ -124,7 +131,7 @@ func main() {
}
if cfg.addmissing {
err = modlist.AddModsNotInList(cfg.modsdir, &cfg.mods)
err = modlist.AddModsNotInList(cfg.modsdir, &cfg.mods, cfg.missingstate)
if err != nil {
return err
}

View file

@ -152,7 +152,7 @@ func ReadFromFile(filename string) (Modlist, error) {
}
// AddModsNotInList finds mod archives in the mod folder that aren't in the modlist, and adds them.
func AddModsNotInList(modsdir string, mods *Modlist) error {
func AddModsNotInList(modsdir string, mods *Modlist, state bool) error {
r := regexp.MustCompile(fileRegex)
files, err := os.ReadDir(modsdir)
@ -167,10 +167,10 @@ func AddModsNotInList(modsdir string, mods *Modlist) error {
version := groups[0][2]
if !mods.HasMod(name) {
log.Info("Found %s not in modlist, adding v%s in disabled state.", name, version)
log.Infof("Found %s not in modlist, adding v%s in disabled state.", name, version)
mods.Mods = append(mods.Mods, Mod{
Name: name,
Enabled: false,
Enabled: state,
})
}
}